// File: /workspace/github_c_makefile_star2_O3/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 0x3952d
leaq 0x7049e(%rip), %r14     # 0xa9990
movl $0x8, %edi
movq %r14, %rsi
movl $0x4, %edx
callq 0x3a0e1
movq %rax, %r13
movl $0x4, %edi
movq %r14, %rsi
movl $0x5, %edx
callq 0x3a0e1
movq %rax, (%r13)
movl $0x0, (%rax)
movl $0x1, %eax
jmp 0x396d0
movl %edi, %r12d
leal -0x1(%r12), %edi
movl %edi, 0x4(%rsp)
movq %r15, %rsi
callq 0x394d5
movslq (%r15), %rsi
movslq %r12d, %rbx
imulq %rbx, %rsi
shlq $0x3, %rsi
movq %rax, %rdi
movl %r12d, %edx
callq 0x3a0b4
movq %rax, %r13
movl (%r15), %eax
testl %eax, %eax
jle 0x396cc
leaq (,%rbx,4), %rcx
movq %rcx, 0x18(%rsp)
movl %r12d, %ecx
movq %rcx, 0x38(%rsp)
addq $-0x2, %rcx
movq %rcx, 0x20(%rsp)
movq $0x0, 0x8(%rsp)
movq %r12, 0x28(%rsp)
movq %r13, 0x10(%rsp)
movq %r15, 0x40(%rsp)
movq %rbx, 0x30(%rsp)
cmpl $0x2, %r12d
jl 0x39663
movl $0x1, %ecx
movl $0x8, %ebp
movl $0x4, %r12d
movq 0x20(%rsp), %r14
movq %rcx, %r13
movl (%r15), %r15d
imull %r13d, %r15d
movq 0x8(%rsp), %rbx
addl %ebx, %r15d
movq 0x18(%rsp), %rdi
leaq 0x703b0(%rip), %rsi     # 0xa9990
movl $0x11, %edx
callq 0x3a0e1
movslq %r15d, %rcx
movq 0x10(%rsp), %rdx
movq %rax, (%rdx,%rcx,8)
movq (%rdx,%rbx,8), %rdx
xorl %ecx, %ecx
movl (%rdx,%rcx,4), %esi
movl %esi, (%rax,%rcx,4)
incq %rcx
cmpq %rcx, %r13
jne 0x395fc
leaq 0x1(%r13), %rcx
movq 0x30(%rsp), %rbx
cmpq %rbx, %rcx
jge 0x39633
movq %rax, %rsi
addq %rbp, %rsi
addq %r12, %rdx
xorl %edi, %edi
movl (%rdx,%rdi,4), %r8d
movl %r8d, (%rsi,%rdi,4)
incq %rdi
cmpq %rdi, %r14
jne 0x39623
movl 0x4(%rsp), %edx
movl %edx, (%rax,%r13,4)
addq $0x4, %rbp
addq $0x4, %r12
decq %r14
cmpq 0x38(%rsp), %rcx
movq 0x40(%rsp), %r15
jne 0x395c2
movl (%r15), %eax
movq 0x28(%rsp), %r12
movq 0x10(%rsp), %r13
movq 0x8(%rsp), %rsi
incq %rsi
movslq %eax, %rcx
movq %rsi, 0x8(%rsp)
cmpq %rcx, %rsi
jl 0x395a3
testl %eax, %eax
jle 0x396cc
movl 0x4(%rsp), %ebx
incq %rbx
xorl %r14d, %r14d
movq (%r13,%r14,8), %rdi
movq 0x18(%rsp), %rsi
movl %r12d, %edx
callq 0x3a0b4
movq %rax, (%r13,%r14,8)
cmpl $0x2, %r12d
jl 0x396bb
movq %rbx, %rcx
movl -0x8(%rax,%rcx,4), %edx
movl %edx, -0x4(%rax,%rcx,4)
decq %rcx
cmpq $0x1, %rcx
jg 0x396aa
movl 0x4(%rsp), %ecx
movl %ecx, (%rax)
incq %r14
movslq (%r15), %rax
cmpq %rax, %r14
jl 0x3968a
imull %r12d, %eax
movl %eax, (%r15)
movq %r13, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq