// File: /workspace/github_c_makefile_star2_O3/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 0x8e01(%rip), %rax      # 0x12a80
cmpb $0x0, (%rax)
je 0x9ceb
movl %edx, %ebp
movl %esi, %r14d
movq %rdi, %rbx
leaq 0x30(%rsp), %rsi
callq 0x32c0
cmpl $-0x1, %eax
je 0x9f23
leaq 0x47cc(%rip), %r8       # 0xe472
movq 0x88(%rsp), %r12
movq %rbx, %rax
movzbl (%rax), %ecx
cmpl $0x2e, %ecx
je 0x9cbf
testl %ecx, %ecx
jne 0x9cc2
jmp 0x9cc7
movq %rax, %r8
incq %rax
jmp 0x9cb1
cmpq %r12, 0xadba(%rip)      # 0x14a88
jne 0x9cf3
movb 0x85f7(%rip), %al       # 0x122cd
leal -0x61(%rax), %ecx
incb %al
cmpb $0x19, %cl
movzbl %al, %ecx
movl $0x61, %eax
cmovbl %ecx, %eax
jmp 0x9cfc
xorl %r14d, %r14d
jmp 0x9db9
movq %r12, 0xad8e(%rip)      # 0x14a88
movb $0x20, %al
movb %al, 0x85cb(%rip)       # 0x122cd
movsbl %al, %edx
leaq 0x45e1(%rip), %rsi      # 0xe2ed
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movl %r14d, %ecx
xorl %eax, %eax
callq 0x3480
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 0xab31(%rip), %r14      # 0x14890
leaq 0x467f(%rip), %rsi      # 0xe3e5
leaq 0x8d13(%rip), %rdx      # 0x12a80
movq %r14, %rdi
xorl %eax, %eax
callq 0x3480
movslq %eax, %r13
addq %r14, %r13
leaq 0x8dcc(%rip), %rdx      # 0x12b50
movl $0x1000, %esi           # imm = 0x1000
movq %r13, %rdi
movq %r12, %rcx
callq 0x3400
addq %rax, %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x30a0
movq %r14, %rdi
movl $0x1, %esi
callq 0x98e5
testl %ebp, %ebp
je 0x9dce
incl 0xacd7(%rip)            # 0x14a90
movq %r14, %rax
addq $0x20c8, %rsp           # imm = 0x20C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8e4b(%rip), %r13      # 0x12c20
cmpb $0x0, (%r13)
je 0x9ef9
xorl %ecx, %ecx
leaq 0xc0(%rsp), %r15
leaq 0xaa9f(%rip), %r12      # 0x14890
xorl %eax, %eax
xorl %edx, %edx
movslq %edx, %rbp
movb (%r13,%rbp), %sil
cmpb $0x26, %sil
jne 0x9e36
movzbl 0x1(%r13,%rbp), %esi
cmpl $0x69, %esi
je 0x9e47
cmpl $0x6f, %esi
jne 0x9e5f
cmpb $0x2e, 0x2(%rbp,%r13)
jne 0x9e76
xorl %edx, %edx
xorl %eax, %eax
movzbl (%rdx,%r12), %esi
cmpl $0x2e, %esi
je 0x9e2f
testl %esi, %esi
jne 0x9e31
jmp 0x9e6b
movl %edx, %eax
incq %rdx
jmp 0x9e1f
movb %sil, 0xc0(%rsp,%rcx)
testb %sil, %sil
je 0x9eb2
incl %eax
jmp 0x9e9e
leaq (%rsp,%rcx), %rdi
addq $0xc0, %rdi
movl $0x1fff, %edx           # imm = 0x1FFF
subq %rcx, %rdx
movq %rbx, %rsi
jmp 0x9e8c
incl %eax
movb $0x26, 0xc0(%rsp,%rcx)
jmp 0x9e9e
testl %eax, %eax
je 0x9e76
cltq
movb $0x0, (%rax,%r12)
leaq (%rsp,%rcx), %rdi
addq $0xc0, %rdi
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
movl %eax, %ecx
cmpl $0x1fff, %eax           # imm = 0x1FFF
jbe 0x9df5
callq 0x3888
callq 0x3070
movq %rax, %r15
movl $0x0, (%rax)
leaq 0xc0(%rsp), %rdi
callq 0x3150
movl %eax, %ebx
movl (%r15), %eax
testl %ebx, %ebx
je 0x9f0d
testl %eax, %eax
jne 0x9f15
leaq 0x90d7(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
leaq 0x4568(%rip), %rsi      # 0xe453
movl %ebx, %edx
xorl %eax, %eax
callq 0x32a0
jmp 0x9db3
leaq 0xa990(%rip), %rsi      # 0x14890
movq %rbx, %rdi
callq 0x9f2b
jmp 0x9db3
testl %eax, %eax
je 0x9db3
leaq 0x1246(%rip), %rdi      # 0xb162
callq 0x3440
jmp 0x9eda
movq %rbx, %rdi
callq 0x38ad