// File: /workspace/github_c_makefile_star2_O0/avik-das[P]seam-carver/seam-carver.c
// Function: run_iteration
unsigned char * run_iteration(
        const char *output_directory,
        const unsigned char *data,
        int w,
        int h,
        int iteration) {

    unsigned int *energy = NULL;
    struct seam_link *vertical_seam_links = NULL;
    int *minimal_vertical_seam = NULL;
    unsigned char *output_data = NULL;

    char output_filename[1024];

    energy = compute_energy(data, w, h);
    if (!energy) { goto cleanup; }

    if (iteration == 0) {
        snprintf(output_filename, 1024, "%s/img-energy.jpg", output_directory);
        if (write_energy(energy, w, h, output_filename)) {
            goto cleanup;
        }
    }

    vertical_seam_links = compute_vertical_seam_links(energy, w, h);
    if (!vertical_seam_links) { goto cleanup; }

    minimal_vertical_seam = get_minimal_seam(vertical_seam_links, w, h);

    snprintf(
            output_filename,
            1024,
            "%s/img-seam-%04d.jpg",
            output_directory,
            iteration);
    if (draw_vertical_seam(
                data,
                minimal_vertical_seam,
                w,
                h,
                output_filename)) {
        goto cleanup;
    }

    output_data =
        image_after_vertical_seam_removal(data, minimal_vertical_seam, w, h);

cleanup:
    if (energy) { free(energy); }
    if (vertical_seam_links) { free(vertical_seam_links); }
    if (minimal_vertical_seam) { free(minimal_vertical_seam); }

    return output_data;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x440, %rsp            # imm = 0x440
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
callq 0x5fd0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x691c
jmp 0x69eb
cmpl $0x0, -0x1c(%rbp)
jne 0x6962
leaq -0x440(%rbp), %rdi
movq -0x8(%rbp), %rcx
movl $0x400, %esi            # imm = 0x400
leaq 0x1b490(%rip), %rdx     # 0x21dc9
movb $0x0, %al
callq 0x10a0
movq -0x28(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
leaq -0x440(%rbp), %rcx
callq 0x64f0
cmpl $0x0, %eax
je 0x6960
jmp 0x69eb
jmp 0x6962
movq -0x28(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
callq 0x60a0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x697e
jmp 0x69eb
movq -0x30(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
callq 0x6260
movq %rax, -0x38(%rbp)
leaq -0x440(%rbp), %rdi
movq -0x8(%rbp), %rcx
movl -0x1c(%rbp), %r8d
movl $0x400, %esi            # imm = 0x400
leaq 0x1b42f(%rip), %rdx     # 0x21ddb
movb $0x0, %al
callq 0x10a0
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
leaq -0x440(%rbp), %r8
callq 0x66c0
cmpl $0x0, %eax
je 0x69d4
jmp 0x69eb
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
callq 0x6380
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x69fb
movq -0x28(%rbp), %rdi
callq 0x1030
cmpq $0x0, -0x30(%rbp)
je 0x6a0b
movq -0x30(%rbp), %rdi
callq 0x1030
cmpq $0x0, -0x38(%rbp)
je 0x6a1b
movq -0x38(%rbp), %rdi
callq 0x1030
movq -0x40(%rbp), %rax
addq $0x440, %rsp            # imm = 0x440
popq %rbp
retq
nopl (%rax,%rax)