#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 paren(int pos, int open, int close, int n) {
  static char a[100];
  if (close == n) {
    printf("%s \n", a);
    return;
  } else {
    if (open > close) {
      a[pos] = '}';
      paren(pos + 1, n, open, close + 1);
    }
    if (open < n) {
      a[pos] = '{';
      paren(pos + 1, n, open + 1, close);
    }
  }
}


x86 assembly (clang, -O0):
<paren>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    1158 <paren+0x38>
lea    0xeb9(%rip),%rdi
lea    0x2ef2(%rip),%rsi
call   1040 <printf@plt>
jmp    11c1 <paren+0xa1>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    118a <paren+0x6a>
movslq -0x4(%rbp),%rcx
lea    0x2ed1(%rip),%rax
movb   $0x7d,(%rax,%rcx,1)
mov    -0x4(%rbp),%edi
add    $0x1,%edi
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
call   1030 <paren@plt>
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11bc <paren+0x9c>
movslq -0x4(%rbp),%rcx
lea    0x2e9f(%rip),%rax
movb   $0x7b,(%rax,%rcx,1)
mov    -0x4(%rbp),%edi
add    $0x1,%edi
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%edx
add    $0x1,%edx
mov    -0xc(%rbp),%ecx
call   1030 <paren@plt>
jmp    11c1 <paren+0xa1>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<paren>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    %ecx,%edx
je     118d <paren+0x6d>
mov    %edx,%r14d
mov    %esi,%ebp
movslq %edi,%rax
lea    0x1(%rax),%r12d
lea    0x2f01(%rip),%rbx
add    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ecx,%r15d
cmp    %r14d,%ebp
jle    116c <paren+0x4c>
movb   $0x7d,(%rbx)
lea    0x1(%r14),%ecx
mov    %r12d,%edi
mov    %r15d,%esi
mov    %ebp,%edx
call   1030 <paren@plt>
cmp    %r15d,%ebp
jge    11a8 <paren+0x88>
movb   $0x7b,(%rbx)
add    $0x1,%ebp
add    $0x1,%r12d
add    $0x1,%rbx
mov    %r14d,%ecx
cmp    %r14d,%ebp
mov    %ebp,%r14d
mov    %r15d,%ebp
jne    1150 <paren+0x30>
lea    0xe6c(%rip),%rdi
lea    0x2ea5(%rip),%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@paren.a = internal global [100 x i8] zeroinitializer
@.str = [5 x i8] c"%s \0A\00"
define void @paren(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%9 = load i32, i32* %7
%10 = load i32, i32* %8
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %4
%13 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([100 x i8], [100 x i8]* @paren.a, i64 0, i64 0))
br label %43
14: ; preds = %4
%15 = load i32, i32* %6
%16 = load i32, i32* %7
%17 = icmp sgt i32 %15, %16
br i1 %17, label %18, label %28
18: ; preds = %14
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [100 x i8], [100 x i8]* @paren.a, i64 0, i64 %20
store i8 125, i8* %21
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
%24 = load i32, i32* %8
%25 = load i32, i32* %6
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
br label %28
28: ; preds = %18, %14
%29 = load i32, i32* %6
%30 = load i32, i32* %8
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %42
32: ; preds = %28
%33 = load i32, i32* %5
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [100 x i8], [100 x i8]* @paren.a, i64 0, i64 %34
store i8 123, i8* %35
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
%38 = load i32, i32* %8
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
%41 = load i32, i32* %7
br label %42
42: ; preds = %32, %28
br label %43
43: ; preds = %12, %42
ret void
}

LLVM IR (-O2):
@paren.a = internal global [100 x i8] zeroinitializer
@.str = [5 x i8] c"%s \0A\00"
define void @paren(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %2, %3
br i1 %5, label %8, label %6
6: ; preds = %4
%7 = sext i32 %0 to i64
br label %10
8: ; preds = %23, %4
%9 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([100 x i8], [100 x i8]* @paren.a, i64 0, i64 0))
br label %28
10: ; preds = %6, %23
%11 = phi i64 [ %7, %6 ], [ %25, %23 ]
%12 = phi i32 [ %3, %6 ], [ %13, %23 ]
%13 = phi i32 [ %2, %6 ], [ %26, %23 ]
%14 = phi i32 [ %1, %6 ], [ %12, %23 ]
%15 = icmp sgt i32 %14, %13
br i1 %15, label %16, label %21
16: ; preds = %10
%17 = getelementptr inbounds [100 x i8], [100 x i8]* @paren.a, i64 0, i64 %11
store i8 125, i8* %17
%18 = add nsw i32 %13, 1
%19 = trunc i64 %11 to i32
%20 = add i32 %19, 1
tail call void @paren(i32 %20, i32 %12, i32 %14, i32 %18)
br label %21
21: ; preds = %16, %10
%22 = icmp slt i32 %14, %12
br i1 %22, label %23, label %28
23: ; preds = %21
%24 = getelementptr inbounds [100 x i8], [100 x i8]* @paren.a, i64 0, i64 %11
store i8 123, i8* %24
%25 = add i64 %11, 1
%26 = add nsw i32 %14, 1
%27 = icmp eq i32 %26, %13
br i1 %27, label %8, label %10
28: ; preds = %21, %8
ret void
}