#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 */
unsigned int choose(unsigned int const, unsigned int const);
int /*<<< orphan*/ combination(int *, unsigned int const, unsigned int const,
                               unsigned int);
int /*<<< orphan*/ printf(char *, int, int);
int main() {
  const unsigned n = 4, k = 2;
  const unsigned P = choose(n, k);
  int c[k];
  for (unsigned p = 1; p <= P; ++p) {
    combination(c, n, k, p);
    printf("%i %i\n", c[0], c[1]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x4,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
mov    $0x4,%edi
mov    $0x2,%esi
call   1030 <choose@plt>
mov    %eax,-0x10(%rbp)
mov    %rsp,%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
ja     11af <main+0x7f>
mov    -0x1c(%rbp),%ecx
lea    -0x30(%rbp),%rdi
mov    $0x4,%esi
mov    $0x2,%edx
call   1050 <combination@plt>
mov    -0x30(%rbp),%esi
mov    -0x2c(%rbp),%edx
lea    0xe64(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116d <main+0x3d>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x4,%edi
mov    $0x2,%esi
call   1030 <choose@plt>
test   %eax,%eax
je     118a <main+0x5a>
mov    %eax,%ebx
mov    $0x1,%ebp
mov    %rsp,%r14
lea    0xea5(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x2,%edx
mov    %ebp,%ecx
call   1050 <combination@plt>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
mov    %r15,%rdi
call   1040 <printf@plt>
add    $0x1,%ebp
cmp    %ebx,%ebp
jbe    1160 <main+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%i %i\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 0, i32* %1
store i32 4, i32* %2
store i32 2, i32* %3
%7 = call i32 @choose(i32 4, i32 2)
store i32 %7, i32* %4
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %5
%9 = alloca i32, i64 2
store i32 1, i32* %6
br label %10
10: ; preds = %22, %0
%11 = load i32, i32* %6
%12 = load i32, i32* %4
%13 = icmp ule i32 %11, %12
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = load i32, i32* %6
%16 = call i32 @combination(i32* %9, i32 4, i32 2, i32 %15)
%17 = getelementptr inbounds i32, i32* %9, i64 0
%18 = load i32, i32* %17
%19 = getelementptr inbounds i32, i32* %9, i64 1
%20 = load i32, i32* %19
%21 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %20)
br label %22
22: ; preds = %14
%23 = load i32, i32* %6
%24 = add i32 %23, 1
store i32 %24, i32* %6
br label %10
25: ; preds = %10
store i32 0, i32* %1
%26 = load i8*, i8** %5
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@.str = [7 x i8] c"%i %i\0A\00"
define i32 @main() {
%1 = tail call i32 @choose(i32 4, i32 2)
%2 = alloca [2 x i32]
%3 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%4 = icmp eq i32 %1, 0
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
br label %8
7: ; preds = %8, %0
ret i32 0
8: ; preds = %5, %8
%9 = phi i32 [ 1, %5 ], [ %14, %8 ]
%10 = call i32 @combination(i32* %3, i32 4, i32 2, i32 %9)
%11 = load i32, i32* %3
%12 = load i32, i32* %6
%13 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %12)
%14 = add i32 %9, 1
%15 = icmp ugt i32 %14, %1
br i1 %15, label %7, label %8
}