#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 /*<<< orphan*/ generate_combinations(int, int *, int, int *);
int /*<<< orphan*/ iterative_combinations(int, int *, int);
int /*<<< orphan*/ printf(char *);
int main() {
  int positions = 2;
  int combo[positions];
  int set_size = 8;
  int num_set[set_size];
  int i;
  for (i = 0; i < set_size; i++) {
    num_set[i] = i;
  }
  printf("generate combination of octal numbers\n");
  generate_combinations(positions, combo, set_size, num_set);
  positions = 3;
  set_size = 4;
  int second_combo[positions];
  int letter_set[set_size];
  for (i = 0; i < set_size; i++) {
    letter_set[i] = 'A' + i;
  }
  printf("\ngenerate padlock combinations when it is 4 wheels of A to C\n");
  generate_combinations(positions, second_combo, set_size, letter_set);
  for (i = 0; i < set_size; i++) {
    letter_set[i] = 'Q' + i;
  }
  printf("\ngenerate padlock combinations iteratively\n");
  iterative_combinations(set_size, letter_set, positions);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
movl   $0x8,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11c3 <main+0x93>
mov    -0x48(%rbp),%rax
mov    -0x2c(%rbp),%edx
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    119b <main+0x6b>
lea    0xe36(%rip),%rdi
call   1040 <printf@plt>
mov    -0x50(%rbp),%rsi
mov    -0x48(%rbp),%rcx
mov    -0x8(%rbp),%edi
mov    -0x1c(%rbp),%edx
call   1030 <generate_combinations@plt>
movl   $0x3,-0x8(%rbp)
movl   $0x4,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1262 <main+0x132>
mov    -0x58(%rbp),%rax
mov    -0x2c(%rbp),%edx
add    $0x41,%edx
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1237 <main+0x107>
lea    0xdbe(%rip),%rdi
call   1040 <printf@plt>
mov    -0x60(%rbp),%rsi
mov    -0x58(%rbp),%rcx
mov    -0x8(%rbp),%edi
mov    -0x1c(%rbp),%edx
call   1030 <generate_combinations@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12b3 <main+0x183>
mov    -0x58(%rbp),%rax
mov    -0x2c(%rbp),%edx
add    $0x51,%edx
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1288 <main+0x158>
lea    0xdab(%rip),%rdi
call   1040 <printf@plt>
mov    -0x58(%rbp),%rsi
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%edx
call   1050 <iterative_combinations@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x50,%rsp
movaps 0xec4(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xec8(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
lea    0xeec(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%rsi
lea    0x20(%rsp),%rcx
mov    $0x2,%edi
mov    $0x8,%edx
call   1030 <generate_combinations@plt>
movaps 0xea7(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xee2(%rip),%rdi
call   1040 <puts@plt>
lea    0x40(%rsp),%rsi
mov    %rsp,%rbx
mov    $0x3,%edi
mov    $0x4,%edx
mov    %rbx,%rcx
call   1030 <generate_combinations@plt>
movaps 0xe86(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xeee(%rip),%rdi
call   1040 <puts@plt>
mov    $0x4,%edi
mov    %rbx,%rsi
mov    $0x3,%edx
call   1050 <iterative_combinations@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [39 x i8] c"generate combination of octal numbers\0A\00"
@.str.1 = [62 x i8] c"\0Agenerate padlock combinations when it is 4 wheels of A to C\0A\00"
@.str.2 = [44 x i8] c"\0Agenerate padlock combinations iteratively\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
store i32 0, i32* %1
store i32 2, i32* %2
%10 = load i32, i32* %2
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %3
%13 = alloca i32, i64 %11
store i64 %11, i64* %4
store i32 8, i32* %5
%14 = load i32, i32* %5
%15 = zext i32 %14 to i64
%16 = alloca i32, i64 %15
store i64 %15, i64* %6
store i32 0, i32* %7
br label %17
17: ; preds = %26, %0
%18 = load i32, i32* %7
%19 = load i32, i32* %5
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %29
21: ; preds = %17
%22 = load i32, i32* %7
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %16, i64 %24
store i32 %22, i32* %25
br label %26
26: ; preds = %21
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %17
29: ; preds = %17
%30 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%31 = load i32, i32* %2
%32 = load i32, i32* %5
%33 = call i32 @generate_combinations(i32 %31, i32* %13, i32 %32, i32* %16)
store i32 3, i32* %2
store i32 4, i32* %5
%34 = load i32, i32* %2
%35 = zext i32 %34 to i64
%36 = alloca i32, i64 %35
store i64 %35, i64* %8
%37 = load i32, i32* %5
%38 = zext i32 %37 to i64
%39 = alloca i32, i64 %38
store i64 %38, i64* %9
store i32 0, i32* %7
br label %40
40: ; preds = %50, %29
%41 = load i32, i32* %7
%42 = load i32, i32* %5
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %53
44: ; preds = %40
%45 = load i32, i32* %7
%46 = add nsw i32 65, %45
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %39, i64 %48
store i32 %46, i32* %49
br label %50
50: ; preds = %44
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
br label %40
53: ; preds = %40
%54 = call i32 @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0))
%55 = load i32, i32* %2
%56 = load i32, i32* %5
%57 = call i32 @generate_combinations(i32 %55, i32* %36, i32 %56, i32* %39)
store i32 0, i32* %7
br label %58
58: ; preds = %68, %53
%59 = load i32, i32* %7
%60 = load i32, i32* %5
%61 = icmp slt i32 %59, %60
br i1 %61, label %62, label %71
62: ; preds = %58
%63 = load i32, i32* %7
%64 = add nsw i32 81, %63
%65 = load i32, i32* %7
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32, i32* %39, i64 %66
store i32 %64, i32* %67
br label %68
68: ; preds = %62
%69 = load i32, i32* %7
%70 = add nsw i32 %69, 1
store i32 %70, i32* %7
br label %58
71: ; preds = %58
%72 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%73 = load i32, i32* %5
%74 = load i32, i32* %2
%75 = call i32 @iterative_combinations(i32 %73, i32* %39, i32 %74)
store i32 0, i32* %1
%76 = load i8*, i8** %3
%77 = load i32, i32* %1
ret i32 %77
}

LLVM IR (-O2):
@str = [38 x i8] c"generate combination of octal numbers\00"
@str.3 = [61 x i8] c"\0Agenerate padlock combinations when it is 4 wheels of A to C\00"
@str.4 = [43 x i8] c"\0Agenerate padlock combinations iteratively\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [8 x i32]
%3 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 0
%4 = bitcast [8 x i32]* %2 to <4 x i32>*
store <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32>* %4
%5 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 4
%6 = bitcast i32* %5 to <4 x i32>*
store <4 x i32> <i32 4, i32 5, i32 6, i32 7>, <4 x i32>* %6
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%9 = call i32 @generate_combinations(i32 2, i32* %7, i32 8, i32* %3)
%10 = alloca [3 x i32]
%11 = alloca <4 x i32>
%12 = getelementptr inbounds <4 x i32>, <4 x i32>* %11, i64 0, i64 0
store <4 x i32> <i32 65, i32 66, i32 67, i32 68>, <4 x i32>* %11
%13 = getelementptr inbounds [3 x i32], [3 x i32]* %10, i64 0, i64 0
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @str.3, i64 0, i64 0))
%15 = call i32 @generate_combinations(i32 3, i32* %13, i32 4, i32* %12)
store <4 x i32> <i32 81, i32 82, i32 83, i32 84>, <4 x i32>* %11
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.4, i64 0, i64 0))
%17 = call i32 @iterative_combinations(i32 4, i32* %12, i32 3)
ret i32 0
}