// File: /workspace/github_c_makefile_star2_O1/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 0x8df2(%rip), %rax      # 0x12a80
cmpb $0x0, (%rax)
je 0x9cfe
movl %edx, %ebp
movl %esi, %r14d
movq %rdi, %rbx
leaq 0x30(%rsp), %rsi
callq 0x32b0
cmpl $-0x1, %eax
je 0x9f28
leaq 0x474d(%rip), %r8       # 0xe402
movq 0x88(%rsp), %r12
movq %rbx, %rax
jmp 0x9cc8
movq %rax, %r8
incq %rax
movzbl (%rax), %ecx
cmpl $0x2e, %ecx
je 0x9cc2
testl %ecx, %ecx
jne 0x9cc5
cmpq %r12, 0xadad(%rip)      # 0x14a88
jne 0x9d06
movb 0x85e2(%rip), %al       # 0x122c5
leal -0x61(%rax), %ecx
incb %al
cmpb $0x19, %cl
movzbl %al, %eax
movl $0x61, %ecx
cmovbl %eax, %ecx
movb %cl, 0x85c9(%rip)       # 0x122c5
jmp 0x9d14
xorl %r14d, %r14d
jmp 0x9f05
movb $0x20, 0x85b8(%rip)     # 0x122c5
movq %r12, 0xad74(%rip)      # 0x14a88
movsbl 0x85aa(%rip), %edx      # 0x122c5
leaq 0x455b(%rip), %rsi      # 0xe27d
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movl %r14d, %ecx
xorl %eax, %eax
callq 0x3470
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 0xab1b(%rip), %r14      # 0x14890
leaq 0x45f9(%rip), %rsi      # 0xe375
leaq 0x8cfd(%rip), %rdx      # 0x12a80
movq %r14, %rdi
xorl %eax, %eax
callq 0x3470
movslq %eax, %r13
addq %r14, %r13
leaq 0x8db6(%rip), %rdx      # 0x12b50
movl $0x1000, %esi           # imm = 0x1000
movq %r13, %rdi
movq %r12, %rcx
callq 0x33f0
addq %rax, %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x30a0
movq %r14, %rdi
movl $0x1, %esi
callq 0x98f1
testl %ebp, %ebp
jne 0x9eff
leaq 0x8e4c(%rip), %r13      # 0x12c20
cmpb $0x0, (%r13)
je 0x9ef0
xorl %ecx, %ecx
leaq 0xc0(%rsp), %r15
leaq 0xaaa0(%rip), %r12      # 0x14890
xorl %eax, %eax
xorl %edx, %edx
movslq %edx, %rbp
movb (%r13,%rbp), %sil
cmpb $0x26, %sil
jne 0x9e35
movzbl 0x1(%r13,%rbp), %edi
cmpl $0x69, %edi
je 0x9e46
cmpl $0x6f, %edi
jne 0x9e35
cmpb $0x2e, 0x2(%rbp,%r13)
jne 0x9e69
xorl %edx, %edx
xorl %eax, %eax
movzbl (%rdx,%r12), %esi
cmpl $0x2e, %esi
je 0x9e2e
testl %esi, %esi
jne 0x9e30
jmp 0x9e5e
movl %edx, %eax
incq %rdx
jmp 0x9e1e
movb %sil, 0xc0(%rsp,%rcx)
testb %sil, %sil
je 0x9ea7
incl %eax
jmp 0x9e91
leaq (%rsp,%rcx), %rdi
addq $0xc0, %rdi
movl $0x1fff, %edx           # imm = 0x1FFF
subq %rcx, %rdx
movq %rbx, %rsi
jmp 0x9e7f
testl %eax, %eax
je 0x9e69
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
movslq %eax, %rcx
cmpl $0x1fff, %ecx           # imm = 0x1FFF
jbe 0x9df4
callq 0x3878
callq 0x3070
movq %rax, %r15
movl $0x0, (%rax)
leaq 0xc0(%rsp), %rdi
callq 0x3150
movl %eax, %ebx
testl %eax, %eax
jne 0x9ece
cmpl $0x0, (%r15)
je 0x9eff
cmpl $0x0, (%r15)
jne 0x9f1a
leaq 0x90dd(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
leaq 0x44fe(%rip), %rsi      # 0xe3e3
movl %ebx, %edx
xorl %eax, %eax
callq 0x3290
jmp 0x9eff
leaq 0xa999(%rip), %rsi      # 0x14890
movq %rbx, %rdi
callq 0x9f30
incl 0xab8b(%rip)            # 0x14a90
movq %r14, %rax
addq $0x20c8, %rsp           # imm = 0x20C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1231(%rip), %rdi      # 0xb152
callq 0x3430
jmp 0x9ed4
movq %rbx, %rdi
callq 0x389d