// File: /workspace/github_c_makefile_star2_O2/Matthias-Wandel[P]imgcomp/src/util.c
// Function: BackupImageFile
char * BackupImageFile(char * Name, int DiffMag, int DoNotCopy)
{
    static char DstPath[500];
    static char SuffixChar = ' ';
    static time_t LastSaveTime;
    char * extension;
    int a;
    struct stat statbuf;    
    time_t mtime;
    
    if (SaveDir[0] == '\0') return NULL; // Picture saving not enabled.
    
    if (stat(Name, &statbuf) == -1) {
        perror(Name);
        exit(1);
    }
    mtime = statbuf.st_mtime;
        
    // Get extension (.jpg or .mp4) of file we started with.
    extension = "\0";
    for (a=0;Name[a];a++){
        if (Name[a] == '.') extension = Name+a;
    }

    {
        char NameSuffix[20];
        if (LastSaveTime == mtime){
            // If it's the same second, cycle through suffixes a-z
            SuffixChar = (SuffixChar >= 'a' && SuffixChar <'z') ? SuffixChar+1 : 'a';
        }else{
            // New time. No need for a suffix.
            SuffixChar = ' ';
            LastSaveTime = mtime;
        }
        sprintf(NameSuffix, "%c%04d%s",SuffixChar, DiffMag, extension);
        DestNameFromTime(DstPath, SaveDir, mtime, NameSuffix);
        EnsurePathExists(DstPath, 1);
        if (!DoNotCopy){
            if (CopyJpgCmd[0]){
                // Apply a command, such as jpegtran to copy the file
                CopyJpgFileCmd(Name, DstPath);
            }else{
                // Just copy it from inside the program.
                CopyFile(Name, DstPath);
            }
        }
    }
    BackupImageCount ++;
    return DstPath;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20c8, %rsp           # imm = 0x20C8
leaq 0x97be(%rip), %rax      # 0x12a90
cmpb $0x0, (%rax)
je 0x933c
movl %edx, %ebp
movl %esi, %r14d
movq %rdi, %rbx
leaq 0x30(%rsp), %rsi
callq 0x32c0
cmpl $-0x1, %eax
je 0x9587
leaq 0x5149(%rip), %r8       # 0xe442
movq 0x88(%rsp), %r12
movq %rbx, %rax
movzbl (%rax), %ecx
cmpl $0x2e, %ecx
je 0x9312
testl %ecx, %ecx
jne 0x9315
jmp 0x931a
movq %rax, %r8
incq %rax
jmp 0x9304
cmpq %r12, 0xb777(%rip)      # 0x14a98
jne 0x9344
movb 0x8fac(%rip), %al       # 0x122d5
leal -0x61(%rax), %ecx
incb %al
cmpb $0x19, %cl
movzbl %al, %ecx
pushq $0x61
popq %rax
cmovbl %ecx, %eax
jmp 0x934d
xorl %r14d, %r14d
jmp 0x9408
movq %r12, 0xb74d(%rip)      # 0x14a98
movb $0x20, %al
movb %al, 0x8f82(%rip)       # 0x122d5
movsbl %al, %edx
leaq 0x4f60(%rip), %rsi      # 0xe2bd
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movl %r14d, %ecx
xorl %eax, %eax
callq 0x3490
leaq 0x8(%rsp), %rdi
movq %r12, (%rdi)
callq 0x3060
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
leaq 0xc0(%rsp), %r12
movaps %xmm0, (%r12)
movaps %xmm1, 0x10(%r12)
movaps %xmm2, 0x20(%r12)
movq 0x30(%rax), %rax
movq %rax, 0x30(%r12)
leaq 0xb4f0(%rip), %r14      # 0x148a0
leaq 0x4ffe(%rip), %rsi      # 0xe3b5
leaq 0x96d2(%rip), %rdx      # 0x12a90
movq %r14, %rdi
xorl %eax, %eax
callq 0x3490
movslq %eax, %r13
addq %r14, %r13
leaq 0x978b(%rip), %rdx      # 0x12b60
movl $0x1000, %esi           # imm = 0x1000
movq %r13, %rdi
movq %r12, %rcx
callq 0x3410
addq %rax, %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x30a0
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x8f67
testl %ebp, %ebp
je 0x941d
incl 0xb698(%rip)            # 0x14aa0
movq %r14, %rax
addq $0x20c8, %rsp           # imm = 0x20C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x980c(%rip), %r13      # 0x12c30
cmpb $0x0, (%r13)
je 0x9539
xorl %edx, %edx
leaq 0xc0(%rsp), %r15
leaq 0xb460(%rip), %r12      # 0x148a0
xorl %eax, %eax
cmpl $0x2000, %eax           # imm = 0x2000
jae 0x9563
movslq %eax, %rcx
movslq %edx, %rbp
movb (%r13,%rbp), %sil
cmpb $0x26, %sil
jne 0x949c
movzbl 0x1(%r13,%rbp), %esi
leaq (%rsp,%rcx), %rdi
addq $0xc0, %rdi
cmpl $0x69, %esi
je 0x94ad
cmpl $0x6f, %esi
jne 0x94ba
cmpb $0x2e, 0x2(%rbp,%r13)
jne 0x94d1
xorl %edx, %edx
xorl %eax, %eax
movzbl (%rdx,%r12), %esi
cmpl $0x2e, %esi
je 0x9495
testl %esi, %esi
jne 0x9497
jmp 0x94c6
movl %edx, %eax
incq %rdx
jmp 0x9485
movb %sil, 0xc0(%rsp,%rcx)
testb %sil, %sil
je 0x94f5
incl %eax
jmp 0x94ee
movl $0x1fff, %edx           # imm = 0x1FFF
subq %rcx, %rdx
movq %rbx, %rsi
jmp 0x94dc
incl %eax
movb $0x26, 0xc0(%rsp,%rcx)
jmp 0x94ee
testl %eax, %eax
je 0x94d1
cltq
movb $0x0, (%rax,%r12)
movl $0x1fff, %edx           # imm = 0x1FFF
subq %rcx, %rdx
movq %r12, %rsi
callq 0x3090
incq %rbp
movq %r15, %rdi
callq 0x3130
movl %ebp, %edx
incl %edx
jmp 0x9442
callq 0x3070
movq %rax, %r15
andl $0x0, (%rax)
leaq 0xc0(%rsp), %rdi
callq 0x3150
movl %eax, %ebx
movl (%r15), %eax
testl %ebx, %ebx
je 0x954d
testl %eax, %eax
jne 0x9555
leaq 0x9aa7(%rip), %rax      # 0x12fc8
movq (%rax), %rdi
leaq 0x4ef8(%rip), %rsi      # 0xe423
movl %ebx, %edx
xorl %eax, %eax
callq 0x32a0
jmp 0x9402
leaq 0xb360(%rip), %rsi      # 0x148a0
movq %rbx, %rdi
callq 0x9593
jmp 0x9402
testl %eax, %eax
je 0x9402
leaq 0x1c06(%rip), %rdi      # 0xb162
callq 0x3450
jmp 0x951a
movq 0x8a8e(%rip), %rax      # 0x11ff8
movq (%rax), %rcx
leaq 0x4e98(%rip), %rdi      # 0xe40c
pushq $0x16
popq %rsi
pushq $0x1
popq %rdx
callq 0x34b0
pushq $-0x1
popq %rdi
callq 0x34a0
movq %rbx, %rdi
callq 0x3450
pushq $0x1
jmp 0x9581