// File: /workspace/github_c_makefile_star2_O0/Matthias-Wandel[P]imgcomp/src/util.c
// Function: CopyJpgFileCmd
static void CopyJpgFileCmd(char * src, char * dest)
{
    // Build the exec string.  &i and &o in the exec string get replaced by input and output files.
    char ExecString[PATH_MAX*2];
    int e = 0;
    for (int a=0;;a++){
        if (e >= sizeof(ExecString)){
            fprintf(stderr, "Copy command too long\n");
            exit(-1);
        }

        if (CopyJpgCmd[a] == '&' && (CopyJpgCmd[a+1] == 'i' || CopyJpgCmd[a+1] == 'o')){
            if (CopyJpgCmd[a+1] == 'o'){
                if (CopyJpgCmd[a+2] == '.'){
                    // If it's specified "&o.", that means cut off the old extension.
                    // That way, we can specify a copyjpgcmd in imgcomp.conf to convert
                    // to a different image format.  Example using imagemagick convert:
                    //   copyjpgcmd = convert -quality 60 "&i" "&o.webp"
                    int extension = 0;
                    for (int b=0;dest[b];b++){
                        if (dest[b] == '.') extension = b;
                    }
                    if (extension) dest[extension] = '\0';
                }
                strncpy(ExecString+e, dest, sizeof(ExecString)-e-1);
            }else{
                strncpy(ExecString+e, src, sizeof(ExecString)-e-1);
            }

            a += 1;
            e = strlen(ExecString);
            continue;
        }
        ExecString[e++] = CopyJpgCmd[a];
        if (CopyJpgCmd[a] == 0) break;
    }

    //printf("Cmd:%s\n",ExecString);

    errno = 0;
    int err = system(ExecString);

    if (err || errno){
        if (errno) perror("system");
        fprintf(Log, "jpeg copy command failed (%d)\n",err);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2030, %rsp           # imm = 0x2030
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x2014(%rbp)
movl $0x0, -0x2018(%rbp)
movslq -0x2014(%rbp), %rax
cmpq $0x2000, %rax           # imm = 0x2000
jb 0xc2e8
movq 0x7d23(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x51a5(%rip), %rsi      # 0x1147c
movb $0x0, %al
callq 0x3290
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3480
movslq -0x2018(%rbp), %rcx
leaq 0x898a(%rip), %rax      # 0x14c80
movsbl (%rax,%rcx), %eax
cmpl $0x26, %eax
jne 0xc46c
movl -0x2018(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x896a(%rip), %rax      # 0x14c80
movsbl (%rax,%rcx), %eax
cmpl $0x69, %eax
je 0xc33f
movl -0x2018(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x894e(%rip), %rax      # 0x14c80
movsbl (%rax,%rcx), %eax
cmpl $0x6f, %eax
jne 0xc46c
movl -0x2018(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x892e(%rip), %rax      # 0x14c80
movsbl (%rax,%rcx), %eax
cmpl $0x6f, %eax
jne 0xc41c
movl -0x2018(%rbp), %eax
addl $0x2, %eax
movslq %eax, %rcx
leaq 0x890e(%rip), %rax      # 0x14c80
movsbl (%rax,%rcx), %eax
cmpl $0x2e, %eax
jne 0xc3ed
movl $0x0, -0x201c(%rbp)
movl $0x0, -0x2020(%rbp)
movq -0x10(%rbp), %rax
movslq -0x2020(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0xc3d3
movq -0x10(%rbp), %rax
movslq -0x2020(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2e, %eax
jne 0xc3c0
movl -0x2020(%rbp), %eax
movl %eax, -0x201c(%rbp)
jmp 0xc3c2
movl -0x2020(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2020(%rbp)
jmp 0xc38f
cmpl $0x0, -0x201c(%rbp)
je 0xc3eb
movq -0x10(%rbp), %rax
movslq -0x201c(%rbp), %rcx
movb $0x0, (%rax,%rcx)
jmp 0xc3ed
leaq -0x2010(%rbp), %rdi
movslq -0x2014(%rbp), %rax
addq %rax, %rdi
movq -0x10(%rbp), %rsi
movslq -0x2014(%rbp), %rax
movl $0x2000, %edx           # imm = 0x2000
subq %rax, %rdx
subq $0x1, %rdx
callq 0x3090
jmp 0xc449
leaq -0x2010(%rbp), %rdi
movslq -0x2014(%rbp), %rax
addq %rax, %rdi
movq -0x8(%rbp), %rsi
movslq -0x2014(%rbp), %rax
movl $0x2000, %edx           # imm = 0x2000
subq %rax, %rdx
subq $0x1, %rdx
callq 0x3090
movl -0x2018(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2018(%rbp)
leaq -0x2010(%rbp), %rdi
callq 0x3130
movl %eax, -0x2014(%rbp)
jmp 0xc4b2
movslq -0x2018(%rbp), %rcx
leaq 0x8806(%rip), %rax      # 0x14c80
movb (%rax,%rcx), %cl
movl -0x2014(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x2014(%rbp)
cltq
movb %cl, -0x2010(%rbp,%rax)
movslq -0x2018(%rbp), %rcx
leaq 0x87db(%rip), %rax      # 0x14c80
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0xc4b0
jmp 0xc4c6
jmp 0xc4b2
movl -0x2018(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2018(%rbp)
jmp 0xc2b7
callq 0x3070
movl $0x0, (%rax)
leaq -0x2010(%rbp), %rdi
callq 0x3150
movl %eax, -0x2024(%rbp)
cmpl $0x0, -0x2024(%rbp)
jne 0xc4f6
callq 0x3070
cmpl $0x0, (%rax)
je 0xc52a
callq 0x3070
cmpl $0x0, (%rax)
je 0xc50c
leaq 0x1c33(%rip), %rdi      # 0xe13a
callq 0x3430
leaq 0x8b05(%rip), %rax      # 0x15018
movq (%rax), %rdi
movl -0x2024(%rbp), %edx
leaq 0x4f70(%rip), %rsi      # 0x11493
movb $0x0, %al
callq 0x3290
addq $0x2030, %rsp           # imm = 0x2030
popq %rbp
retq
nopw %cs:(%rax,%rax)