// File: /workspace/github_c_makefile_star2_O2/ryvnf[P]czc/main.c
// Function: invoke_gcc
void invoke_gcc(struct arg_list *src_files, struct arg_list *gcc_args,
        struct arg_list **gcc_args_tailp)
{
    // The beginning of the temporary file arguments passed to GCC (used to
    // remove them after compilation).
    struct arg_list **tmp_files = gcc_args_tailp;

    char tmp_dir[] = "/tmp/czc.XXXXXX";
    if (mkdtemp(tmp_dir) == NULL)
        perror("mkdtemp");

    for (struct arg_list *i = src_files; i != NULL; i = i->next) {
        // TODO: This does will not work if compiling dir0/a.zc and dir1/a.zc in
        //       the same command.  A better solution should be implemented in
        //       the future.
        char *arg = basename(strdup(i->arg));
        char *arg_ext = get_file_ext(arg);
        if (arg_ext != NULL)
            arg_ext[-1] = '\0';

        size_t n = strlen(tmp_dir) + 1 + strlen(arg) + 2;
        char c_file_name[n + 1];
        snprintf(c_file_name, sizeof c_file_name, "%s/%s.c", tmp_dir, arg);

        FILE *fp;
        if ((fp = fopen(c_file_name, "w")) == NULL)
            perror(c_file_name);

        gen_input_file(i->arg, fp);

        *gcc_args_tailp = arg_list_new(c_file_name);
        gcc_args_tailp = &(*gcc_args_tailp)->next;

        fclose(fp);
    }

    // Count number of arguments.
    size_t gcc_argc = 0;
    for (struct arg_list *i = gcc_args; i != NULL; i = i->next)
        gcc_argc++;

    char **gcc_argv = malloc((gcc_argc + 1) * sizeof *gcc_argv);

    // Initialize the arguments.
    struct arg_list *i = gcc_args;
    for (size_t j = 0; j < gcc_argc; ++j) {
        gcc_argv[j] = i->arg;
        i = i->next;
    }
    gcc_argv[gcc_argc] = NULL;

    // Execute GCC.
    pid_t pid = fork();
    if (pid < 0) {
        perror("fork");
        exit(1);
    } else if (pid == 0) {
        if (execvp("gcc", gcc_argv) < 0) {
            perror("execvp");
            exit(1);
        }
    }

    waitpid(pid, NULL, 0);

    // Remove the created temporary files.
    for (struct arg_list *i = *tmp_files; i != NULL; i = i->next)
        unlink(i->arg);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %rbx
movq %rsi, -0x30(%rbp)
movq %rdi, %r15
movaps 0x4419(%rip), %xmm0     # 0xc640
leaq -0x50(%rbp), %rdi
movaps %xmm0, (%rdi)
callq 0x21a0
testq %rax, %rax
je 0x83ab
movq %rbx, %r12
testq %r15, %r15
je 0x8315
movq %r12, -0x40(%rbp)
movq (%r15), %rdi
callq 0x2220
movq %rax, %rdi
callq 0x2140
movq %rax, %r13
movq %rax, %rdi
callq 0x8094
testq %rax, %rax
je 0x8270
movb $0x0, -0x1(%rax)
leaq -0x50(%rbp), %r14
movq %r14, %rdi
callq 0x20a0
movq %rax, %r12
movq %r13, %rdi
callq 0x20a0
movq %rsp, -0x38(%rbp)
leaq (%r12,%rax), %rsi
addq $0x4, %rsi
addq %r12, %rax
addq $0x13, %rax
andq $-0x10, %rax
movq %rsp, %r12
subq %rax, %r12
movq %r12, %rsp
movq %r12, %rdi
leaq 0x42e1(%rip), %rdx      # 0xc592
movq %r14, %rcx
movq %r13, %r8
xorl %eax, %eax
callq 0x20c0
movq %r12, %rdi
leaq 0x42fa(%rip), %rsi      # 0xc5c2
callq 0x21c0
movq %rax, %r13
testq %rax, %rax
je 0x830b
movq (%r15), %rdi
movq %r13, %rsi
callq 0x80fb
movq %r12, %rdi
callq 0x80ce
movq %rax, %r12
movq -0x40(%rbp), %rax
movq %r12, (%rax)
addq $0x8, %r12
movq %r13, %rdi
callq 0x2090
movq -0x38(%rbp), %rsp
movq 0x8(%r15), %r15
jmp 0x823f
movq %r12, %rdi
callq 0x21d0
jmp 0x82d5
pushq $0x8
popq %rdi
xorl %r14d, %r14d
movq -0x30(%rbp), %rax
testq %rax, %rax
je 0x8331
incq %r14
movq 0x8(%rax), %rax
addq $0x8, %rdi
jmp 0x831f
callq 0x2160
movq %rax, %r15
xorl %eax, %eax
movq -0x30(%rbp), %rdx
cmpq %rax, %r14
je 0x8354
movq (%rdx), %rcx
movq %rcx, (%r15,%rax,8)
movq 0x8(%rdx), %rdx
incq %rax
jmp 0x833f
andq $0x0, (%r15,%r14,8)
callq 0x2250
testl %eax, %eax
js 0x83bc
movl %eax, %r14d
jne 0x837a
leaq 0x4231(%rip), %rdi      # 0xc59f
movq %r15, %rsi
callq 0x21f0
testl %eax, %eax
js 0x83c5
movl %r14d, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x21b0
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x839c
movq (%rbx), %rdi
callq 0x2060
addq $0x8, %rbx
jmp 0x8386
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x41d8(%rip), %rdi      # 0xc58a
callq 0x21d0
jmp 0x823c
leaq 0x41d7(%rip), %rdi      # 0xc59a
jmp 0x83cc
leaq 0x41d7(%rip), %rdi      # 0xc5a3
callq 0x21d0
pushq $0x1
popq %rdi
callq 0x2200