#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 pow(int, int);
int /*<<< orphan*/ printf(char *, ...);
void iterative_combinations(int set_size, int set[set_size], int positions) {
  int n, i;
  int val[positions];
  int c[positions];
  for (n = 0; n < positions; ++n) {
    c[n] = 0;
    val[n] = 0;
  }
  for (n = 0; n < pow(set_size, positions); n++) {
    for (i = 0; i < positions; i++) {
      printf("%c ", set[val[i]]);
      c[i]++;
      if (c[i] == pow(set_size, (positions - 1 - i))) {
        c[i] = 0;
        val[i]++;
        if (val[i] == set_size)
          val[i] = 0;
      }
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<iterative_combinations>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b8 <iterative_combinations+0x98>
mov    -0x48(%rbp),%rax
mov    -0x40(%rbp),%rcx
movslq -0x18(%rbp),%rdx
movl   $0x0,(%rcx,%rdx,4)
movslq -0x18(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1180 <iterative_combinations+0x60>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <pow@plt>
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
cmp    %ecx,%eax
jge    12bd <iterative_combinations+0x19d>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12a1 <iterative_combinations+0x181>
mov    -0x48(%rbp),%rcx
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x40(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x50(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
sub    -0x1c(%rbp),%esi
call   1040 <pow@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%eax
cmp    %ecx,%eax
jne    128e <iterative_combinations+0x16e>
mov    -0x48(%rbp),%rax
mov    -0x40(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
movl   $0x0,(%rcx,%rdx,4)
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x4(%rbp),%eax
jne    1289 <iterative_combinations+0x169>
mov    -0x48(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
jmp    128e <iterative_combinations+0x16e>
jmp    1293 <iterative_combinations+0x173>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e4 <iterative_combinations+0xc4>
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11bf <iterative_combinations+0x9f>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iterative_combinations>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edx,%r15d
mov    %rsi,-0x58(%rbp)
mov    %edi,-0x2c(%rbp)
mov    %edx,%ebx
mov    %rsp,%r13
lea    0xf(,%rbx,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
test   %edx,%edx
jle    11a1 <iterative_combinations+0x61>
lea    0x0(,%rbx,4),%r14
mov    %r12,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1050 <memset@plt>
mov    %r13,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1050 <memset@plt>
mov    %r12,-0x40(%rbp)
mov    -0x2c(%rbp),%edi
mov    %r15d,%esi
call   1060 <pow@plt>
test   %eax,%eax
jle    1286 <iterative_combinations+0x146>
lea    -0x1(%r15),%eax
mov    %eax,-0x30(%rbp)
xor    %r14d,%r14d
mov    %r15,-0x48(%rbp)
mov    %rbx,-0x50(%rbp)
jmp    11fa <iterative_combinations+0xba>
nopl   0x0(%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x34(%rbp),%r14d
add    $0x1,%r14d
mov    -0x2c(%rbp),%edi
mov    -0x48(%rbp),%r15
mov    %r15d,%esi
call   1060 <pow@plt>
cmp    %eax,%r14d
jge    1286 <iterative_combinations+0x146>
mov    %r14d,-0x34(%rbp)
test   %r15d,%r15d
jle    11d0 <iterative_combinations+0x90>
mov    -0x30(%rbp),%r14d
xor    %r15d,%r15d
jmp    1221 <iterative_combinations+0xe1>
nopl   0x0(%rax)
add    $0x1,%r15
add    $0xffffffff,%r14d
mov    -0x50(%rbp),%rbx
cmp    %r15,%rbx
je     11d0 <iterative_combinations+0x90>
movslq 0x0(%r13,%r15,4),%r12
mov    -0x58(%rbp),%rax
mov    (%rax,%r12,4),%esi
lea    0xdcb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rbx
mov    -0x40(%rbp),%rax
mov    (%rax,%r15,4),%r13d
add    $0x1,%r13d
mov    %r13d,(%rax,%r15,4)
mov    -0x2c(%rbp),%edi
mov    %r14d,%esi
call   1060 <pow@plt>
cmp    %eax,%r13d
mov    %rbx,%r13
jne    1210 <iterative_combinations+0xd0>
mov    -0x40(%rbp),%rax
movl   $0x0,(%rax,%r15,4)
add    $0x1,%r12d
cmp    -0x2c(%rbp),%r12d
mov    $0x0,%eax
cmove  %eax,%r12d
mov    %r12d,0x0(%r13,%r15,4)
jmp    1210 <iterative_combinations+0xd0>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%c \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @iterative_combinations(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%12 = load i32, i32* %4
%13 = zext i32 %12 to i64
%14 = load i32, i32* %6
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %9
%17 = alloca i32, i64 %15
store i64 %15, i64* %10
%18 = load i32, i32* %6
%19 = zext i32 %18 to i64
%20 = alloca i32, i64 %19
store i64 %19, i64* %11
store i32 0, i32* %7
br label %21
21: ; preds = %32, %3
%22 = load i32, i32* %7
%23 = load i32, i32* %6
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %35
25: ; preds = %21
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %20, i64 %27
store i32 0, i32* %28
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %17, i64 %30
store i32 0, i32* %31
br label %32
32: ; preds = %25
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %21
35: ; preds = %21
store i32 0, i32* %7
br label %36
36: ; preds = %99, %35
%37 = load i32, i32* %7
%38 = load i32, i32* %4
%39 = load i32, i32* %6
%40 = call i32 @pow(i32 %38, i32 %39)
%41 = icmp slt i32 %37, %40
br i1 %41, label %42, label %102
42: ; preds = %36
store i32 0, i32* %8
br label %43
43: ; preds = %94, %42
%44 = load i32, i32* %8
%45 = load i32, i32* %6
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %97
47: ; preds = %43
%48 = load i32*, i32** %5
%49 = load i32, i32* %8
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i32, i32* %17, i64 %50
%52 = load i32, i32* %51
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %48, i64 %53
%55 = load i32, i32* %54
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %55)
%57 = load i32, i32* %8
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %20, i64 %58
%60 = load i32, i32* %59
%61 = add nsw i32 %60, 1
store i32 %61, i32* %59
%62 = load i32, i32* %8
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i32, i32* %20, i64 %63
%65 = load i32, i32* %64
%66 = load i32, i32* %4
%67 = load i32, i32* %6
%68 = sub nsw i32 %67, 1
%69 = load i32, i32* %8
%70 = sub nsw i32 %68, %69
%71 = call i32 @pow(i32 %66, i32 %70)
%72 = icmp eq i32 %65, %71
br i1 %72, label %73, label %93
73: ; preds = %47
%74 = load i32, i32* %8
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i32, i32* %20, i64 %75
store i32 0, i32* %76
%77 = load i32, i32* %8
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i32, i32* %17, i64 %78
%80 = load i32, i32* %79
%81 = add nsw i32 %80, 1
store i32 %81, i32* %79
%82 = load i32, i32* %8
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i32, i32* %17, i64 %83
%85 = load i32, i32* %84
%86 = load i32, i32* %4
%87 = icmp eq i32 %85, %86
br i1 %87, label %88, label %92
88: ; preds = %73
%89 = load i32, i32* %8
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i32, i32* %17, i64 %90
store i32 0, i32* %91
br label %92
92: ; preds = %88, %73
br label %93
93: ; preds = %92, %47
br label %94
94: ; preds = %93
%95 = load i32, i32* %8
%96 = add nsw i32 %95, 1
store i32 %96, i32* %8
br label %43
97: ; preds = %43
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %99
99: ; preds = %97
%100 = load i32, i32* %7
%101 = add nsw i32 %100, 1
store i32 %101, i32* %7
br label %36
102: ; preds = %36
%103 = load i8*, i8** %9
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%c \00"
define void @iterative_combinations(i32 %0, i32* nocapture %1, i32 %2) {
%4 = zext i32 %2 to i64
%5 = alloca i32, i64 %4
%6 = alloca i32, i64 %4
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %12
8: ; preds = %3
%9 = bitcast i32* %6 to i8*
%10 = bitcast i32* %5 to i8*
%11 = shl nuw nsw i64 %4, 2
br label %12
12: ; preds = %8, %3
%13 = tail call i32 @pow(i32 %0, i32 %2)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %45
15: ; preds = %12, %40
%16 = phi i32 [ %42, %40 ], [ 0, %12 ]
br i1 %7, label %17, label %40
17: ; preds = %15, %37
%18 = phi i64 [ %38, %37 ], [ 0, %15 ]
%19 = trunc i64 %18 to i32
%20 = getelementptr inbounds i32, i32* %5, i64 %18
%21 = load i32, i32* %20
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %1, i64 %22
%24 = load i32, i32* %23
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = getelementptr inbounds i32, i32* %6, i64 %18
%27 = load i32, i32* %26
%28 = add nsw i32 %27, 1
store i32 %28, i32* %26
%29 = xor i32 %19, -1
%30 = add i32 %29, %2
%31 = tail call i32 @pow(i32 %0, i32 %30)
%32 = icmp eq i32 %28, %31
br i1 %32, label %33, label %37
33: ; preds = %17
store i32 0, i32* %26
%34 = add nsw i32 %21, 1
%35 = icmp eq i32 %34, %0
%36 = select i1 %35, i32 0, i32 %34
store i32 %36, i32* %20
br label %37
37: ; preds = %33, %17
%38 = add nuw nsw i64 %18, 1
%39 = icmp eq i64 %38, %4
br i1 %39, label %40, label %17
40: ; preds = %37, %15
%41 = tail call i32 @putchar(i32 10)
%42 = add nuw nsw i32 %16, 1
%43 = tail call i32 @pow(i32 %0, i32 %2)
%44 = icmp slt i32 %42, %43
br i1 %44, label %15, label %45
45: ; preds = %40, %12
ret void
}