#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>


// Location of timetamp file for software watchdog
char timestamp_watchdog[200] = "/home/carol/watchdog/timestamp.txt";
// Max errors that can be found for a single iteration
// If more than max errors is found, exit the program
unsigned long int max_errors_per_iter = 5000;

// Absolute path for log file, if needed
char absolute_path[200] = "/home/carol/logs/";

// Used to print the log only for some iterations, equal 1 means print every iteration
int iter_interval_print = 1;

char log_file_name[200] = "";
char full_log_file_name[300] = "";

// Saves the last amount of error found for a specific iteration
unsigned long int last_iter_errors = 0;
// Saves the last iteration index that had an error
unsigned long int last_iter_with_errors = 0;

unsigned long int kernels_total_errors = 0;
unsigned long int iteration_number = 0;
double kernel_time_acc = 0;
double kernel_time = 0;
long long it_time_start;

// ~ ===========================================================================
inline long long get_time() {
    struct timeval tv;

    gettimeofday(&tv, NULL);

    return (tv.tv_sec * 1000000) + tv.tv_usec;
};

// ~ ===========================================================================
unsigned long int set_max_errors_iter(unsigned long int max_errors){
     max_errors_per_iter = max_errors;

     return max_errors_per_iter;
};

// ~ ===========================================================================
// Set the interval the program must print log details, default is 1 (each iteration)
int set_iter_interval_print(int interval){
    if(interval < 1) {
        iter_interval_print = 1;
    }
    else {
        iter_interval_print = interval;
    }

    return iter_interval_print;
};

// ~ ===========================================================================
// Update with current timestamp the file where the software watchdog watchs
void update_timestamp() {
    time_t timestamp = time(NULL);
    char time_s[50];
    char string[100] = "echo ";

    sprintf(time_s, "%d", (int) timestamp);

    strcat(string, time_s);
    strcat(string, " > ");
    strcat(string, timestamp_watchdog);
    system(string);
};

// ~ ===========================================================================
// In case the user needs the log to be generated in some exact absolute path
void set_absolute_path(char *path){
    strcpy(absolute_path, path);
};

// ~ ===========================================================================
// Return the name of the log file generated
char * get_log_file_name(){
    return full_log_file_name;
};

// ~ ===========================================================================
// Generate the log file name, log info from user about the test to be executed and reset log variables
int start_log_file(char *benchmark_name, char *test_info){

    update_timestamp();

    time_t file_time;
    struct tm *ptm;
    char day[10], month[10], year[15], hour[10], second[10], minute[10];
    char log_file_name[180] = "";

    file_time = time(NULL);
    ptm = gmtime(&file_time);

    snprintf(day,       sizeof(day),    "%02d", ptm->tm_mday);
    snprintf(month,     sizeof(month),  "%02d", ptm->tm_mon+1);
    snprintf(year,      sizeof(year),   "%04d", ptm->tm_year+1900);
    snprintf(hour,      sizeof(hour),   "%02d", ptm->tm_hour);
    snprintf(minute,    sizeof(minute), "%02d", ptm->tm_min);
    snprintf(second,    sizeof(second), "%02d", ptm->tm_sec);

    // ~ Get the host name to add inside the log name.
    char host[35] = "Host";
    int host_error = 0;
    host_error = gethostname(host, 35);

    if (host_error != 0) {
        fprintf(stderr, "[ERROR in gethostname(char *, int)] Could not access the host name\n");
        return 1;
    }

    strcpy(log_file_name, year);             strcat(log_file_name, "_");
    strcat(log_file_name, month);            strcat(log_file_name, "_");
    strcat(log_file_name, day);              strcat(log_file_name, "_");

    strcat(log_file_name, hour);             strcat(log_file_name, "_");
    strcat(log_file_name, minute);           strcat(log_file_name, "_");
    strcat(log_file_name, second);           strcat(log_file_name, "_");

    strcat(log_file_name, benchmark_name);   strcat(log_file_name, "_");
    strcat(log_file_name, host);
    strcat(log_file_name, ".log");


    strcpy(full_log_file_name, absolute_path);
    if(strlen(absolute_path) > 0 && absolute_path[strlen(absolute_path)-1] != '/' )
        strcat(full_log_file_name, "/");
    strcat(full_log_file_name, log_file_name);
// ~ printf("%s\n", full_log_file_name);

    struct stat buf;
    if (stat(full_log_file_name, &buf) == 0) {
        fprintf(stderr, "[ERROR in create_log_file(char *)] File already exists %s\n",full_log_file_name);
        return 1;
    }

    FILE *file = NULL;

    file = fopen(full_log_file_name, "a");
    if (file == NULL){
        fprintf(stderr, "[ERROR in create_log_file(char *)] Unable to open file %s\n",full_log_file_name);
        return 1;
    }
    else if(test_info != NULL) {
        fprintf(file, "#HEADER %s\n",test_info);
    }
    else {
        fprintf(file, "#HEADER\n");
    }

    fprintf(file, "#BEGIN Y:%s M:%s D:%s Time:%s:%s:%s\n", year, month, day, hour, minute, second);
    fflush(file);
    fclose(file);

    kernels_total_errors = 0;
    iteration_number = 0;
    kernel_time_acc = 0;

    return 0;
};

// ~ ===========================================================================
// Log the string "#END" and reset global variables
int end_log_file(){
    FILE *file = NULL;

    file = fopen(full_log_file_name, "a");
    if (file == NULL){
        fprintf(stderr, "[ERROR in log_string(char *)] Unable to open file %s\n",full_log_file_name);
        return 1;
    }

    fprintf(file, "#END");
    fflush(file);
    fclose(file);
    kernels_total_errors = 0;
    iteration_number = 0;
    kernel_time_acc = 0;
    strcpy(log_file_name, "");
    strcpy(absolute_path, "");
    strcpy(full_log_file_name, "");

    return 0;
};

// ~ ===========================================================================
// Start time to measure kernel time, also update iteration number and log to file
int start_iteration(){

    update_timestamp();

/*
    FILE *file = fopen(full_log_file_name, "a");

    if (file == NULL){
        fprintf(stderr, "[ERROR in log_string(char *)] Unable to open file %s\n",full_log_file_name);
        return 1;
    }

    fprintf(file, "#ITER it:%lu\n", iteration_number);
    fflush(file);
    fclose(file);
    iteration_number++;
*/
    it_time_start = get_time();
    return 0;

};

// ~ ===========================================================================
// Finish the measured kernel time log both time (total time and kernel time)
int end_iteration(){

    update_timestamp();

    kernel_time = (double) (get_time() - it_time_start) / 1000000;
    kernel_time_acc += kernel_time;



    if(iteration_number % iter_interval_print == 0) {

        FILE *file = fopen(full_log_file_name, "a");

        if (file == NULL){
            fprintf(stderr, "[ERROR in log_string(char *)] Unable to open file %s\n",full_log_file_name);
            return 1;
        }

        fprintf(file,"#IT Ite:%lu KerTime:%f AccTime:%f\n", iteration_number, kernel_time, kernel_time_acc);
        //fprintf(file, "#TIME kernel_time:%f\n", kernel_time);
        //fprintf(file, "#ACC_TIME total_time:%f\n", kernel_time_acc);
        fflush(file);
        fclose(file);
    }

    iteration_number++;

    return 0;

};

// ~ ===========================================================================
// Update total errors variable and log both errors(total errors and kernel errors)
int log_error_count(unsigned long int kernel_errors){

    update_timestamp();

    if(kernel_errors < 1) {
        return 0;
    }

    kernels_total_errors += kernel_errors;

    FILE *file = NULL;
    file = fopen(full_log_file_name, "a");

    if (file == NULL){
        fprintf(stderr, "[ERROR in log_string(char *)] Unable to open file %s\n",full_log_file_name);
        return 1;
    }

    // (iteration_number-1) because this function is called after end_iteration() that increments iteration_number
    fprintf(file, "#SDC Ite:%lu KerTime:%f AccTime:%f KerErr:%lu AccErr:%lu\n", iteration_number-1, kernel_time, kernel_time_acc, kernel_errors, kernels_total_errors);
    //fprintf(file, "#SDC kernel_errors:%lu\n", kernel_errors);
    //fprintf(file, "#TOTAL_SDC total_errors:%lu\n", kernels_total_errors);
    fflush(file);


    if(kernel_errors > max_errors_per_iter){
        fprintf(file, "#ABORT too many errors per iteration\n");
        fflush(file);
        fclose(file);
        end_log_file();
        exit(1);
    }


    if(kernel_errors == last_iter_errors && (last_iter_with_errors+1) == iteration_number && kernel_errors != 0){
        fprintf(file, "#ABORT amount of errors equals of the last iteration\n");
        fflush(file);
        fclose(file);
        end_log_file();
        exit(1);
    }

    fclose(file);

    last_iter_errors = kernel_errors;
    last_iter_with_errors = iteration_number;

    return 0;

};

