// File: chhylp123[P]hifiasm/hic.cpp
// Function: get_max_hap_g(bub_sort_vec*, unsigned int*)
uint32_t get_max_hap_g(bub_sort_vec* w_stack, uint32_t* require_iso)
{
    uint32_t k, max_idx = (uint32_t)-1;
    double max_w;
    for (k = require_iso? (*require_iso)+1 : 0, max_idx = (uint32_t)-1; k < w_stack->n; k++)
    {
        if(w_stack->a[k].used) continue;
        if(!require_iso)
        {
            if(w_stack->a[k].p_id == (uint32_t)-1) continue;
            if((max_idx == (uint32_t)-1) || (max_idx != (uint32_t)-1 && max_w < w_stack->a[k].weight))
            {
                max_w = w_stack->a[k].weight;
                max_idx = k;
            }
        }
        else
        {
            if(w_stack->a[k].p_id != (uint32_t)-1) continue;
            return k;
        }
    }

    if(require_iso && (*require_iso) != 0)
    {
        for (k = 0; k < w_stack->n; k++)
        {
            if(w_stack->a[k].used) continue;
            if(w_stack->a[k].p_id != (uint32_t)-1) continue;
            return k;
        }
    }

    return max_idx;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0xffffffff, -0x20(%rbp) # imm = 0xFFFFFFFF
cmpq $0x0, -0x18(%rbp)
je 0x1f4a88
movq -0x18(%rbp), %rax
movl (%rax), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1f4a8f
xorl %eax, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1f4a8f
movl -0x2c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl $0xffffffff, -0x20(%rbp) # imm = 0xFFFFFFFF
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x1f4b75
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpb $0x0, 0x20(%rax)
je 0x1f4ac9
jmp 0x1f4b67
cmpq $0x0, -0x18(%rbp)
jne 0x1f4b3c
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, 0x8(%rax)
jne 0x1f4aee
jmp 0x1f4b67
cmpl $-0x1, -0x20(%rbp)
je 0x1f4b1a
cmpl $-0x1, -0x20(%rbp)
je 0x1f4b3a
movsd -0x28(%rbp), %xmm1
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1f4b3a
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x28(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0x1f4b65
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, 0x8(%rax)
je 0x1f4b5a
jmp 0x1f4b67
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1f4beb
jmp 0x1f4b67
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1f4a9c
cmpq $0x0, -0x18(%rbp)
je 0x1f4be5
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x1f4be5
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x1f4be3
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpb $0x0, 0x20(%rax)
je 0x1f4bb2
jmp 0x1f4bd8
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, 0x8(%rax)
je 0x1f4bd0
jmp 0x1f4bd8
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1f4beb
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1f4b8c
jmp 0x1f4be5
movl -0x20(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq