#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 print_parens_aux(char *buff, size_t buff_i, unsigned open_used, unsigned n,
                      unsigned to_close) {
  if (open_used == n && to_close == 0) {
    buff[buff_i] = '\0';
    printf("%s\n", buff);
    return;
  }
  if (to_close > 0) {
    buff[buff_i] = ')';
    print_parens_aux(buff, buff_i + 1, open_used, n, to_close - 1);
  }
  if (open_used < n) {
    buff[buff_i] = '(';
    print_parens_aux(buff, buff_i + 1, open_used + 1, n, to_close + 1);
  }
}


x86 assembly (clang, -O0):
<print_parens_aux>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    1171 <print_parens_aux+0x51>
cmpl   $0x0,-0x1c(%rbp)
jne    1171 <print_parens_aux+0x51>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rsi
lea    0xe99(%rip),%rdi
call   1040 <printf@plt>
jmp    11e0 <print_parens_aux+0xc0>
cmpl   $0x0,-0x1c(%rbp)
jbe    11a6 <print_parens_aux+0x86>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movb   $0x29,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
sub    $0x1,%r8d
call   1030 <print_parens_aux@plt>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    11e0 <print_parens_aux+0xc0>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movb   $0x28,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
add    $0x1,%r8d
call   1030 <print_parens_aux@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_parens_aux>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,%ebx
mov    %ecx,%r12d
mov    %edx,%ebp
mov    %rsi,0x8(%rsp)
mov    %rdi,0x10(%rsp)
test   %r8d,%r8d
sete   %al
cmp    %ecx,%edx
jne    1152 <print_parens_aux+0x32>
test   %ebx,%ebx
je     11e9 <print_parens_aux+0xc9>
lea    -0x1(%rbx),%ecx
mov    %rcx,0x20(%rsp)
not    %ebx
xor    %r13d,%r13d
mov    %r12d,%r14d
sub    %ebp,%r14d
cmovb  %r13d,%r14d
mov    %ebp,%ecx
mov    %rcx,0x18(%rsp)
not    %ebp
add    %r12d,%ebp
mov    0x10(%rsp),%rcx
mov    0x8(%rsp),%rdx
lea    (%rcx,%rdx,1),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   $0x1,%al
jne    11c5 <print_parens_aux+0xa5>
mov    0x18(%rsp),%rax
lea    (%rax,%r13,1),%rdx
movb   $0x29,(%r15,%r13,1)
mov    0x8(%rsp),%rax
lea    (%rax,%r13,1),%rsi
add    $0x1,%rsi
mov    0x20(%rsp),%rax
lea    (%rax,%r13,1),%r8d
mov    0x10(%rsp),%rdi
mov    %r12d,%ecx
call   1030 <print_parens_aux@plt>
cmp    %r13d,%r14d
je     1211 <print_parens_aux+0xf1>
movb   $0x28,(%r15,%r13,1)
mov    %r13d,%ecx
cmp    %r13d,%ebx
sete   %al
add    $0x1,%r13
cmp    %ecx,%ebp
jne    1190 <print_parens_aux+0x70>
cmp    %ecx,%ebx
jne    1190 <print_parens_aux+0x70>
add    %r13,0x8(%rsp)
mov    0x10(%rsp),%rsi
mov    0x8(%rsp),%rax
movb   $0x0,(%rsi,%rax,1)
lea    0xe02(%rip),%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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