// File: /workspace/github_c_makefile_star2_O1/olcaytaner[P]Isell/libiteration.c
// Function: generate_permutations
int** generate_permutations(int howmany, int*total)
{
 /*!Last Changed 27.04.2004*/
 int **result, i, j, k, index;
 if (howmany == 1)
  {
   result = safemalloc(sizeof(int *), "generate_permutations", 4);
   result[0] = safemalloc(sizeof(int), "generate_permutations", 5);
   result[0][0] = 0;
   *total = 1;
  }
 else
  {
   result = generate_permutations(howmany - 1, total);
   result = alloc(result, (*total) * howmany * sizeof(int *), howmany);
   for (i = 0; i < *total; i++)
     for (j = 1; j < howmany; j++)
      {
       index = (*total)*j + i; 
       result[index] = safemalloc(howmany * sizeof(int), "generate_permutations", 17);
       for (k = 0; k < j; k++)
         result[index][k] = result[i][k];
       for (k = j + 1; k < howmany; k++)
         result[index][k] = result[i][k - 1];
       result[index][j] = howmany - 1;
      }
   for (i = 0; i < *total; i++)
    {
     result[i] = alloc(result[i], howmany * sizeof(int), howmany);
     for (j = howmany - 1; j > 0; j--)
       result[i][j] = result[i][j - 1];
     result[i][0] = howmany - 1;
    }
   *total *= howmany;
  }
 return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r15
cmpl $0x1, %edi
jne 0x387d2
leaq 0x6e1cd(%rip), %r14     # 0xa6962
movl $0x8, %edi
movq %r14, %rsi
movl $0x4, %edx
callq 0x390f5
movq %rax, %rbx
movl $0x4, %edi
movq %r14, %rsi
movl $0x5, %edx
callq 0x390f5
movq %rbx, %r9
movq %rax, (%rbx)
movl $0x0, (%rax)
movl $0x1, %eax
jmp 0x38968
movl %edi, %r12d
leal -0x1(%r12), %edi
movl %edi, 0xc(%rsp)
movq %r15, %rsi
callq 0x38778
movslq (%r15), %rsi
movslq %r12d, %rdx
movq %rdx, 0x10(%rsp)
imulq %rdx, %rsi
shlq $0x3, %rsi
movq %rax, %rdi
movl %r12d, %edx
callq 0x390c8
movq %rax, %r9
cmpl $0x0, (%r15)
movq %rax, 0x18(%rsp)
jle 0x38908
movq 0x10(%rsp), %rax
leaq (,%rax,4), %rax
movq %rax, 0x38(%rsp)
movl %r12d, %eax
movq %rax, 0x30(%rsp)
addq $-0x2, %rax
movq %rax, 0x20(%rsp)
xorl %ebx, %ebx
movq %r15, 0x40(%rsp)
movq %r12, 0x28(%rsp)
cmpl $0x2, %r12d
jl 0x388f4
movl $0x1, %ecx
movl $0x8, %ebp
movl $0x4, %r12d
movq 0x20(%rsp), %r14
movq %rcx, %r13
movl (%r15), %r15d
imull %r13d, %r15d
addl %ebx, %r15d
movq 0x38(%rsp), %rdi
leaq 0x6e0e5(%rip), %rsi     # 0xa6962
movl $0x11, %edx
callq 0x390f5
movq 0x18(%rsp), %r9
movslq %r15d, %rcx
movq %rax, (%r9,%rcx,8)
movq (%r9,%rbx,8), %rcx
xorl %edx, %edx
movl (%rcx,%rdx,4), %esi
movl %esi, (%rax,%rdx,4)
incq %rdx
cmpq %rdx, %r13
jne 0x38899
leaq 0x1(%r13), %rcx
cmpq 0x10(%rsp), %rcx
jge 0x388d1
movq %rax, %rdx
addq %rbp, %rdx
movq (%r9,%rbx,8), %rsi
addq %r12, %rsi
xorl %edi, %edi
movl (%rsi,%rdi,4), %r8d
movl %r8d, (%rdx,%rdi,4)
incq %rdi
cmpq %rdi, %r14
jne 0x388c1
movl 0xc(%rsp), %edx
movl %edx, (%rax,%r13,4)
addq $0x4, %rbp
addq $0x4, %r12
decq %r14
cmpq 0x30(%rsp), %rcx
movq 0x40(%rsp), %r15
jne 0x38864
incq %rbx
movslq (%r15), %rax
cmpq %rax, %rbx
movq 0x28(%rsp), %r12
jl 0x38845
movl (%r15), %eax
testl %eax, %eax
jle 0x38964
shlq $0x2, 0x10(%rsp)
movl 0xc(%rsp), %ebx
incq %rbx
xorl %r14d, %r14d
movq (%r9,%r14,8), %rdi
movq 0x10(%rsp), %rsi
movl %r12d, %edx
callq 0x390c8
movq 0x18(%rsp), %r9
movq %rax, (%r9,%r14,8)
cmpl $0x2, %r12d
jl 0x38953
movq %rbx, %rcx
movl -0x8(%rax,%rcx,4), %edx
movl %edx, -0x4(%rax,%rcx,4)
decq %rcx
cmpq $0x1, %rcx
jg 0x38942
movl 0xc(%rsp), %ecx
movl %ecx, (%rax)
incq %r14
movslq (%r15), %rax
cmpq %rax, %r14
jl 0x3891f
imull %r12d, %eax
movl %eax, (%r15)
movq %r9, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq