#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*/ printf(char *, char *);
void recursive_enumerate(int zeros, int ones, int twos, char *string, int loc) {
  if (zeros > 0) {
    string[loc] = '0';
    recursive_enumerate(zeros - 1, ones, twos, string, loc + 1);
  }
  if (ones > 0) {
    string[loc] = '1';
    recursive_enumerate(zeros, ones - 1, twos, string, loc + 1);
  }
  if (twos > 0) {
    string[loc] = '2';
    recursive_enumerate(zeros, ones, twos - 1, string, loc + 1);
  }
  if (zeros + ones + twos == 0) {
    string[loc] = '\0';
    printf("%s\n", string);
  }
}


x86 assembly (clang, -O0):
<recursive_enumerate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    116c <recursive_enumerate+0x4c>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x30,(%rax,%rcx,1)
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
add    $0x1,%r8d
call   1030 <recursive_enumerate@plt>
cmpl   $0x0,-0x8(%rbp)
jle    119f <recursive_enumerate+0x7f>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x31,(%rax,%rcx,1)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
add    $0x1,%r8d
call   1030 <recursive_enumerate@plt>
cmpl   $0x0,-0xc(%rbp)
jle    11d2 <recursive_enumerate+0xb2>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x32,(%rax,%rcx,1)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
add    $0x1,%r8d
call   1030 <recursive_enumerate@plt>
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
cmp    $0x0,%eax
jne    1200 <recursive_enumerate+0xe0>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rsi
lea    0xe05(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recursive_enumerate>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r15
mov    %edx,%r14d
mov    %esi,%ebx
mov    %edi,%r12d
movslq %r8d,%r13
test   %edi,%edi
jle    1156 <recursive_enumerate+0x36>
movb   $0x30,(%r15,%r13,1)
lea    -0x1(%r12),%edi
lea    0x1(%r13),%r8d
mov    %ebx,%esi
mov    %r14d,%edx
mov    %r15,%rcx
call   1030 <recursive_enumerate@plt>
test   %ebx,%ebx
jle    1174 <recursive_enumerate+0x54>
movb   $0x31,(%r15,%r13,1)
lea    -0x1(%rbx),%esi
lea    0x1(%r13),%r8d
mov    %r12d,%edi
mov    %r14d,%edx
mov    %r15,%rcx
call   1030 <recursive_enumerate@plt>
test   %r14d,%r14d
jle    1193 <recursive_enumerate+0x73>
movb   $0x32,(%r15,%r13,1)
lea    -0x1(%r14),%edx
lea    0x1(%r13),%r8d
mov    %r12d,%edi
mov    %ebx,%esi
mov    %r15,%rcx
call   1030 <recursive_enumerate@plt>
add    %r12d,%ebx
add    %r14d,%ebx
jne    11b8 <recursive_enumerate+0x98>
movb   $0x0,(%r15,%r13,1)
lea    0xe59(%rip),%rdi
mov    %r15,%rsi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <printf@plt>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
define void @recursive_enumerate(i32 %0, i32 %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%11 = load i32, i32* %6
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %5
%14 = load i8*, i8** %9
%15 = load i32, i32* %10
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
store i8 48, i8* %17
%18 = load i32, i32* %6
%19 = sub nsw i32 %18, 1
%20 = load i32, i32* %7
%21 = load i32, i32* %8
%22 = load i8*, i8** %9
%23 = load i32, i32* %10
%24 = add nsw i32 %23, 1
br label %25
25: ; preds = %13, %5
%26 = load i32, i32* %7
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %40
28: ; preds = %25
%29 = load i8*, i8** %9
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 49, i8* %32
%33 = load i32, i32* %6
%34 = load i32, i32* %7
%35 = sub nsw i32 %34, 1
%36 = load i32, i32* %8
%37 = load i8*, i8** %9
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 1
br label %40
40: ; preds = %28, %25
%41 = load i32, i32* %8
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %55
43: ; preds = %40
%44 = load i8*, i8** %9
%45 = load i32, i32* %10
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
store i8 50, i8* %47
%48 = load i32, i32* %6
%49 = load i32, i32* %7
%50 = load i32, i32* %8
%51 = sub nsw i32 %50, 1
%52 = load i8*, i8** %9
%53 = load i32, i32* %10
%54 = add nsw i32 %53, 1
br label %55
55: ; preds = %43, %40
%56 = load i32, i32* %6
%57 = load i32, i32* %7
%58 = add nsw i32 %56, %57
%59 = load i32, i32* %8
%60 = add nsw i32 %58, %59
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %69
62: ; preds = %55
%63 = load i8*, i8** %9
%64 = load i32, i32* %10
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
store i8 0, i8* %66
%67 = load i8*, i8** %9
%68 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %67)
br label %69
69: ; preds = %62, %55
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define void @recursive_enumerate(i32 %0, i32 %1, i32 %2, i8* %3, i32 %4) {
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %12
7: ; preds = %5
%8 = sext i32 %4 to i64
%9 = getelementptr inbounds i8, i8* %3, i64 %8
store i8 48, i8* %9
%10 = add nsw i32 %0, -1
%11 = add nsw i32 %4, 1
tail call void @recursive_enumerate(i32 %10, i32 %1, i32 %2, i8* %3, i32 %11)
br label %12
12: ; preds = %7, %5
%13 = icmp sgt i32 %1, 0
br i1 %13, label %14, label %19
14: ; preds = %12
%15 = sext i32 %4 to i64
%16 = getelementptr inbounds i8, i8* %3, i64 %15
store i8 49, i8* %16
%17 = add nsw i32 %1, -1
%18 = add nsw i32 %4, 1
tail call void @recursive_enumerate(i32 %0, i32 %17, i32 %2, i8* %3, i32 %18)
br label %19
19: ; preds = %14, %12
%20 = icmp sgt i32 %2, 0
br i1 %20, label %21, label %26
21: ; preds = %19
%22 = sext i32 %4 to i64
%23 = getelementptr inbounds i8, i8* %3, i64 %22
store i8 50, i8* %23
%24 = add nsw i32 %2, -1
%25 = add nsw i32 %4, 1
tail call void @recursive_enumerate(i32 %0, i32 %1, i32 %24, i8* %3, i32 %25)
br label %26
26: ; preds = %21, %19
%27 = add nsw i32 %1, %0
%28 = sub i32 0, %2
%29 = icmp eq i32 %27, %28
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = sext i32 %4 to i64
%32 = getelementptr inbounds i8, i8* %3, i64 %31
store i8 0, i8* %32
%33 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %34
34: ; preds = %30, %26
ret void
}