// File: /workspace/github_c_makefile_star2_O0/avik-das[P]seam-carver/seam-carver.c
// Function: compute_vertical_seam_links
struct seam_link * compute_vertical_seam_links(
        const unsigned int *energy,
        int w,
        int h) {
    struct seam_link *links = malloc(w * h * sizeof(struct seam_link));
    if (!links) {
        fprintf(stderr, "Unable to allocate memory (%d)\n", __LINE__);
        return NULL;
    }

    for (int x = 0; x < w; x++) {
        links[x] = (struct seam_link) {
            .energy = energy[x],
            .parent_coordinate = -1
        };
    }

    for (int y = 1; y < h; y++)
    for (int x = 0; x < w; x++) {
        int i = y * w + x;

        int min_parent_energy = INT_MAX;
        int min_parent_x = -1;

        int parent_x = x == 0 ? x : x - 1;
        int parent_x_end = x == w - 1 ? x : x + 1;
        for (; parent_x <= parent_x_end; parent_x++) {
            int candidate_energy = links[(y - 1) * w + parent_x].energy;
            if (candidate_energy < min_parent_energy) {
                min_parent_energy = candidate_energy;
                min_parent_x = parent_x;
            }
        }

        links[i] = (struct seam_link) {
            .energy = energy[i] + min_parent_energy,
            .parent_coordinate = min_parent_x
        };
    }

    return links;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl -0x14(%rbp), %eax
imull -0x18(%rbp), %eax
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x1150
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x60fa
movq 0x20f21(%rip), %rax     # 0x26ff8
movq (%rax), %rdi
leaq 0x1bc3b(%rip), %rsi     # 0x21d1c
movl $0x4a, %edx
movb $0x0, %al
callq 0x1100
movq $0x0, -0x8(%rbp)
jmp 0x624b
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x6139
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq -0x10(%rbp), %rdx
movslq -0x24(%rbp), %rsi
movl (%rdx,%rsi,4), %edx
movl %edx, -0x2c(%rbp)
movl $0xffffffff, -0x28(%rbp) # imm = 0xFFFFFFFF
movq -0x2c(%rbp), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x6101
movl $0x1, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x6243
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x6233
movl -0x30(%rbp), %eax
imull -0x14(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x38(%rbp)
movl $0x7fffffff, -0x3c(%rbp) # imm = 0x7FFFFFFF
movl $0xffffffff, -0x40(%rbp) # imm = 0xFFFFFFFF
cmpl $0x0, -0x34(%rbp)
jne 0x6188
movl -0x34(%rbp), %eax
movl %eax, -0x58(%rbp)
jmp 0x6191
movl -0x34(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x34(%rbp), %eax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x61ac
movl -0x34(%rbp), %eax
movl %eax, -0x5c(%rbp)
jmp 0x61b5
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x48(%rbp), %eax
jg 0x61fe
movq -0x20(%rbp), %rax
movl -0x30(%rbp), %ecx
subl $0x1, %ecx
imull -0x14(%rbp), %ecx
addl -0x44(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,8), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x61f1
movl -0x4c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x61f3
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x61bb
movq -0x20(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rdx
movslq -0x38(%rbp), %rsi
movl (%rdx,%rsi,4), %edx
addl -0x3c(%rbp), %edx
movl %edx, -0x54(%rbp)
movl -0x40(%rbp), %edx
movl %edx, -0x50(%rbp)
movq -0x54(%rbp), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x6153
jmp 0x6235
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x6140
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)