// File: /workspace/github_cpp_makefile_star2_O3/ruippeixotog[P]algo-lib/kuhn-munkres.cpp
// Function: kuhnMunkres(int)
int kuhnMunkres(int n) {
  for(int i = 0; i < n; i++) {
    mx[i] = my[i] = -1;
    lx[i] = ly[i] = 0;
  }
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++)
      ly[j] = max(ly[j], w[i][j]);
  }
  for(int i = 0; i < n; i++) {
    memset(s, 0, sizeof(s));
    memset(rem, 0x3f, sizeof(rem));

    int st;
    for(st = 0; st < n; st++) {
      if(mx[st] == -1) { kuhnAdd(st, n); break; }
    }
    while(mx[st] == -1) {
      int miny = -1;
      for(int y = 0; y < n; y++) {
        if(rem[y] != -INF && (miny == -1 || rem[miny] >= rem[y]))
          miny = y;
      }

      if(rem[miny]) {
        for(int x = 0; x < n; x++) if(s[x]) lx[x] -= rem[miny];
        for(int y = 0, d = rem[miny]; y < n; y++) {
          if(rem[y] == -INF) ly[y] += d;
          else rem[y] -= d;
        }
      }

      if(my[miny] == -1) {
        int cur = miny;
        while(remx[cur] != st) {
          int pmate = mx[remx[cur]];
          my[cur] = remx[cur]; mx[my[cur]] = cur;
          my[pmate] = -1; cur = pmate;
        }
        my[cur] = remx[cur]; mx[my[cur]] = cur;
      } else {
        kuhnAdd(my[miny], n); rem[miny] = -INF;
      }
    }
  }

  int ret = 0;
  for(int i = 0; i < n; i++)
    ret += w[i][mx[i]];
  return ret;
}

// Assembly:
testl %edi, %edi
jle 0x1475
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edi, %ebp
movl %edi, %r15d
leaq (,%r15,4), %r14
leaq 0x3d75d5(%rip), %rdi    # 0x3d87c0
movl $0xff, %esi
movq %r14, %rdx
callq 0x1030
leaq 0x3d6621(%rip), %rdi    # 0x3d7820
movl $0xff, %esi
movq %r14, %rdx
callq 0x1030
leaq 0x3d94ed(%rip), %r13    # 0x3da700
xorl %ebx, %ebx
movq %r13, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x1030
leaq 0x3d8537(%rip), %rdi    # 0x3d9760
xorl %esi, %esi
movq %r14, %rdx
callq 0x1030
movq %r15, %r8
leaq 0x2e03(%rip), %rax      # 0x4040
xorl %ecx, %ecx
movl (%rcx,%r13), %edx
movl (%rax,%rcx), %esi
cmpl %esi, %edx
cmovgl %edx, %esi
movl %esi, (%rcx,%r13)
addq $0x4, %rcx
cmpq %rcx, %r14
jne 0x123f
incq %rbx
addq $0xfa0, %rax            # imm = 0xFA0
cmpq %r8, %rbx
jne 0x123d
testl %ebp, %ebp
jle 0x1464
xorl %eax, %eax
leaq 0x3d36c9(%rip), %rbx    # 0x3d4940
leaq 0x3d4662(%rip), %r15    # 0x3d58e0
movl %ebp, 0x4(%rsp)
movq %r8, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movl $0xfa0, %edx            # imm = 0xFA0
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1030
movl $0xfa0, %edx            # imm = 0xFA0
movq %r15, %rdi
movl $0x3f, %esi
callq 0x1030
movq 0x8(%rsp), %r8
leaq 0x3d6567(%rip), %r10    # 0x3d7820
movq %r10, %rax
xorl %ebp, %ebp
cmpl $-0x1, (%rax)
je 0x12d4
incq %rbp
addq $0x4, %rax
cmpq %rbp, %r8
jne 0x12be
movl %r8d, %ebp
jmp 0x12eb
movl %ebp, %edi
movl 0x4(%rsp), %esi
callq 0x113c
leaq 0x3d653a(%rip), %r10    # 0x3d7820
movq 0x8(%rsp), %r8
leaq 0x3d74ce(%rip), %r9     # 0x3d87c0
leaq 0x3d8467(%rip), %r11    # 0x3d9760
movl %ebp, %eax
movq %rax, 0x20(%rsp)
cmpl $-0x1, (%r10,%rax,4)
jne 0x1417
movslq %ebp, %rax
movq %rax, 0x18(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movl (%r15,%rcx,4), %edx
cmpl $0xc4653600, %edx       # imm = 0xC4653600
je 0x1336
cmpl $-0x1, %eax
je 0x1334
movslq %eax, %rsi
cmpl %edx, (%r15,%rsi,4)
jl 0x1336
movl %ecx, %eax
incq %rcx
cmpq %r8, %rcx
jne 0x131a
movslq %eax, %r12
movl (%r15,%r12,4), %ecx
testl %ecx, %ecx
je 0x1381
xorl %edx, %edx
cmpl $0x0, (%rdx,%rbx)
je 0x1355
subl %ecx, (%rdx,%r11)
addq $0x4, %rdx
cmpq %rdx, %r14
jne 0x134b
xorl %edx, %edx
movl (%rdx,%r15), %esi
cmpl $0xc4653600, %esi       # imm = 0xC4653600
jne 0x1372
addl %ecx, (%rdx,%r13)
jmp 0x1378
subl %ecx, %esi
movl %esi, (%rdx,%r15)
addq $0x4, %rdx
cmpq %rdx, %r14
jne 0x1360
movl (%r9,%r12,4), %edi
cmpl $-0x1, %edi
je 0x13c0
movl 0x4(%rsp), %esi
callq 0x113c
leaq 0x3d83c6(%rip), %r11    # 0x3d9760
leaq 0x3d647f(%rip), %r10    # 0x3d7820
leaq 0x3d7418(%rip), %r9     # 0x3d87c0
movq 0x8(%rsp), %r8
movl $0xc4653600, (%r15,%r12,4) # imm = 0xC4653600
movq 0x20(%rsp), %rax
movl (%r10,%rax,4), %edx
jmp 0x1404
leaq 0x3d54b9(%rip), %rsi    # 0x3d6880
movl (%rsi,%r12,4), %ecx
cmpl %ebp, %ecx
jne 0x13d3
movl %eax, %edx
jmp 0x13f7
movslq %ecx, %rcx
movl (%r10,%rcx,4), %edx
movl %ecx, (%r9,%r12,4)
movl %eax, (%r10,%rcx,4)
movslq %edx, %r12
movl $0xffffffff, (%r9,%r12,4) # imm = 0xFFFFFFFF
movl (%rsi,%r12,4), %ecx
movl %edx, %eax
cmpl %ebp, %ecx
jne 0x13d3
movl %ebp, (%r9,%r12,4)
movq 0x18(%rsp), %rax
movl %edx, (%r10,%rax,4)
movl $0x0, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $-0x1, %edx
je 0x131a
movq 0x10(%rsp), %rax
incl %eax
movl 0x4(%rsp), %ebp
cmpl %ebp, %eax
jne 0x1287
testl %ebp, %ebp
jle 0x1464
imulq $0xfa0, %r8, %rcx       # imm = 0xFA0
xorl %edx, %edx
leaq 0x3d63e2(%rip), %rsi    # 0x3d7820
leaq 0x2bfb(%rip), %rdi      # 0x4040
xorl %eax, %eax
movslq (%rsi), %r8
leaq (%rdx,%r8,4), %r8
addl (%rdi,%r8), %eax
addq $0x4, %rsi
addq $0xfa0, %rdx            # imm = 0xFA0
cmpq %rdx, %rcx
jne 0x1447
jmp 0x1466
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
retq