#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 n, int open, int close) {
  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    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    1158 <paren+0x38>
lea    0xeb9(%rip),%rdi
lea    0x2ef2(%rip),%rsi
call   1040 <printf@plt>
jmp    11c1 <paren+0xa1>
mov    -0xc(%rbp),%eax
cmp    -0x10(%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    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
call   1030 <paren@plt>
mov    -0xc(%rbp),%eax
cmp    -0x8(%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    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
add    $0x1,%edx
mov    -0x10(%rbp),%ecx
call   1030 <paren@plt>
jmp    11c1 <paren+0xa1>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<paren>:
cmp    %esi,%ecx
jne    1137 <paren+0x17>
lea    0xed5(%rip),%rdi
lea    0x2f0e(%rip),%rsi
jmp    1040 <printf@plt>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r12d
mov    %edx,%ebp
mov    %esi,%r14d
lea    0x1(%r12),%eax
mov    %eax,0x4(%rsp)
cmp    %esi,%edx
mov    %esi,%r13d
cmovg  %edx,%r13d
movslq %edi,%rax
lea    0x1(%rax),%ebx
lea    0x2ed7(%rip),%r15
add    %rax,%r15
cmp    %r12d,%ebp
jle    1194 <paren+0x74>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x7d,(%r15)
mov    %ebx,%edi
mov    %r14d,%esi
mov    %ebp,%edx
mov    0x4(%rsp),%ecx
call   1030 <paren@plt>
cmp    %ebp,%r13d
je     11ae <paren+0x8e>
movb   $0x7b,(%r15)
add    $0x1,%ebp
add    $0x1,%ebx
add    $0x1,%r15
cmp    %r12d,%ebp
jg     1180 <paren+0x60>
jmp    1194 <paren+0x74>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
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* %8
%10 = load i32, i32* %6
%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* %7
%16 = load i32, i32* %8
%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* %6
%25 = load i32, i32* %7
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
br label %28
28: ; preds = %18, %14
%29 = load i32, i32* %7
%30 = load i32, i32* %6
%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* %6
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
%41 = load i32, i32* %8
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 %3, %1
br i1 %5, label %10, label %6
6: ; preds = %4
%7 = add nsw i32 %3, 1
%8 = sext i32 %0 to i64
%9 = call i32 @llvm.smax.i32(i32 %2, i32 %1)
br label %12
10: ; preds = %4
%11 = 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 %26
12: ; preds = %22, %6
%13 = phi i64 [ %8, %6 ], [ %24, %22 ]
%14 = phi i32 [ %2, %6 ], [ %25, %22 ]
%15 = icmp sgt i32 %14, %3
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = getelementptr inbounds [100 x i8], [100 x i8]* @paren.a, i64 0, i64 %13
store i8 125, i8* %17
%18 = trunc i64 %13 to i32
%19 = add i32 %18, 1
tail call void @paren(i32 %19, i32 %1, i32 %14, i32 %7)
br label %20
20: ; preds = %16, %12
%21 = icmp eq i32 %14, %9
br i1 %21, label %26, label %22
22: ; preds = %20
%23 = getelementptr inbounds [100 x i8], [100 x i8]* @paren.a, i64 0, i64 %13
store i8 123, i8* %23
%24 = add nsw i64 %13, 1
%25 = add i32 %14, 1
br label %12
26: ; preds = %20, %10
ret void
}