// File: /workspace/github_c_makefile_star2_O0/Matthias-Wandel[P]imgcomp/src/util.c
// Function: LogFileMaintain
void LogFileMaintain(int ForceLogSaveReboot)
{
    static char ThisLogTo[PATH_MAX];
    char NewLogTo[PATH_MAX];
    
    int HaveLogAlready;

    if (LogToFile[0] == 0){
        Log = stdout;
        return;
    }
    HaveLogAlready = (Log != NULL);
   
    if (MoveLogNames[0]){
        strftime(NewLogTo, PATH_MAX, MoveLogNames, localtime(&LastPic_mtime));
		if (ForceLogSaveReboot){
			// Just change the old name, so it gets backed up, and not overwritten
			// by new log after reboot.
			strcat(ThisLogTo, " reboot");
			printf("modified log name: %s\n",ThisLogTo);
		}
        if (strcmp(ThisLogTo, NewLogTo)){
            if (Log != NULL){
                if (BackupImageCount){
                    printf("Log rotate %s --> %s\n", ThisLogTo, NewLogTo);
                    fprintf(Log,"Log rotate %s --> %s\n", ThisLogTo, NewLogTo);
                    EnsurePathExists(ThisLogTo, 1);
                    fclose(Log);
                    Log = NULL;
                    CopyFile(LogToFile, ThisLogTo);
                    unlink(LogToFile);
                    BackupImageCount = 0;
                }else{
                    fprintf(Log,"Skip log rotate to %s (no images were saved in dir)\n", NewLogTo);
                    strncpy(ThisLogTo, NewLogTo, PATH_MAX);
                }
            }
        }
    }
    
    if (Log == NULL){
        Log = fopen(LogToFile,"a");
        if (Log == NULL){
            fprintf(stderr, "Failed to open log file %s\n",LogToFile);
            exit(-1);
        }
        if (HaveLogAlready){
            fprintf(Log,"<pre>Rotated log file (previous %s)\n",ThisLogTo);
        }else{
            fprintf(Log,"\n\n----------Restarting imcomp, keep old log---------------\n");
        }
        if (ThisLogTo[0]){
            strncpy(ThisLogTo, NewLogTo, PATH_MAX);
        }
        strcpy(ThisLogTo, NewLogTo);        
    }
    
    static int lastmin = 0;
    time_t now;
    time(&now);
    struct tm * nowTm = localtime(&now);
    if (nowTm->tm_min != lastmin && Log != NULL){
        // Put an indexable tag into the log file every minute.
        fprintf(Log, "<z id=\"%02d\"/>\n", nowTm->tm_min);
        lastmin = nowTm->tm_min;
    }
    
    fflush(Log); // Assuming logging to ramdisk, or we wear out flash.
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1030, %rsp           # imm = 0x1030
movl %edi, -0x4(%rbp)
leaq 0x879b(%rip), %rax      # 0x14e80
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0xc706
movq 0x78dc(%rip), %rax      # 0x13fd0
movq (%rax), %rcx
leaq 0x891a(%rip), %rax      # 0x15018
movq %rcx, (%rax)
jmp 0xca00
leaq 0x890b(%rip), %rax      # 0x15018
cmpq $0x0, (%rax)
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x1014(%rbp)
leaq 0x882a(%rip), %rax      # 0x14f50
cmpb $0x0, (%rax)
je 0xc8a4
leaq -0x1010(%rbp), %rax
movq %rax, -0x1030(%rbp)
leaq 0x7c24(%rip), %rdi      # 0x14368
callq 0x3060
movq -0x1030(%rbp), %rdi
movq %rax, %rcx
movl $0x1000, %esi           # imm = 0x1000
leaq 0x87f1(%rip), %rdx      # 0x14f50
callq 0x33f0
cmpl $0x0, -0x4(%rbp)
je 0xc792
leaq 0xa3bf(%rip), %rdi      # 0x16b30
leaq 0x4b99(%rip), %rsi      # 0x11311
callq 0x3460
leaq 0x4b95(%rip), %rdi      # 0x11319
leaq 0xa3a5(%rip), %rsi      # 0x16b30
movb $0x0, %al
callq 0x3170
leaq -0x1010(%rbp), %rsi
leaq 0xa390(%rip), %rdi      # 0x16b30
callq 0x3250
cmpl $0x0, %eax
je 0xc8a2
leaq 0x8863(%rip), %rax      # 0x15018
cmpq $0x0, (%rax)
je 0xc8a0
cmpl $0x0, 0xa35a(%rip)      # 0x16b20
je 0xc867
leaq -0x1010(%rbp), %rdx
leaq 0x4b56(%rip), %rdi      # 0x11330
leaq 0xa34f(%rip), %rsi      # 0x16b30
movb $0x0, %al
callq 0x3170
leaq 0x8829(%rip), %rax      # 0x15018
movq (%rax), %rdi
leaq -0x1010(%rbp), %rcx
leaq 0x4b30(%rip), %rsi      # 0x11330
leaq 0xa329(%rip), %rdx      # 0x16b30
movb $0x0, %al
callq 0x3290
leaq 0xa31b(%rip), %rdi      # 0x16b30
movl $0x1, %esi
callq 0xbb80
leaq 0x87f2(%rip), %rax      # 0x15018
movq (%rax), %rdi
callq 0x3110
leaq 0x87e3(%rip), %rax      # 0x15018
movq $0x0, (%rax)
leaq 0x863d(%rip), %rdi      # 0x14e80
leaq 0xa2e6(%rip), %rsi      # 0x16b30
callq 0xc540
leaq 0x862a(%rip), %rdi      # 0x14e80
callq 0x3080
movl $0x0, 0xa2bb(%rip)      # 0x16b20
jmp 0xc89e
leaq 0x87aa(%rip), %rax      # 0x15018
movq (%rax), %rdi
leaq -0x1010(%rbp), %rdx
leaq 0x4ac7(%rip), %rsi      # 0x11346
movb $0x0, %al
callq 0x3290
leaq -0x1010(%rbp), %rsi
leaq 0xa29c(%rip), %rdi      # 0x16b30
movl $0x1000, %edx           # imm = 0x1000
callq 0x3090
jmp 0xc8a0
jmp 0xc8a2
jmp 0xc8a4
leaq 0x876d(%rip), %rax      # 0x15018
cmpq $0x0, (%rax)
jne 0xc981
leaq 0x85c4(%rip), %rdi      # 0x14e80
leaq 0x4591(%rip), %rsi      # 0x10e54
callq 0x3420
movq %rax, %rcx
leaq 0x8746(%rip), %rax      # 0x15018
movq %rcx, (%rax)
leaq 0x873c(%rip), %rax      # 0x15018
cmpq $0x0, (%rax)
jne 0xc90b
movq 0x7707(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x4a88(%rip), %rsi      # 0x1137b
leaq 0x8586(%rip), %rdx      # 0x14e80
movb $0x0, %al
callq 0x3290
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3480
cmpl $0x0, -0x1014(%rbp)
je 0xc935
leaq 0x86fd(%rip), %rax      # 0x15018
movq (%rax), %rdi
leaq 0x4a72(%rip), %rsi      # 0x11397
leaq 0xa204(%rip), %rdx      # 0x16b30
movb $0x0, %al
callq 0x3290
jmp 0xc94d
leaq 0x86dc(%rip), %rax      # 0x15018
movq (%rax), %rdi
leaq 0x4a76(%rip), %rsi      # 0x113bc
movb $0x0, %al
callq 0x3290
cmpb $0x0, 0xa1dc(%rip)      # 0x16b30
je 0xc96e
leaq -0x1010(%rbp), %rsi
leaq 0xa1cc(%rip), %rdi      # 0x16b30
movl $0x1000, %edx           # imm = 0x1000
callq 0x3090
leaq -0x1010(%rbp), %rsi
leaq 0xa1b4(%rip), %rdi      # 0x16b30
callq 0x30b0
leaq -0x1020(%rbp), %rdi
callq 0x3300
leaq -0x1020(%rbp), %rdi
callq 0x3060
movq %rax, -0x1028(%rbp)
movq -0x1028(%rbp), %rax
movl 0x4(%rax), %eax
cmpl 0xb180(%rip), %eax      # 0x17b30
je 0xc9f1
leaq 0x865f(%rip), %rax      # 0x15018
cmpq $0x0, (%rax)
je 0xc9f1
leaq 0x8652(%rip), %rax      # 0x15018
movq (%rax), %rdi
movq -0x1028(%rbp), %rax
movl 0x4(%rax), %edx
leaq 0x4a1e(%rip), %rsi      # 0x113f8
movb $0x0, %al
callq 0x3290
movq -0x1028(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, 0xb13f(%rip)      # 0x17b30
leaq 0x8620(%rip), %rax      # 0x15018
movq (%rax), %rdi
callq 0x3340
addq $0x1030, %rsp           # imm = 0x1030
popq %rbp
retq
nopl (%rax)