// File: /workspace/github_c_makefile_star2_O0/lh3[P]minigraph/algo.c
// Function: mg_mss_all
mg_msseg_t *mg_mss_all(void *km, int32_t n, const MG_MSS_TYPE *S, MG_MSS_TYPE min_sc, MG_MSS_TYPE xdrop, int32_t *n_seg)
{
    int32_t i, j;
    MG_MSS_TYPE L, max;
    msseg_v ret = {0,0,0};
    msseg_aux_v seg = {0,0,0};
    msseg_aux_t t;

	kv_resize(mg_msseg_t, km, ret, 16);
	kv_resize(msseg_aux_t, km, seg, 16);
    for (i = 0, L = 0, max = MSS_NEG_INF; i < n;) {
        if (S[i] > 0) {
            int32_t k;
            MG_MSS_TYPE R = L + S[i];
            for (k = i + 1; k < n && S[k] > 0; ++k)
                R += S[k];
			if (R > max) max = R;
            t.st = i, t.en = k, t.L = L, t.R = R;
            while (1) {
                msseg_aux_t *p;
                for (j = seg.n - 1; j >= 0;) {
                    p = &seg.a[j];
                    if (p->L < t.L) break;
                    j = p->pre >= 0? p->pre : j - 1;
                }
                if (j >= 0 && seg.a[j].R < t.R) {
                    p = &seg.a[j];
                    t.st = p->st, t.L = p->L, t.pre = p->pre;
                    seg.n = j;
                } else {
                    if (j < 0) {
						move_segs(km, &ret, &seg, min_sc);
						max = R;
					}
                    t.pre = j;
                    kv_push(msseg_aux_t, km, seg, t);
                    break;
                }
            }
            L = R, i = k;
        } else {
			if (xdrop > 0 && L + S[i] + xdrop < max) { // reset
				move_segs(km, &ret, &seg, min_sc);
				L = 0, max = MSS_NEG_INF;
			}
			L += S[i++];
		}
    }
    move_segs(km, &ret, &seg, min_sc);
    kfree(km, seg.a);
	KREALLOC(km, ret.a, ret.n);
    *n_seg = ret.n;
    return ret.a;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movq %r9, -0x28(%rbp)
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x2190
leaq -0x68(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x2190
cmpq $0x10, -0x48(%rbp)
jae 0x35f1
movq $0x10, -0x48(%rbp)
movq -0x48(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
shrq %rax
orq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
shrq $0x2, %rax
orq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
shrq $0x4, %rax
orq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
shrq $0x8, %rax
orq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
shrq $0x10, %rax
orq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
imulq $0xc, -0x48(%rbp), %rdx
callq 0x2ae0
movq %rax, -0x40(%rbp)
jmp 0x35f3
jmp 0x35f5
cmpq $0x10, -0x60(%rbp)
jae 0x3685
movq $0x10, -0x60(%rbp)
movq -0x60(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
shrq %rax
orq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
shrq $0x2, %rax
orq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
shrq $0x4, %rax
orq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
shrq $0x8, %rax
orq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
shrq $0x10, %rax
orq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
imulq $0x14, -0x60(%rbp), %rdx
callq 0x2ae0
movq %rax, -0x58(%rbp)
jmp 0x3687
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x80000000, -0x38(%rbp) # imm = 0x80000000
movl -0x2c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x394b
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jle 0x38ed
movl -0x34(%rbp), %eax
movq -0x18(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
addl (%rcx,%rdx,4), %eax
movl %eax, -0x84(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
movl -0x80(%rbp), %ecx
xorl %eax, %eax
cmpl -0xc(%rbp), %ecx
movb %al, -0x91(%rbp)
jge 0x36fc
movq -0x18(%rbp), %rax
movslq -0x80(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
setg %al
movb %al, -0x91(%rbp)
movb -0x91(%rbp), %al
testb $0x1, %al
jne 0x3708
jmp 0x372a
movq -0x18(%rbp), %rax
movslq -0x80(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addl -0x84(%rbp), %eax
movl %eax, -0x84(%rbp)
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x36d7
movl -0x84(%rbp), %eax
cmpl -0x38(%rbp), %eax
jle 0x373e
movl -0x84(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x7c(%rbp)
movl -0x80(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x84(%rbp), %eax
movl %eax, -0x70(%rbp)
movq -0x68(%rbp), %rax
subq $0x1, %rax
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jl 0x37c7
movq -0x58(%rbp), %rax
movslq -0x30(%rbp), %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x74(%rbp), %eax
jge 0x3791
jmp 0x37c7
movq -0x90(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jl 0x37b0
movq -0x90(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x98(%rbp)
jmp 0x37bc
movl -0x30(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x98(%rbp)
movl -0x98(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x3764
cmpl $0x0, -0x30(%rbp)
jl 0x382d
movq -0x58(%rbp), %rax
movslq -0x30(%rbp), %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
cmpl -0x70(%rbp), %eax
jge 0x382d
movq -0x58(%rbp), %rax
movslq -0x30(%rbp), %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x7c(%rbp)
movq -0x90(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x74(%rbp)
movq -0x90(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x6c(%rbp)
movslq -0x30(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x38d7
cmpl $0x0, -0x30(%rbp)
jge 0x3850
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %ecx
leaq -0x50(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0x39a0
movl -0x84(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x6c(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x60(%rbp), %rax
jne 0x38a6
cmpq $0x0, -0x60(%rbp)
je 0x3877
movq -0x60(%rbp), %rax
shlq %rax
movq %rax, -0xa0(%rbp)
jmp 0x3885
movl $0x2, %eax
movq %rax, -0xa0(%rbp)
jmp 0x3885
movq -0xa0(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
imulq $0x14, -0x60(%rbp), %rdx
callq 0x2ae0
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq -0x68(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x68(%rbp)
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq -0x7c(%rbp), %rcx
movq %rcx, (%rax)
movq -0x74(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl -0x6c(%rbp), %ecx
movl %ecx, 0x10(%rax)
jmp 0x38dc
jmp 0x3759
movl -0x84(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x80(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x3946
cmpl $0x0, -0x20(%rbp)
jle 0x392b
movl -0x34(%rbp), %eax
movq -0x18(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
addl (%rcx,%rdx,4), %eax
addl -0x20(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x392b
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %ecx
leaq -0x50(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0x39a0
movl $0x0, -0x34(%rbp)
movl $0x80000000, -0x38(%rbp) # imm = 0x80000000
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x2c(%rbp)
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x369c
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %ecx
leaq -0x50(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0x39a0
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x2670
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
imulq $0xc, -0x50(%rbp), %rdx
callq 0x2ae0
movq %rax, -0x40(%rbp)
movq -0x50(%rbp), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x40(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax,%rax)