// ~ ===========================================================================
// Print some string with the detail of an error to log file
int log_error_detail(char *string){
    FILE *file = NULL;

    file = fopen(full_log_file_name, "a");
    if (file == NULL){
        fprintf(stderr, "[ERROR in log_string(char *)] Unable to open file %s\n",full_log_file_name);
        return 1;
    }

    fputs("#ERR ", file);
    fputs(string, file);
    fprintf(file, "\n");
    fflush(file);
    fclose(file);
    return 0;
};


	.file	"tmpxft_00226575_00000000-6_log_helper.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2054:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2054:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.text._Z8get_timev,"axG",@progbits,_Z8get_timev,comdat
	.weak	_Z8get_timev
	.type	_Z8get_timev, @function
_Z8get_timev:
.LFB2040:
	.cfi_startproc
	endbr64
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	xorl	%esi, %esi
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdi
	call	gettimeofday@PLT
	imulq	$1000000, 8(%rsp), %rax
	addq	16(%rsp), %rax
	movq	24(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L3
	call	__stack_chk_fail@PLT
.L3:
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2040:
	.size	_Z8get_timev, .-_Z8get_timev
	.text
	.globl	_Z19set_max_errors_iterm
	.type	_Z19set_max_errors_iterm, @function
_Z19set_max_errors_iterm:
.LFB2041:
	.cfi_startproc
	endbr64
	movq	%rdi, max_errors_per_iter(%rip)
	movq	%rdi, %rax
	ret
	.cfi_endproc
.LFE2041:
	.size	_Z19set_max_errors_iterm, .-_Z19set_max_errors_iterm
	.globl	_Z23set_iter_interval_printi
	.type	_Z23set_iter_interval_printi, @function
_Z23set_iter_interval_printi:
.LFB2042:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	movl	$1, %eax
	cmovg	%edi, %eax
	movl	%eax, iter_interval_print(%rip)
	ret
	.cfi_endproc
.LFE2042:
	.size	_Z23set_iter_interval_printi, .-_Z23set_iter_interval_printi
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	" > "
	.text
	.globl	_Z16update_timestampv
	.type	_Z16update_timestampv, @function
_Z16update_timestampv:
.LFB2043:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	xorl	%edi, %edi
	subq	$160, %rsp
	.cfi_def_cfa_offset 176
	movq	%fs:40, %rax
	movq	%rax, 152(%rsp)
	xorl	%eax, %eax
	leaq	2(%rsp), %rbx
	call	time@PLT
	xorl	%edx, %edx
	leaq	68(%rsp), %rdi
	movl	$21, %ecx
	movq	%rax, %r8
	movq	%rdx, 60(%rsp)
	movl	$2, %esi
	movabsq	$139308065637, %rax
	movq	%rax, 52(%rsp)
	xorl	%eax, %eax
	movl	$50, %edx
	rep stosl
	leaq	.LC0(%rip), %rcx
	movq	%rbx, %rdi
	call	__sprintf_chk@PLT
	leaq	52(%rsp), %rdi
	movl	$100, %edx
	movq	%rbx, %rsi
	call	__strcat_chk@PLT
	movl	$100, %edx
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	__strcat_chk@PLT
	movl	$100, %edx
	leaq	timestamp_watchdog(%rip), %rsi
	movq	%rax, %rdi
	call	__strcat_chk@PLT
	movq	%rax, %rdi
	call	system@PLT
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L9
	call	__stack_chk_fail@PLT
.L9:
	addq	$160, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2043:
	.size	_Z16update_timestampv, .-_Z16update_timestampv
	.globl	_Z17set_absolute_pathPc
	.type	_Z17set_absolute_pathPc, @function
_Z17set_absolute_pathPc:
.LFB2044:
	.cfi_startproc
	endbr64
	movq	%rdi, %rsi
	movl	$200, %edx
	leaq	absolute_path(%rip), %rdi
	jmp	__strcpy_chk@PLT
	.cfi_endproc
.LFE2044:
	.size	_Z17set_absolute_pathPc, .-_Z17set_absolute_pathPc
	.globl	_Z17get_log_file_namev
	.type	_Z17get_log_file_namev, @function
_Z17get_log_file_namev:
.LFB2045:
	.cfi_startproc
	endbr64
	leaq	full_log_file_name(%rip), %rax
	ret
	.cfi_endproc
.LFE2045:
	.size	_Z17get_log_file_namev, .-_Z17get_log_file_namev
	.section	.rodata.str1.1
.LC2:
	.string	"%02d"
.LC3:
	.string	"%04d"
.LC4:
	.string	"[ERROR in gethostname(char *, int)] Could not access the host name\n"
.LC5:
	.string	"_"
.LC6:
	.string	".log"
.LC7:
	.string	"/"
.LC8:
	.string	"[ERROR in create_log_file(char *)] File already exists %s\n"
.LC9:
	.string	"a"
.LC10:
	.string	"[ERROR in create_log_file(char *)] Unable to open file %s\n"
.LC11:
	.string	"#HEADER %s\n"
.LC12:
	.string	"#HEADER\n"
.LC13:
	.string	"#BEGIN Y:%s M:%s D:%s Time:%s:%s:%s\n"
	.text
	.globl	_Z14start_log_filePcS_
	.type	_Z14start_log_filePcS_, @function
_Z14start_log_filePcS_:
.LFB2046:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$504, %rsp
	.cfi_def_cfa_offset 560
	movq	%rdi, 40(%rsp)
	leaq	208(%rsp), %r13
	leaq	218(%rsp), %r14
	leaq	258(%rsp), %r15
	leaq	228(%rsp), %r12
	movq	%fs:40, %rax
	movq	%rax, 488(%rsp)
	xorl	%eax, %eax
	call	_Z16update_timestampv
	xorl	%eax, %eax
	movl	$45, %ecx
	leaq	308(%rsp), %rdi
	rep stosl
	xorl	%edi, %edi
	call	time@PLT
	leaq	56(%rsp), %rdi
	movq	%rax, 56(%rsp)
	call	gmtime@PLT
	leaq	.LC2(%rip), %r8
	movl	$10, %ecx
	movq	%r13, %rdi
	movl	12(%rax), %r9d
	movq	%rax, %rbx
	movl	$2, %edx
	xorl	%eax, %eax
	movl	$10, %esi
	call	__snprintf_chk@PLT
	movl	16(%rbx), %eax
	movl	$10, %ecx
	movq	%r14, %rdi
	leaq	.LC2(%rip), %r8
	movl	$2, %edx
	movl	$10, %esi
	leal	1(%rax), %r9d
	xorl	%eax, %eax
	call	__snprintf_chk@PLT
	movl	20(%rbx), %eax
	movl	$15, %ecx
	movq	%r15, %rdi
	leaq	.LC3(%rip), %r8
	movl	$2, %edx
	movl	$15, %esi
	leal	1900(%rax), %r9d
	xorl	%eax, %eax
	call	__snprintf_chk@PLT
	movl	8(%rbx), %r9d
	movl	$10, %ecx
	xorl	%eax, %eax
	leaq	.LC2(%rip), %r8
	movl	$2, %edx
	movl	$10, %esi
	movq	%r12, %rdi
	call	__snprintf_chk@PLT
	movl	4(%rbx), %r9d
	movl	$10, %ecx
	leaq	248(%rsp), %rax
	movq	%rax, %rdi
	movq	%rax, 16(%rsp)
	movl	$2, %edx
	xorl	%eax, %eax
	leaq	.LC2(%rip), %r8
	movl	$10, %esi
	call	__snprintf_chk@PLT
	movl	(%rbx), %r9d
	movl	$10, %ecx
	leaq	238(%rsp), %rax
	movq	%rax, %rdi
	movq	%rax, 24(%rsp)
	movl	$2, %edx
	xorl	%eax, %eax
	leaq	.LC2(%rip), %r8
	movl	$10, %esi
	call	__snprintf_chk@PLT
	xorl	%ecx, %ecx
	xorl	%eax, %eax
	movl	$35, %edx
	movq	%rcx, 281(%rsp)
	leaq	289(%rsp), %rdi
	movl	$19, %ecx
	movl	$35, %esi
	rep stosb
	leaq	273(%rsp), %rax
	movq	$1953722184, 273(%rsp)
	movq	%rax, %rdi
	movq	%rax, 32(%rsp)
	call	__gethostname_chk@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	leaq	308(%rsp), %rax
	movq	%rax, 8(%rsp)
	je	.L14
	movq	stderr(%rip), %rdi
	leaq	.LC4(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	jmp	.L15
.L14:
	movq	8(%rsp), %rdi
	movq	%r15, %rsi
	movl	$180, %edx
	leaq	.LC5(%rip), %r15
	call	__strcpy_chk@PLT
	movq	8(%rsp), %rdi
	movl	$180, %edx
	movq	%r15, %rsi
	call	__strcat_chk@PLT
	movq	8(%rsp), %rdi
	movl	$180, %edx
	movq	%r14, %rsi
	call	__strcat_chk@PLT
	movq	8(%rsp), %rdi
	movl	$180, %edx
	movq	%r15, %rsi
	call	__strcat_chk@PLT
	movq	8(%rsp), %rdi
	movq	%r13, %rsi
	movl	$180, %edx
	leaq	full_log_file_name(%rip), %r13
	call	__strcat_chk@PLT
	movq	8(%rsp), %rdi
	movl	$180, %edx
	movq	%r15, %rsi
	call	__strcat_chk@PLT
	movq	8(%rsp), %rdi
	movq	%r12, %rsi
	movl	$180, %edx
	leaq	absolute_path(%rip), %r12
	call	__strcat_chk@PLT
	movq	8(%rsp), %rdi
	movl	$180, %edx
	movq	%r15, %rsi
	call	__strcat_chk@PLT
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdi
	movl	$180, %edx
	call	__strcat_chk@PLT
	movq	8(%rsp), %rdi
	movl	$180, %edx
	movq	%r15, %rsi
	call	__strcat_chk@PLT
	movq	24(%rsp), %rsi
	movq	8(%rsp), %rdi
	movl	$180, %edx
	call	__strcat_chk@PLT
	movq	8(%rsp), %rdi
	movl	$180, %edx
	movq	%r15, %rsi
	call	__strcat_chk@PLT
	movq	40(%rsp), %rsi
	movq	8(%rsp), %rdi
	movl	$180, %edx
	call	__strcat_chk@PLT
	movq	8(%rsp), %rdi
	movl	$180, %edx
	movq	%r15, %rsi
	call	__strcat_chk@PLT
	movq	32(%rsp), %rsi
	movq	8(%rsp), %rdi
	movl	$180, %edx
	call	__strcat_chk@PLT
	movq	8(%rsp), %rdi
	movl	$180, %edx
	leaq	.LC6(%rip), %rsi
	call	__strcat_chk@PLT
	movl	$300, %edx
	movq	%r12, %rsi
	movq	%r13, %rdi
	call	__strcpy_chk@PLT
	cmpb	$0, absolute_path(%rip)
	je	.L16
	movq	%r12, %rdi
	call	strlen@PLT
	cmpb	$47, -1(%r12,%rax)
	je	.L16
	movl	$300, %edx
	leaq	.LC7(%rip), %rsi
	movq	%r13, %rdi
	call	__strcat_chk@PLT
.L16:
	movq	8(%rsp), %rsi
	movq	%r13, %rdi
	movl	$300, %edx
	call	__strcat_chk@PLT
	leaq	64(%rsp), %rsi
	movq	%r13, %rdi
	call	stat@PLT
	testl	%eax, %eax
	jne	.L17
	movq	stderr(%rip), %rdi
	movq	%r13, %rcx
	movl	$2, %esi
	leaq	.LC8(%rip), %rdx
.L24:
	call	__fprintf_chk@PLT
.L15:
	movl	$1, %ebx
	jmp	.L13
.L17:
	leaq	.LC9(%rip), %rsi
	movq	%r13, %rdi
	call	fopen@PLT
	movq	%rax, %r12
	testq	%rax, %rax
	jne	.L19
	movq	stderr(%rip), %rdi
	movq	%r13, %rcx
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC10(%rip), %rdx
	jmp	.L24
.L19:
	testq	%rbp, %rbp
	je	.L20
	movq	%rax, %rdi
	movq	%rbp, %rcx
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC11(%rip), %rdx
	call	__fprintf_chk@PLT
	jmp	.L21
.L20:
	movq	%rax, %rdi
	leaq	.LC12(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L21:
	leaq	258(%rsp), %rcx
	pushq	%rax
	.cfi_def_cfa_offset 568
	leaq	.LC13(%rip), %rdx
	movl	$2, %esi
	movq	%r12, %rdi
	leaq	246(%rsp), %rax
	pushq	%rax
	.cfi_def_cfa_offset 576
	leaq	264(%rsp), %rax
	pushq	%rax
	.cfi_def_cfa_offset 584
	leaq	252(%rsp), %rax
	pushq	%rax
	.cfi_def_cfa_offset 592
	xorl	%eax, %eax
	leaq	240(%rsp), %r9
	leaq	250(%rsp), %r8
	call	__fprintf_chk@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 560
	movq	%r12, %rdi
	call	fflush@PLT
	movq	%r12, %rdi
	call	fclose@PLT
	xorl	%edx, %edx
	movq	$0x000000000, kernel_time_acc(%rip)
	movq	%rdx, kernels_total_errors(%rip)
	movq	%rdx, iteration_number(%rip)
.L13:
	movq	488(%rsp), %rax
	subq	%fs:40, %rax
	je	.L22
	call	__stack_chk_fail@PLT
.L22:
	addq	$504, %rsp
	.cfi_def_cfa_offset 56
	movl	%ebx, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2046:
	.size	_Z14start_log_filePcS_, .-_Z14start_log_filePcS_
	.section	.rodata.str1.1
.LC15:
	.string	"[ERROR in log_string(char *)] Unable to open file %s\n"
.LC16:
	.string	"#END"
	.text
	.globl	_Z12end_log_filev
	.type	_Z12end_log_filev, @function
_Z12end_log_filev:
.LFB2047:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	full_log_file_name(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rbp, %rdi
	pushq	%rsi
	.cfi_def_cfa_offset 32
	leaq	.LC9(%rip), %rsi
	call	fopen@PLT
	testq	%rax, %rax
	jne	.L26
	movq	stderr(%rip), %rdi
	movq	%rbp, %rcx
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC15(%rip), %rdx
	call	__fprintf_chk@PLT
	movl	$1, %eax
	jmp	.L25
.L26:
	movq	%rax, %rbx
	leaq	.LC16(%rip), %rdx
	movl	$2, %esi
	movq	%rax, %rdi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	%rbx, %rdi
	call	fflush@PLT
	movq	%rbx, %rdi
	call	fclose@PLT
	xorl	%ecx, %ecx
	movb	$0, log_file_name(%rip)
	xorl	%eax, %eax
	movq	%rcx, kernels_total_errors(%rip)
	movq	%rcx, iteration_number(%rip)
	movq	$0x000000000, kernel_time_acc(%rip)
	movb	$0, absolute_path(%rip)
	movb	$0, full_log_file_name(%rip)
.L25:
	popq	%rdx
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2047:
	.size	_Z12end_log_filev, .-_Z12end_log_filev
	.globl	_Z15start_iterationv
	.type	_Z15start_iterationv, @function
_Z15start_iterationv:
.LFB2048:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	call	_Z16update_timestampv
	call	_Z8get_timev
	movq	%rax, it_time_start(%rip)
	xorl	%eax, %eax
	popq	%rdx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2048:
	.size	_Z15start_iterationv, .-_Z15start_iterationv
	.section	.rodata.str1.1
.LC18:
	.string	"#IT Ite:%lu KerTime:%f AccTime:%f\n"
	.text
	.globl	_Z13end_iterationv
	.type	_Z13end_iterationv, @function
_Z13end_iterationv:
.LFB2049:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	pushq	%rcx
	.cfi_def_cfa_offset 32
	call	_Z16update_timestampv
	call	_Z8get_timev
	subq	it_time_start(%rip), %rax
	movslq	iter_interval_print(%rip), %rcx
	xorl	%edx, %edx
	cvtsi2sdq	%rax, %xmm0
	movq	iteration_number(%rip), %rax
	divsd	.LC17(%rip), %xmm0
	movsd	%xmm0, kernel_time(%rip)
	addsd	kernel_time_acc(%rip), %xmm0
	divq	%rcx
	movsd	%xmm0, kernel_time_acc(%rip)
	testq	%rdx, %rdx
	jne	.L32
	leaq	full_log_file_name(%rip), %rbp
	leaq	.LC9(%rip), %rsi
	movq	%rbp, %rdi
	call	fopen@PLT
	movq	%rax, %rbx
	testq	%rax, %rax
	jne	.L33
	movq	stderr(%rip), %rdi
	movq	%rbp, %rcx
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC15(%rip), %rdx
	call	__fprintf_chk@PLT
	movl	$1, %eax
	jmp	.L31
.L33:
	movsd	kernel_time_acc(%rip), %xmm1
	movsd	kernel_time(%rip), %xmm0
	movq	%rax, %rdi
	leaq	.LC18(%rip), %rdx
	movq	iteration_number(%rip), %rcx
	movl	$2, %esi
	movb	$2, %al
	call	__fprintf_chk@PLT
	movq	%rbx, %rdi
	call	fflush@PLT
	movq	%rbx, %rdi
	call	fclose@PLT
.L32:
	incq	iteration_number(%rip)
	xorl	%eax, %eax
.L31:
	popq	%rdx
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2049:
	.size	_Z13end_iterationv, .-_Z13end_iterationv
	.section	.rodata.str1.1
.LC19:
	.string	"#SDC Ite:%lu KerTime:%f AccTime:%f KerErr:%lu AccErr:%lu\n"
.LC20:
	.string	"#ABORT too many errors per iteration\n"
.LC21:
	.string	"#ABORT amount of errors equals of the last iteration\n"
	.text
	.globl	_Z15log_error_countm
	.type	_Z15log_error_countm, @function
_Z15log_error_countm:
.LFB2050:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	call	_Z16update_timestampv
	testq	%rbp, %rbp
	je	.L37
	leaq	full_log_file_name(%rip), %r12
	leaq	.LC9(%rip), %rsi
	addq	%rbp, kernels_total_errors(%rip)
	movq	%r12, %rdi
	call	fopen@PLT
	movq	%rax, %rbx
	testq	%rax, %rax
	jne	.L38
	movq	stderr(%rip), %rdi
	movq	%r12, %rcx
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC15(%rip), %rdx
	call	__fprintf_chk@PLT
	movl	$1, %eax
	jmp	.L36
.L38:
	movq	iteration_number(%rip), %rax
	movq	kernels_total_errors(%rip), %r9
	leaq	.LC19(%rip), %rdx
	movq	%rbp, %r8
	movsd	kernel_time_acc(%rip), %xmm1
	movsd	kernel_time(%rip), %xmm0
	movl	$2, %esi
	movq	%rbx, %rdi
	leaq	-1(%rax), %rcx
	movb	$2, %al
	call	__fprintf_chk@PLT
	movq	%rbx, %rdi
	call	fflush@PLT
	cmpq	%rbp, max_errors_per_iter(%rip)
	leaq	.LC20(%rip), %rdx
	jb	.L46
	cmpq	%rbp, last_iter_errors(%rip)
	jne	.L41
	movq	last_iter_with_errors(%rip), %rax
	incq	%rax
	cmpq	iteration_number(%rip), %rax
	jne	.L41
	leaq	.LC21(%rip), %rdx
.L46:
	movl	$2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	%rbx, %rdi
	call	fflush@PLT
	movq	%rbx, %rdi
	call	fclose@PLT
	call	_Z12end_log_filev
	movl	$1, %edi
	call	exit@PLT
.L41:
	movq	%rbx, %rdi
	call	fclose@PLT
	movq	iteration_number(%rip), %rax
	movq	%rbp, last_iter_errors(%rip)
	movq	%rax, last_iter_with_errors(%rip)
.L37:
	xorl	%eax, %eax
.L36:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2050:
	.size	_Z15log_error_countm, .-_Z15log_error_countm
	.section	.rodata.str1.1
.LC22:
	.string	"#ERR "
.LC23:
	.string	"\n"
	.text
	.globl	_Z16log_error_detailPc
	.type	_Z16log_error_detailPc, @function
_Z16log_error_detailPc:
.LFB2051:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	full_log_file_name(%rip), %r12
	leaq	.LC9(%rip), %rsi
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rdi, %rbp
	movq	%r12, %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	call	fopen@PLT
	testq	%rax, %rax
	jne	.L48
	movq	stderr(%rip), %rdi
	movq	%r12, %rcx
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC15(%rip), %rdx
	call	__fprintf_chk@PLT
	movl	$1, %eax
	jmp	.L47
.L48:
	movq	%rax, %rbx
	movq	%rax, %rsi
	leaq	.LC22(%rip), %rdi
	call	fputs@PLT
	movq	%rbx, %rsi
	movq	%rbp, %rdi
	call	fputs@PLT
	movl	$2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	leaq	.LC23(%rip), %rdx
	call	__fprintf_chk@PLT
	movq	%rbx, %rdi
	call	fflush@PLT
	movq	%rbx, %rdi
	call	fclose@PLT
	xorl	%eax, %eax
.L47:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2051:
	.size	_Z16log_error_detailPc, .-_Z16log_error_detailPc
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2077:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2077:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.globl	it_time_start
	.bss
	.align 8
	.type	it_time_start, @object
	.size	it_time_start, 8
it_time_start:
	.zero	8
	.globl	kernel_time
	.align 8
	.type	kernel_time, @object
	.size	kernel_time, 8
kernel_time:
	.zero	8
	.globl	kernel_time_acc
	.align 8
	.type	kernel_time_acc, @object
	.size	kernel_time_acc, 8
kernel_time_acc:
	.zero	8
	.globl	iteration_number
	.align 8
	.type	iteration_number, @object
	.size	iteration_number, 8
iteration_number:
	.zero	8
	.globl	kernels_total_errors
	.align 8
	.type	kernels_total_errors, @object
	.size	kernels_total_errors, 8
kernels_total_errors:
	.zero	8
	.globl	last_iter_with_errors
	.align 8
	.type	last_iter_with_errors, @object
	.size	last_iter_with_errors, 8
last_iter_with_errors:
	.zero	8
	.globl	last_iter_errors
	.align 8
	.type	last_iter_errors, @object
	.size	last_iter_errors, 8
last_iter_errors:
	.zero	8
	.globl	full_log_file_name
	.align 32
	.type	full_log_file_name, @object
	.size	full_log_file_name, 300
full_log_file_name:
	.zero	300
	.globl	log_file_name
	.align 32
	.type	log_file_name, @object
	.size	log_file_name, 200
log_file_name:
	.zero	200
	.globl	iter_interval_print
	.data
	.align 4
	.type	iter_interval_print, @object
	.size	iter_interval_print, 4
iter_interval_print:
	.long	1
	.globl	absolute_path
	.align 32
	.type	absolute_path, @object
	.size	absolute_path, 200
absolute_path:
	.string	"/home/carol/logs/"
	.zero	182
	.globl	max_errors_per_iter
	.align 8
	.type	max_errors_per_iter, @object
	.size	max_errors_per_iter, 8
max_errors_per_iter:
	.quad	5000
	.globl	timestamp_watchdog
	.align 32
	.type	timestamp_watchdog, @object
	.size	timestamp_watchdog, 200
timestamp_watchdog:
	.string	"/home/carol/watchdog/timestamp.txt"
	.zero	165
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC17:
	.long	0
	.long	1093567616
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>


// Location of timetamp file for software watchdog
char timestamp_watchdog[200] = "/home/carol/watchdog/timestamp.txt";
// Max errors that can be found for a single iteration
// If more than max errors is found, exit the program
unsigned long int max_errors_per_iter = 5000;

// Absolute path for log file, if needed
char absolute_path[200] = "/home/carol/logs/";

// Used to print the log only for some iterations, equal 1 means print every iteration
int iter_interval_print = 1;

char log_file_name[200] = "";
char full_log_file_name[300] = "";

// Saves the last amount of error found for a specific iteration
unsigned long int last_iter_errors = 0;
// Saves the last iteration index that had an error
unsigned long int last_iter_with_errors = 0;

unsigned long int kernels_total_errors = 0;
unsigned long int iteration_number = 0;
double kernel_time_acc = 0;
double kernel_time = 0;
long long it_time_start;

// ~ ===========================================================================
inline long long get_time() {
    struct timeval tv;

    gettimeofday(&tv, NULL);

    return (tv.tv_sec * 1000000) + tv.tv_usec;
};

// ~ ===========================================================================
unsigned long int set_max_errors_iter(unsigned long int max_errors){
     max_errors_per_iter = max_errors;

     return max_errors_per_iter;
};

// ~ ===========================================================================
// Set the interval the program must print log details, default is 1 (each iteration)
int set_iter_interval_print(int interval){
    if(interval < 1) {
        iter_interval_print = 1;
    }
    else {
        iter_interval_print = interval;
    }

    return iter_interval_print;
};

// ~ ===========================================================================
// Update with current timestamp the file where the software watchdog watchs
void update_timestamp() {
    time_t timestamp = time(NULL);
    char time_s[50];
    char string[100] = "echo ";

    sprintf(time_s, "%d", (int) timestamp);

    strcat(string, time_s);
    strcat(string, " > ");
    strcat(string, timestamp_watchdog);
    system(string);
};

// ~ ===========================================================================
// In case the user needs the log to be generated in some exact absolute path
void set_absolute_path(char *path){
    strcpy(absolute_path, path);
};

// ~ ===========================================================================
// Return the name of the log file generated
char * get_log_file_name(){
    return full_log_file_name;
};

// ~ ===========================================================================
// Generate the log file name, log info from user about the test to be executed and reset log variables
int start_log_file(char *benchmark_name, char *test_info){

    update_timestamp();

    time_t file_time;
    struct tm *ptm;
    char day[10], month[10], year[15], hour[10], second[10], minute[10];
    char log_file_name[180] = "";

    file_time = time(NULL);
    ptm = gmtime(&file_time);

    snprintf(day,       sizeof(day),    "%02d", ptm->tm_mday);
    snprintf(month,     sizeof(month),  "%02d", ptm->tm_mon+1);
    snprintf(year,      sizeof(year),   "%04d", ptm->tm_year+1900);
    snprintf(hour,      sizeof(hour),   "%02d", ptm->tm_hour);
    snprintf(minute,    sizeof(minute), "%02d", ptm->tm_min);
    snprintf(second,    sizeof(second), "%02d", ptm->tm_sec);

    // ~ Get the host name to add inside the log name.
    char host[35] = "Host";
    int host_error = 0;
    host_error = gethostname(host, 35);

    if (host_error != 0) {
        fprintf(stderr, "[ERROR in gethostname(char *, int)] Could not access the host name\n");
        return 1;
    }

    strcpy(log_file_name, year);             strcat(log_file_name, "_");
    strcat(log_file_name, month);            strcat(log_file_name, "_");
    strcat(log_file_name, day);              strcat(log_file_name, "_");

    strcat(log_file_name, hour);             strcat(log_file_name, "_");
    strcat(log_file_name, minute);           strcat(log_file_name, "_");
    strcat(log_file_name, second);           strcat(log_file_name, "_");

    strcat(log_file_name, benchmark_name);   strcat(log_file_name, "_");
    strcat(log_file_name, host);
    strcat(log_file_name, ".log");


    strcpy(full_log_file_name, absolute_path);
    if(strlen(absolute_path) > 0 && absolute_path[strlen(absolute_path)-1] != '/' )
        strcat(full_log_file_name, "/");
    strcat(full_log_file_name, log_file_name);
// ~ printf("%s\n", full_log_file_name);

    struct stat buf;
    if (stat(full_log_file_name, &buf) == 0) {
        fprintf(stderr, "[ERROR in create_log_file(char *)] File already exists %s\n",full_log_file_name);
        return 1;
    }

    FILE *file = NULL;

    file = fopen(full_log_file_name, "a");
    if (file == NULL){
        fprintf(stderr, "[ERROR in create_log_file(char *)] Unable to open file %s\n",full_log_file_name);
        return 1;
    }
    else if(test_info != NULL) {
        fprintf(file, "#HEADER %s\n",test_info);
    }
    else {
        fprintf(file, "#HEADER\n");
    }

    fprintf(file, "#BEGIN Y:%s M:%s D:%s Time:%s:%s:%s\n", year, month, day, hour, minute, second);
    fflush(file);
    fclose(file);

    kernels_total_errors = 0;
    iteration_number = 0;
    kernel_time_acc = 0;

    return 0;
};

// ~ ===========================================================================
// Log the string "#END" and reset global variables
int end_log_file(){
    FILE *file = NULL;

    file = fopen(full_log_file_name, "a");
    if (file == NULL){
        fprintf(stderr, "[ERROR in log_string(char *)] Unable to open file %s\n",full_log_file_name);
        return 1;
    }

    fprintf(file, "#END");
    fflush(file);
    fclose(file);
    kernels_total_errors = 0;
    iteration_number = 0;
    kernel_time_acc = 0;
    strcpy(log_file_name, "");
    strcpy(absolute_path, "");
    strcpy(full_log_file_name, "");

    return 0;
};

// ~ ===========================================================================
// Start time to measure kernel time, also update iteration number and log to file
int start_iteration(){

    update_timestamp();

/*
    FILE *file = fopen(full_log_file_name, "a");

    if (file == NULL){
        fprintf(stderr, "[ERROR in log_string(char *)] Unable to open file %s\n",full_log_file_name);
        return 1;
    }

    fprintf(file, "#ITER it:%lu\n", iteration_number);
    fflush(file);
    fclose(file);
    iteration_number++;
*/
    it_time_start = get_time();
    return 0;

};

// ~ ===========================================================================
// Finish the measured kernel time log both time (total time and kernel time)
int end_iteration(){

    update_timestamp();

    kernel_time = (double) (get_time() - it_time_start) / 1000000;
    kernel_time_acc += kernel_time;



    if(iteration_number % iter_interval_print == 0) {

        FILE *file = fopen(full_log_file_name, "a");

        if (file == NULL){
            fprintf(stderr, "[ERROR in log_string(char *)] Unable to open file %s\n",full_log_file_name);
            return 1;
        }

        fprintf(file,"#IT Ite:%lu KerTime:%f AccTime:%f\n", iteration_number, kernel_time, kernel_time_acc);
        //fprintf(file, "#TIME kernel_time:%f\n", kernel_time);
        //fprintf(file, "#ACC_TIME total_time:%f\n", kernel_time_acc);
        fflush(file);
        fclose(file);
    }

    iteration_number++;

    return 0;

};

// ~ ===========================================================================
// Update total errors variable and log both errors(total errors and kernel errors)
int log_error_count(unsigned long int kernel_errors){

    update_timestamp();

    if(kernel_errors < 1) {
        return 0;
    }

    kernels_total_errors += kernel_errors;

    FILE *file = NULL;
    file = fopen(full_log_file_name, "a");

    if (file == NULL){
        fprintf(stderr, "[ERROR in log_string(char *)] Unable to open file %s\n",full_log_file_name);
        return 1;
    }

    // (iteration_number-1) because this function is called after end_iteration() that increments iteration_number
    fprintf(file, "#SDC Ite:%lu KerTime:%f AccTime:%f KerErr:%lu AccErr:%lu\n", iteration_number-1, kernel_time, kernel_time_acc, kernel_errors, kernels_total_errors);
    //fprintf(file, "#SDC kernel_errors:%lu\n", kernel_errors);
    //fprintf(file, "#TOTAL_SDC total_errors:%lu\n", kernels_total_errors);
    fflush(file);


    if(kernel_errors > max_errors_per_iter){
        fprintf(file, "#ABORT too many errors per iteration\n");
        fflush(file);
        fclose(file);
        end_log_file();
        exit(1);
    }


    if(kernel_errors == last_iter_errors && (last_iter_with_errors+1) == iteration_number && kernel_errors != 0){
        fprintf(file, "#ABORT amount of errors equals of the last iteration\n");
        fflush(file);
        fclose(file);
        end_log_file();
        exit(1);
    }

    fclose(file);

    last_iter_errors = kernel_errors;
    last_iter_with_errors = iteration_number;

    return 0;

};

// ~ ===========================================================================
// Print some string with the detail of an error to log file
int log_error_detail(char *string){
    FILE *file = NULL;

    file = fopen(full_log_file_name, "a");
    if (file == NULL){
        fprintf(stderr, "[ERROR in log_string(char *)] Unable to open file %s\n",full_log_file_name);
        return 1;
    }

    fputs("#ERR ", file);
    fputs(string, file);
    fprintf(file, "\n");
    fflush(file);
    fclose(file);
    return 0;
};


	.text
	.file	"log_helper.hip"
	.globl	_Z19set_max_errors_iterm        # -- Begin function _Z19set_max_errors_iterm
	.type	_Z19set_max_errors_iterm,@function
_Z19set_max_errors_iterm:               # @_Z19set_max_errors_iterm
	.cfi_startproc
# %bb.0:
	movq	%rdi, %rax
	movq	%rdi, max_errors_per_iter(%rip)
	retq
.Lfunc_end0:
	.size	_Z19set_max_errors_iterm, .Lfunc_end0-_Z19set_max_errors_iterm
	.cfi_endproc
                                        # -- End function
	.globl	_Z23set_iter_interval_printi    # -- Begin function _Z23set_iter_interval_printi
	.type	_Z23set_iter_interval_printi,@function
_Z23set_iter_interval_printi:           # @_Z23set_iter_interval_printi
	.cfi_startproc
# %bb.0:
	cmpl	$2, %edi
	movl	$1, %eax
	cmovgel	%edi, %eax
	movl	%eax, iter_interval_print(%rip)
	retq
.Lfunc_end1:
	.size	_Z23set_iter_interval_printi, .Lfunc_end1-_Z23set_iter_interval_printi
	.cfi_endproc
                                        # -- End function
	.globl	_Z16update_timestampv           # -- Begin function _Z16update_timestampv
	.type	_Z16update_timestampv,@function
_Z16update_timestampv:                  # @_Z16update_timestampv
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	subq	$168, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	xorl	%edi, %edi
	callq	time
	xorps	%xmm0, %xmm0
	movq	%rsp, %rbx
	movaps	%xmm0, (%rbx)
	movaps	%xmm0, 80(%rbx)
	movaps	%xmm0, 64(%rbx)
	movaps	%xmm0, 48(%rbx)
	movaps	%xmm0, 32(%rbx)
	movaps	%xmm0, 16(%rbx)
	movl	$0, 96(%rbx)
	movl	$1869112165, (%rbx)             # imm = 0x6F686365
	movb	$32, 4(%rbx)
	leaq	112(%rsp), %r14
	movl	$.L.str, %esi
	movq	%r14, %rdi
	movl	%eax, %edx
	xorl	%eax, %eax
	callq	sprintf
	movq	%rbx, %rdi
	movq	%r14, %rsi
	callq	strcat
	movq	%rbx, %rdi
	callq	strlen
	movl	$2113056, (%rsp,%rax)           # imm = 0x203E20
	movl	$timestamp_watchdog, %esi
	movq	%rbx, %rdi
	callq	strcat
	movq	%rbx, %rdi
	callq	system
	addq	$168, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z16update_timestampv, .Lfunc_end2-_Z16update_timestampv
	.cfi_endproc
                                        # -- End function
	.globl	_Z17set_absolute_pathPc         # -- Begin function _Z17set_absolute_pathPc
	.type	_Z17set_absolute_pathPc,@function
_Z17set_absolute_pathPc:                # @_Z17set_absolute_pathPc
	.cfi_startproc
# %bb.0:
	movq	%rdi, %rsi
	movl	$absolute_path, %edi
	jmp	strcpy                          # TAILCALL
.Lfunc_end3:
	.size	_Z17set_absolute_pathPc, .Lfunc_end3-_Z17set_absolute_pathPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z17get_log_file_namev          # -- Begin function _Z17get_log_file_namev
	.type	_Z17get_log_file_namev,@function
_Z17get_log_file_namev:                 # @_Z17get_log_file_namev
	.cfi_startproc
# %bb.0:
	movl	$full_log_file_name, %eax
	retq
.Lfunc_end4:
	.size	_Z17get_log_file_namev, .Lfunc_end4-_Z17get_log_file_namev
	.cfi_endproc
                                        # -- End function
	.globl	_Z14start_log_filePcS_          # -- Begin function _Z14start_log_filePcS_
	.type	_Z14start_log_filePcS_,@function
_Z14start_log_filePcS_:                 # @_Z14start_log_filePcS_
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$456, %rsp                      # imm = 0x1C8
	.cfi_def_cfa_offset 512
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	movq	%rdi, %r14
	callq	_Z16update_timestampv
	leaq	80(%rsp), %rdi
	movl	$180, %edx
	xorl	%esi, %esi
	callq	memset@PLT
	xorl	%edi, %edi
	callq	time
	leaq	72(%rsp), %rdi
	movq	%rax, (%rdi)
	callq	gmtime
	movq	%rax, %r15
	movl	12(%rax), %ecx
	leaq	27(%rsp), %rdi
	movl	$10, %esi
	movl	$.L.str.2, %edx
	xorl	%eax, %eax
	callq	snprintf
	movl	16(%r15), %ecx
	incl	%ecx
	leaq	17(%rsp), %rdi
	movl	$10, %esi
	movl	$.L.str.2, %edx
	xorl	%eax, %eax
	callq	snprintf
	movl	$1900, %ecx                     # imm = 0x76C
	addl	20(%r15), %ecx
	leaq	57(%rsp), %rdi
	movl	$15, %esi
	movl	$.L.str.3, %edx
	xorl	%eax, %eax
	callq	snprintf
	movl	8(%r15), %ecx
	leaq	7(%rsp), %rdi
	movl	$10, %esi
	movl	$.L.str.2, %edx
	xorl	%eax, %eax
	callq	snprintf
	movl	4(%r15), %ecx
	leaq	37(%rsp), %rdi
	movl	$10, %esi
	movl	$.L.str.2, %edx
	xorl	%eax, %eax
	callq	snprintf
	movl	(%r15), %ecx
	leaq	47(%rsp), %rdi
	movl	$10, %esi
	movl	$.L.str.2, %edx
	xorl	%eax, %eax
	callq	snprintf
	xorps	%xmm0, %xmm0
	leaq	272(%rsp), %rdi
	movaps	%xmm0, (%rdi)
	movaps	%xmm0, 16(%rdi)
	movl	$0, 31(%rdi)
	movl	$1953722184, (%rdi)             # imm = 0x74736F48
	movl	$35, %esi
	callq	gethostname
	testl	%eax, %eax
	jne	.LBB5_11
# %bb.1:
	leaq	80(%rsp), %r13
	leaq	57(%rsp), %rsi
	movq	%r13, %rdi
	callq	strcpy
	movq	%r13, %rdi
	callq	strlen
	movw	$95, %bp
	movw	%bp, 80(%rsp,%rax)
	leaq	17(%rsp), %rsi
	movq	%r13, %rdi
	callq	strcat
	movq	%r13, %rdi
	callq	strlen
	movw	%bp, 80(%rsp,%rax)
	leaq	27(%rsp), %rsi
	movq	%r13, %rdi
	callq	strcat
	movq	%r13, %rdi
	callq	strlen
	movw	%bp, 80(%rsp,%rax)
	leaq	7(%rsp), %rsi
	movq	%r13, %rdi
	callq	strcat
	movq	%r13, %rdi
	callq	strlen
	movw	%bp, 80(%rsp,%rax)
	leaq	37(%rsp), %r15
	movq	%r13, %rdi
	movq	%r15, %rsi
	callq	strcat
	movq	%r13, %rdi
	callq	strlen
	movw	%bp, 80(%rsp,%rax)
	leaq	47(%rsp), %r12
	movq	%r13, %rdi
	movq	%r12, %rsi
	callq	strcat
	movq	%r13, %rdi
	callq	strlen
	movw	%bp, 80(%rsp,%rax)
	movq	%r13, %rdi
	movq	%r14, %rsi
	callq	strcat
	movq	%r13, %rdi
	callq	strlen
	movw	%bp, 80(%rsp,%rax)
	leaq	272(%rsp), %rsi
	movq	%r13, %rdi
	callq	strcat
	movq	%r13, %rdi
	callq	strlen
	movl	$1735355438, 80(%rsp,%rax)      # imm = 0x676F6C2E
	movb	$0, 84(%rsp,%rax)
	movl	$full_log_file_name, %edi
	movl	$absolute_path, %esi
	callq	strcpy
	movl	$absolute_path, %edi
	callq	strlen
	testq	%rax, %rax
	je	.LBB5_4
# %bb.2:
	cmpb	$47, absolute_path-1(%rax)
	je	.LBB5_4
# %bb.3:
	movl	$full_log_file_name, %edi
	callq	strlen
	movw	$47, full_log_file_name(%rax)
.LBB5_4:
	leaq	80(%rsp), %rsi
	movl	$full_log_file_name, %edi
	callq	strcat
	leaq	312(%rsp), %rsi
	movl	$full_log_file_name, %edi
	callq	stat
	testl	%eax, %eax
	je	.LBB5_12
# %bb.5:
	movl	$full_log_file_name, %edi
	movl	$.L.str.9, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB5_13
# %bb.6:
	movq	%rax, %r14
	testq	%rbx, %rbx
	je	.LBB5_8
# %bb.7:
	movl	$.L.str.11, %esi
	movq	%r14, %rdi
	movq	%rbx, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB5_9
.LBB5_8:
	movl	$.L.str.12, %edi
	movl	$8, %esi
	movl	$1, %edx
	movq	%r14, %rcx
	callq	fwrite@PLT
.LBB5_9:
	xorl	%ebx, %ebx
	leaq	57(%rsp), %rdx
	leaq	17(%rsp), %rcx
	leaq	27(%rsp), %r8
	leaq	7(%rsp), %r9
	movl	$.L.str.13, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	pushq	%r12
	.cfi_adjust_cfa_offset 8
	pushq	%r15
	.cfi_adjust_cfa_offset 8
	callq	fprintf
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
	movq	%r14, %rdi
	callq	fflush
	movq	%r14, %rdi
	callq	fclose
	movq	%rbx, kernels_total_errors(%rip)
	movq	%rbx, iteration_number(%rip)
	movq	%rbx, kernel_time_acc(%rip)
.LBB5_10:
	movl	%ebx, %eax
	addq	$456, %rsp                      # imm = 0x1C8
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB5_11:
	.cfi_def_cfa_offset 512
	movq	stderr(%rip), %rcx
	movl	$.L.str.4, %edi
	movl	$67, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	jmp	.LBB5_15
.LBB5_12:
	movq	stderr(%rip), %rdi
	movl	$.L.str.8, %esi
	jmp	.LBB5_14
.LBB5_13:
	movq	stderr(%rip), %rdi
	movl	$.L.str.10, %esi
.LBB5_14:
	movl	$full_log_file_name, %edx
	xorl	%eax, %eax
	callq	fprintf
.LBB5_15:
	movl	$1, %ebx
	jmp	.LBB5_10
.Lfunc_end5:
	.size	_Z14start_log_filePcS_, .Lfunc_end5-_Z14start_log_filePcS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z12end_log_filev               # -- Begin function _Z12end_log_filev
	.type	_Z12end_log_filev,@function
_Z12end_log_filev:                      # @_Z12end_log_filev
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	$full_log_file_name, %edi
	movl	$.L.str.9, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB6_1
# %bb.2:
	movq	%rax, %rbx
	movl	$.L.str.15, %edi
	movl	$4, %esi
	movl	$1, %edx
	movq	%rax, %rcx
	callq	fwrite@PLT
	movq	%rbx, %rdi
	callq	fflush
	movq	%rbx, %rdi
	callq	fclose
	xorl	%eax, %eax
	movq	%rax, kernels_total_errors(%rip)
	movq	%rax, iteration_number(%rip)
	movq	%rax, kernel_time_acc(%rip)
	movb	%al, log_file_name(%rip)
	movb	%al, absolute_path(%rip)
	movb	%al, full_log_file_name(%rip)
.LBB6_3:
                                        # kill: def $eax killed $eax killed $rax
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB6_1:
	.cfi_def_cfa_offset 16
	movq	stderr(%rip), %rdi
	movl	$.L.str.14, %esi
	movl	$full_log_file_name, %edx
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %eax
	jmp	.LBB6_3
.Lfunc_end6:
	.size	_Z12end_log_filev, .Lfunc_end6-_Z12end_log_filev
	.cfi_endproc
                                        # -- End function
	.globl	_Z15start_iterationv            # -- Begin function _Z15start_iterationv
	.type	_Z15start_iterationv,@function
_Z15start_iterationv:                   # @_Z15start_iterationv
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -16
	callq	_Z16update_timestampv
	movq	%rsp, %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	imulq	$1000000, (%rbx), %rax          # imm = 0xF4240
	addq	8(%rbx), %rax
	movq	%rax, it_time_start(%rip)
	xorl	%eax, %eax
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end7:
	.size	_Z15start_iterationv, .Lfunc_end7-_Z15start_iterationv
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z13end_iterationv
.LCPI8_0:
	.quad	0x412e848000000000              # double 1.0E+6
	.text
	.globl	_Z13end_iterationv
	.type	_Z13end_iterationv,@function
_Z13end_iterationv:                     # @_Z13end_iterationv
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	callq	_Z16update_timestampv
	xorl	%ebx, %ebx
	leaq	8(%rsp), %r14
	movq	%r14, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	imulq	$1000000, (%r14), %rax          # imm = 0xF4240
	addq	8(%r14), %rax
	subq	it_time_start(%rip), %rax
	cvtsi2sd	%rax, %xmm0
	divsd	.LCPI8_0(%rip), %xmm0
	movsd	%xmm0, kernel_time(%rip)
	addsd	kernel_time_acc(%rip), %xmm0
	movsd	%xmm0, kernel_time_acc(%rip)
	movq	iteration_number(%rip), %rcx
	movslq	iter_interval_print(%rip), %rsi
	movq	%rcx, %rax
	xorl	%edx, %edx
	divq	%rsi
	testq	%rdx, %rdx
	jne	.LBB8_3
# %bb.1:
	movl	$full_log_file_name, %edi
	movl	$.L.str.9, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB8_5
# %bb.2:                                # %.thread
	movq	%rax, %r14
	movq	iteration_number(%rip), %rdx
	movsd	kernel_time(%rip), %xmm0        # xmm0 = mem[0],zero
	movsd	kernel_time_acc(%rip), %xmm1    # xmm1 = mem[0],zero
	movl	$.L.str.17, %esi
	movq	%rax, %rdi
	movb	$2, %al
	callq	fprintf
	movq	%r14, %rdi
	callq	fflush
	movq	%r14, %rdi
	callq	fclose
	movq	iteration_number(%rip), %rcx
.LBB8_3:
	incq	%rcx
	movq	%rcx, iteration_number(%rip)
.LBB8_4:
	movl	%ebx, %eax
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.LBB8_5:
	.cfi_def_cfa_offset 48
	movq	stderr(%rip), %rdi
	movl	$.L.str.14, %esi
	movl	$full_log_file_name, %edx
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %ebx
	jmp	.LBB8_4
.Lfunc_end8:
	.size	_Z13end_iterationv, .Lfunc_end8-_Z13end_iterationv
	.cfi_endproc
                                        # -- End function
	.globl	_Z15log_error_countm            # -- Begin function _Z15log_error_countm
	.type	_Z15log_error_countm,@function
_Z15log_error_countm:                   # @_Z15log_error_countm
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %rbp, -16
	movq	%rdi, %r14
	callq	_Z16update_timestampv
	xorl	%ebp, %ebp
	testq	%r14, %r14
	je	.LBB9_10
# %bb.1:
	addq	%r14, kernels_total_errors(%rip)
	movl	$full_log_file_name, %edi
	movl	$.L.str.9, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB9_2
# %bb.3:
	movq	%rax, %rbx
	movq	iteration_number(%rip), %rdx
	decq	%rdx
	movsd	kernel_time(%rip), %xmm0        # xmm0 = mem[0],zero
	movsd	kernel_time_acc(%rip), %xmm1    # xmm1 = mem[0],zero
	movq	kernels_total_errors(%rip), %r8
	movl	$.L.str.18, %esi
	movq	%rax, %rdi
	movq	%r14, %rcx
	movb	$2, %al
	callq	fprintf
	movq	%rbx, %rdi
	callq	fflush
	cmpq	%r14, max_errors_per_iter(%rip)
	jb	.LBB9_4
# %bb.6:
	cmpq	%r14, last_iter_errors(%rip)
	jne	.LBB9_9
# %bb.7:
	movq	last_iter_with_errors(%rip), %rax
	incq	%rax
	cmpq	iteration_number(%rip), %rax
	je	.LBB9_8
.LBB9_9:
	movq	%rbx, %rdi
	callq	fclose
	movq	%r14, last_iter_errors(%rip)
	movq	iteration_number(%rip), %rax
	movq	%rax, last_iter_with_errors(%rip)
.LBB9_10:
	movl	%ebp, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB9_2:
	.cfi_def_cfa_offset 32
	movq	stderr(%rip), %rdi
	movl	$.L.str.14, %esi
	movl	$full_log_file_name, %edx
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %ebp
	jmp	.LBB9_10
.LBB9_4:
	movl	$.L.str.19, %edi
	movl	$37, %esi
	jmp	.LBB9_5
.LBB9_8:
	movl	$.L.str.20, %edi
	movl	$53, %esi
.LBB9_5:
	movl	$1, %edx
	movq	%rbx, %rcx
	callq	fwrite@PLT
	movq	%rbx, %rdi
	callq	fflush
	movq	%rbx, %rdi
	callq	fclose
	callq	_Z12end_log_filev
	movl	$1, %edi
	callq	exit
.Lfunc_end9:
	.size	_Z15log_error_countm, .Lfunc_end9-_Z15log_error_countm
	.cfi_endproc
                                        # -- End function
	.globl	_Z16log_error_detailPc          # -- Begin function _Z16log_error_detailPc
	.type	_Z16log_error_detailPc,@function
_Z16log_error_detailPc:                 # @_Z16log_error_detailPc
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movq	%rdi, %r14
	movl	$full_log_file_name, %edi
	movl	$.L.str.9, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB10_1
# %bb.2:
	movq	%rax, %rbx
	movl	$.L.str.21, %edi
	movq	%rax, %rsi
	callq	fputs
	movq	%r14, %rdi
	movq	%rbx, %rsi
	callq	fputs
	movl	$10, %edi
	movq	%rbx, %rsi
	callq	fputc@PLT
	movq	%rbx, %rdi
	callq	fflush
	movq	%rbx, %rdi
	callq	fclose
	xorl	%eax, %eax
.LBB10_3:
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.LBB10_1:
	.cfi_def_cfa_offset 32
	movq	stderr(%rip), %rdi
	movl	$.L.str.14, %esi
	movl	$full_log_file_name, %edx
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %eax
	jmp	.LBB10_3
.Lfunc_end10:
	.size	_Z16log_error_detailPc, .Lfunc_end10-_Z16log_error_detailPc
	.cfi_endproc
                                        # -- End function
	.type	timestamp_watchdog,@object      # @timestamp_watchdog
	.data
	.globl	timestamp_watchdog
	.p2align	4, 0x0
timestamp_watchdog:
	.asciz	"/home/carol/watchdog/timestamp.txt\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
	.size	timestamp_watchdog, 200

	.type	max_errors_per_iter,@object     # @max_errors_per_iter
	.globl	max_errors_per_iter
	.p2align	3, 0x0
max_errors_per_iter:
	.quad	5000                            # 0x1388
	.size	max_errors_per_iter, 8

	.type	absolute_path,@object           # @absolute_path
	.globl	absolute_path
	.p2align	4, 0x0
absolute_path:
	.asciz	"/home/carol/logs/\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
	.size	absolute_path, 200

	.type	iter_interval_print,@object     # @iter_interval_print
	.globl	iter_interval_print
	.p2align	2, 0x0
iter_interval_print:
	.long	1                               # 0x1
	.size	iter_interval_print, 4

	.type	log_file_name,@object           # @log_file_name
	.bss
	.globl	log_file_name
	.p2align	4, 0x0
log_file_name:
	.zero	200
	.size	log_file_name, 200

	.type	full_log_file_name,@object      # @full_log_file_name
	.globl	full_log_file_name
	.p2align	4, 0x0
full_log_file_name:
	.zero	300
	.size	full_log_file_name, 300

	.type	last_iter_errors,@object        # @last_iter_errors
	.globl	last_iter_errors
	.p2align	3, 0x0
last_iter_errors:
	.quad	0                               # 0x0
	.size	last_iter_errors, 8

	.type	last_iter_with_errors,@object   # @last_iter_with_errors
	.globl	last_iter_with_errors
	.p2align	3, 0x0
last_iter_with_errors:
	.quad	0                               # 0x0
	.size	last_iter_with_errors, 8

	.type	kernels_total_errors,@object    # @kernels_total_errors
	.globl	kernels_total_errors
	.p2align	3, 0x0
kernels_total_errors:
	.quad	0                               # 0x0
	.size	kernels_total_errors, 8

	.type	iteration_number,@object        # @iteration_number
	.globl	iteration_number
	.p2align	3, 0x0
iteration_number:
	.quad	0                               # 0x0
	.size	iteration_number, 8

	.type	kernel_time_acc,@object         # @kernel_time_acc
	.globl	kernel_time_acc
	.p2align	3, 0x0
kernel_time_acc:
	.quad	0x0000000000000000              # double 0
	.size	kernel_time_acc, 8

	.type	kernel_time,@object             # @kernel_time
	.globl	kernel_time
	.p2align	3, 0x0
kernel_time:
	.quad	0x0000000000000000              # double 0
	.size	kernel_time, 8

	.type	it_time_start,@object           # @it_time_start
	.globl	it_time_start
	.p2align	3, 0x0
it_time_start:
	.quad	0                               # 0x0
	.size	it_time_start, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%d"
	.size	.L.str, 3

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"%02d"
	.size	.L.str.2, 5

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"%04d"
	.size	.L.str.3, 5

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"[ERROR in gethostname(char *, int)] Could not access the host name\n"
	.size	.L.str.4, 68

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	".log"
	.size	.L.str.6, 5

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"[ERROR in create_log_file(char *)] File already exists %s\n"
	.size	.L.str.8, 59

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"a"
	.size	.L.str.9, 2

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"[ERROR in create_log_file(char *)] Unable to open file %s\n"
	.size	.L.str.10, 59

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"#HEADER %s\n"
	.size	.L.str.11, 12

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"#HEADER\n"
	.size	.L.str.12, 9

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"#BEGIN Y:%s M:%s D:%s Time:%s:%s:%s\n"
	.size	.L.str.13, 37

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"[ERROR in log_string(char *)] Unable to open file %s\n"
	.size	.L.str.14, 54

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"#END"
	.size	.L.str.15, 5

	.type	.L.str.17,@object               # @.str.17
.L.str.17:
	.asciz	"#IT Ite:%lu KerTime:%f AccTime:%f\n"
	.size	.L.str.17, 35

	.type	.L.str.18,@object               # @.str.18
.L.str.18:
	.asciz	"#SDC Ite:%lu KerTime:%f AccTime:%f KerErr:%lu AccErr:%lu\n"
	.size	.L.str.18, 58

	.type	.L.str.19,@object               # @.str.19
.L.str.19:
	.asciz	"#ABORT too many errors per iteration\n"
	.size	.L.str.19, 38

	.type	.L.str.20,@object               # @.str.20
.L.str.20:
	.asciz	"#ABORT amount of errors equals of the last iteration\n"
	.size	.L.str.20, 54

	.type	.L.str.21,@object               # @.str.21
.L.str.21:
	.asciz	"#ERR "
	.size	.L.str.21, 6

	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym timestamp_watchdog
	.addrsig_sym absolute_path
	.addrsig_sym full_log_file_name
	.addrsig_sym __hip_cuid_

	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
