#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int *malloc(int);
int **permute(int *, int, int *, int **);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc <= 1) {
    fprintf(stderr, "Usage: ./test ...\n");
    exit(-1);
  }
  int i, j, count = argc - 1;
  int *nums = malloc(count * sizeof(int));
  for (i = 0; i < count; i++) {
    nums[i] = atoi(argv[i + 1]);
  }
  int *size;
  int **lists = permute(nums, argc - 1, &count, &size);
  for (i = 0; i < count; i++) {
    for (j = 0; j < argc - 1; j++) {
      printf("%d", lists[i][j]);
    }
    putchar('\n');
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     11af <main+0x3f>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    120f <main+0x9f>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1080 <atoi@plt>
mov    %eax,%edx
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d2 <main+0x62>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
lea    -0x1c(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1040 <permute@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    129a <main+0x12a>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1282 <main+0x112>
mov    -0x38(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xda4(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1244 <main+0xd4>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1231 <main+0xc1>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x1,%edi
jle    124c <main+0xdc>
mov    %rsi,%r12
mov    %edi,%r14d
lea    -0x1(%r14),%r15d
mov    %r15d,0xc(%rsp)
lea    -0x4(,%r14,4),%edi
ff
call   1070 <malloc@plt>
mov    %rax,%r13
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
lea    0x1(%rbp),%rbx
mov    0x8(%r12,%rbp,8),%rdi
call   1080 <atoi@plt>
mov    %eax,0x0(%r13,%rbp,4)
mov    %rbx,%rbp
cmp    %rbx,%r15
jne    11b0 <main+0x40>
lea    0xc(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    %r13,%rdi
mov    %r15d,%esi
call   1040 <permute@plt>
cmpl   $0x0,0xc(%rsp)
jle    123b <main+0xcb>
mov    %rax,%r13
xor    %ebx,%ebx
lea    0xe20(%rip),%r12
jmp    1218 <main+0xa8>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jge    123b <main+0xcb>
cmp    $0x2,%r14d
jl     1200 <main+0x90>
xor    %ebp,%ebp
mov    0x0(%r13,%rbx,8),%rax
mov    (%rax,%rbp,4),%esi
mov    %r12,%rdi
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1220 <main+0xb0>
jmp    1200 <main+0x90>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
lea    0xda4(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"Usage: ./test ...\0A\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp sle i32 %12, 1
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %2
%19 = load i32, i32* %4
%20 = sub nsw i32 %19, 1
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = mul i64 %22, 4
%24 = trunc i64 %23 to i32
%25 = call i32* @malloc(i32 %24)
store i32* %25, i32** %9
store i32 0, i32* %6
br label %26
26: ; preds = %42, %18
%27 = load i32, i32* %6
%28 = load i32, i32* %8
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %45
30: ; preds = %26
%31 = load i8**, i8*** %5
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8*, i8** %31, i64 %34
%36 = load i8*, i8** %35
%37 = call i32 @atoi(i8* %36)
%38 = load i32*, i32** %9
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
store i32 %37, i32* %41
br label %42
42: ; preds = %30
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %6
br label %26
45: ; preds = %26
%46 = load i32*, i32** %9
%47 = load i32, i32* %4
%48 = sub nsw i32 %47, 1
%49 = call i32** @permute(i32* %46, i32 %48, i32* %8, i32** %10)
store i32** %49, i32*** %11
store i32 0, i32* %6
br label %50
50: ; preds = %76, %45
%51 = load i32, i32* %6
%52 = load i32, i32* %8
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %79
54: ; preds = %50
store i32 0, i32* %7
br label %55
55: ; preds = %71, %54
%56 = load i32, i32* %7
%57 = load i32, i32* %4
%58 = sub nsw i32 %57, 1
%59 = icmp slt i32 %56, %58
br i1 %59, label %60, label %74
60: ; preds = %55
%61 = load i32**, i32*** %11
%62 = load i32, i32* %6
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i32*, i32** %61, i64 %63
%65 = load i32*, i32** %64
%66 = load i32, i32* %7
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i32, i32* %65, i64 %67
%69 = load i32, i32* %68
%70 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %69)
br label %71
71: ; preds = %60
%72 = load i32, i32* %7
%73 = add nsw i32 %72, 1
store i32 %73, i32* %7
br label %55
74: ; preds = %55
%75 = call i32 @putchar(i8 signext 10)
br label %76
76: ; preds = %74
%77 = load i32, i32* %6
%78 = add nsw i32 %77, 1
store i32 %78, i32* %6
br label %50
79: ; preds = %50
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"Usage: ./test ...\0A\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %2
%11 = bitcast i32* %3 to i8*
%12 = add nsw i32 %0, -1
store i32 %12, i32* %3
%13 = shl i32 %12, 2
%14 = tail call i32* @malloc(i32 %13)
%15 = zext i32 %12 to i64
br label %16
16: ; preds = %10, %16
%17 = phi i64 [ 0, %10 ], [ %18, %16 ]
%18 = add nuw nsw i64 %17, 1
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
%22 = getelementptr inbounds i32, i32* %14, i64 %17
store i32 %21, i32* %22
%23 = icmp eq i64 %18, %15
br i1 %23, label %24, label %16
24: ; preds = %16
%25 = bitcast i32** %4 to i8*
%26 = call i32** @permute(i32* %14, i32 %12, i32* %3, i32** %4)
%27 = load i32, i32* %3
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %50
29: ; preds = %24
%30 = icmp sgt i32 %0, 1
%31 = zext i32 %12 to i64
br label %32
32: ; preds = %29, %44
%33 = phi i64 [ 0, %29 ], [ %46, %44 ]
br i1 %30, label %34, label %44
34: ; preds = %32
%35 = getelementptr inbounds i32*, i32** %26, i64 %33
br label %36
36: ; preds = %34, %36
%37 = phi i64 [ 0, %34 ], [ %42, %36 ]
%38 = load i32*, i32** %35
%39 = getelementptr inbounds i32, i32* %38, i64 %37
%40 = load i32, i32* %39
%41 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %40)
%42 = add nuw nsw i64 %37, 1
%43 = icmp eq i64 %42, %31
br i1 %43, label %44, label %36
44: ; preds = %36, %32
%45 = call i32 @putchar(i8 signext 10)
%46 = add nuw nsw i64 %33, 1
%47 = load i32, i32* %3
%48 = sext i32 %47 to i64
%49 = icmp slt i64 %46, %48
br i1 %49, label %32, label %50
50: ; preds = %44, %24
ret i32 0
}