// File: /workspace/github_c_makefile_star2_O0/vrancurel[P]ec/mat.c
// Function: mat_inv
void mat_inv(t_mat *mat)
{
  t_mat *aug;
  int dim, i, j, k, tpos, tval, r;

  assert(mat->n_rows == mat->n_cols);
  dim = mat->n_rows;
  aug = mat_xcalloc(dim, dim * 2);

  for (i = 0;i < dim;i++) {
    for (j = 0;j < dim;j++) {
      MAT_ITEM(aug, i, j) = MAT_ITEM(mat, i, j);
    }
  }

  for (i = 0;i < dim;i++) {
    for (j = dim;j < 2*dim;j++) {
      if (i == (j % dim))
        MAT_ITEM(aug, i, j) = 1;
      else
        MAT_ITEM(aug, i, j) = 0;
    }
  }

  /* using gauss-jordan elimination */
  for (j = 0;j < dim;j++) {
    tpos = j;
    
    /* finding maximum jth column element in last (dimension-j) rows */
    for (i = j+1;i < dim;i++) {
      if (MAT_ITEM(aug, i, j) > MAT_ITEM(aug, tpos, j))
        tpos = i;
    }
    
    /* swapping row which has maximum jth column element */
    if (tpos != j) {
      for (k=0;k < 2*dim;k++) {
        tval = MAT_ITEM(aug, j, k);
        MAT_ITEM(aug, j, k) = MAT_ITEM(aug, tpos, k);
        MAT_ITEM(aug, tpos, k) = tval;
      }
    }
    
    /* performing row operations to form required identity matrix out of the input matrix */
    for (i = 0;i < dim;i++) {
      if (i != j) {
        r = MAT_ITEM(aug, i, j);
        for (k = 0;k < 2*dim;k++) {
          MAT_ITEM(aug, i, k) ^= gmul(gdiv(MAT_ITEM(aug, j, k), MAT_ITEM(aug, j, j)), r);
        }
      } else {
        r = MAT_ITEM(aug, i, j);
        for (k = 0;k < 2*dim;k++) {
          MAT_ITEM(aug, i, k) = gdiv(MAT_ITEM(aug, i, k), r);
        }
      }
    }
  }

  for (i = 0;i < dim;i++) {
    for (j = 0;j < dim;j++) {
      MAT_ITEM(mat, i, j) = MAT_ITEM(aug, i, dim + j);
    }
  }

  mat_free(aug);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jne 0x325d
jmp 0x327c
leaq 0x10f8(%rip), %rdi      # 0x435c
leaq 0x10c5(%rip), %rsi      # 0x4330
movl $0xc8, %edx
leaq 0x1100(%rip), %rcx      # 0x4377
callq 0x1080
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %edi
movl -0x14(%rbp), %esi
shll %esi
callq 0x2a10
movq %rax, -0x10(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x3302
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x32f5
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x18(%rbp), %ecx
movq -0x8(%rbp), %rdx
imull 0x4(%rdx), %ecx
addl -0x1c(%rbp), %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rsi
imull 0x4(%rsi), %ecx
addl -0x1c(%rbp), %ecx
movl %ecx, %ecx
movl %edx, (%rax,%rcx,4)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x32ac
jmp 0x32f7
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x329d
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x3398
movl -0x14(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl -0x14(%rbp), %ecx
shll %ecx
cmpl %ecx, %eax
jge 0x3388
movl -0x18(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x1c(%rbp), %eax
cltd
idivl -0x14(%rbp)
movl -0x30(%rbp), %eax
cmpl %edx, %eax
jne 0x335c
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rdx
imull 0x4(%rdx), %ecx
addl -0x1c(%rbp), %ecx
movl %ecx, %ecx
movl $0x1, (%rax,%rcx,4)
jmp 0x337b
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rdx
imull 0x4(%rdx), %ecx
addl -0x1c(%rbp), %ecx
movl %ecx, %ecx
movl $0x0, (%rax,%rcx,4)
jmp 0x337d
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x331b
jmp 0x338a
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x3309
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x3612
movl -0x1c(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x340d
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rdx
imull 0x4(%rdx), %ecx
addl -0x1c(%rbp), %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl -0x24(%rbp), %edx
movq -0x10(%rbp), %rsi
imull 0x4(%rsi), %edx
addl -0x1c(%rbp), %edx
movl %edx, %edx
cmpl (%rcx,%rdx,4), %eax
jle 0x3400
movl -0x18(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x3402
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x33ba
movl -0x24(%rbp), %eax
cmpl -0x1c(%rbp), %eax
je 0x34b2
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movl -0x14(%rbp), %ecx
shll %ecx
cmpl %ecx, %eax
jge 0x34b0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x1c(%rbp), %ecx
movq -0x10(%rbp), %rdx
imull 0x4(%rdx), %ecx
addl -0x20(%rbp), %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x24(%rbp), %ecx
movq -0x10(%rbp), %rdx
imull 0x4(%rdx), %ecx
addl -0x20(%rbp), %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x1c(%rbp), %ecx
movq -0x10(%rbp), %rsi
imull 0x4(%rsi), %ecx
addl -0x20(%rbp), %ecx
movl %ecx, %ecx
movl %edx, (%rax,%rcx,4)
movl -0x28(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x24(%rbp), %ecx
movq -0x10(%rbp), %rsi
imull 0x4(%rsi), %ecx
addl -0x20(%rbp), %ecx
movl %ecx, %ecx
movl %edx, (%rax,%rcx,4)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x3420
jmp 0x34b2
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x3602
movl -0x18(%rbp), %eax
cmpl -0x1c(%rbp), %eax
je 0x3574
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rdx
imull 0x4(%rdx), %ecx
addl -0x1c(%rbp), %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x2c(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movl -0x14(%rbp), %ecx
shll %ecx
cmpl %ecx, %eax
jge 0x3572
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x1c(%rbp), %ecx
movq -0x10(%rbp), %rdx
imull 0x4(%rdx), %ecx
addl -0x20(%rbp), %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x1c(%rbp), %ecx
movq -0x10(%rbp), %rdx
imull 0x4(%rdx), %ecx
addl -0x1c(%rbp), %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %esi
callq 0x14b0
movl %eax, %edi
movl -0x2c(%rbp), %esi
callq 0x1440
movl %eax, %edx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rsi
imull 0x4(%rsi), %ecx
addl -0x20(%rbp), %ecx
movl %ecx, %ecx
xorl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x34f6
jmp 0x35f2
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rdx
imull 0x4(%rdx), %ecx
addl -0x1c(%rbp), %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x2c(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movl -0x14(%rbp), %ecx
shll %ecx
cmpl %ecx, %eax
jge 0x35f0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rdx
imull 0x4(%rdx), %ecx
addl -0x20(%rbp), %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edi
movl -0x2c(%rbp), %esi
callq 0x14b0
movl %eax, %edx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rsi
imull 0x4(%rsi), %ecx
addl -0x20(%rbp), %ecx
movl %ecx, %ecx
movl %edx, (%rax,%rcx,4)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x3599
jmp 0x35f2
jmp 0x35f4
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x34b9
jmp 0x3604
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x339f
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x3683
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x3676
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rdx
imull 0x4(%rdx), %ecx
movl -0x14(%rbp), %edx
addl -0x1c(%rbp), %edx
addl %edx, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edx
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x18(%rbp), %ecx
movq -0x8(%rbp), %rsi
imull 0x4(%rsi), %ecx
addl -0x1c(%rbp), %ecx
movl %ecx, %ecx
movl %edx, (%rax,%rcx,4)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x3628
jmp 0x3678
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x3619
movq -0x10(%rbp), %rdi
callq 0x2a80
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)