#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
scalar_t__ pow(double, double);
int /*<<< orphan*/ recur(int, int /*<<< orphan*/, char *, char **, int *);
char **generateParenthesis(int n, int *returnSize) {
  int MAX_N = (int)pow(2.0, (double)(2 * n));
  char **ans = (char **)malloc(sizeof(char *) * MAX_N);
  int i = 0;
  for (i = 0; i < MAX_N; ++i) {
    ans[i] = (char *)malloc(sizeof(char) * (2 * n + 2));
    memset(ans[i], '\0', (2 * n + 2));
  }
  *returnSize = 0;
  char *s = (char *)malloc(sizeof(char) * (2 * n + 2));
  memset(s, '\0', 2 * n + 2);
  recur(n, 0, s, ans, returnSize);
  return ans;
}


x86 assembly (clang, -O0):
<generateParenthesis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe9f(%rip),%xmm0
call   1060 <pow@plt>
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e5 <generateParenthesis+0xa5>
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x4(%rbp),%edx
shl    $0x1,%edx
add    $0x2,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118a <generateParenthesis+0x4a>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x4(%rbp),%edx
shl    $0x1,%edx
add    $0x2,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x4(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%r8
xor    %esi,%esi
call   1030 <recur@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generateParenthesis>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
lea    (%r15,%r15,1),%eax
cvtsi2sd %eax,%xmm1
movsd  0xe9f(%rip),%xmm0
call   1060 <pow@plt>
mov    %rax,%r12
lea    0x0(,%rax,8),%edi
call   1050 <malloc@plt>
mov    %rax,%r13
lea    (%r15,%r15,1),%ebp
add    $0x2,%ebp
test   %r12d,%r12d
jle    11b1 <generateParenthesis+0x71>
mov    %r12d,%r12d
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,0x0(%r13,%rbx,8)
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1040 <memset@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1190 <generateParenthesis+0x50>
movl   $0x0,(%r14)
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1040 <memset@plt>
mov    %r15d,%edi
xor    %esi,%esi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %r14,%r8
call   1030 <recur@plt>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8** @generateParenthesis(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i8*
store i32 %0, i32* %3
store i32* %1, i32** %4
%9 = load i32, i32* %3
%10 = mul nsw i32 2, %9
%11 = sitofp i32 %10 to double
%12 = call i64 @pow(double 2.000000e+00, double %11)
%13 = trunc i64 %12 to i32
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = mul i64 8, %15
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8**
store i8** %19, i8*** %6
store i32 0, i32* %7
store i32 0, i32* %7
br label %20
20: ; preds = %46, %2
%21 = load i32, i32* %7
%22 = load i32, i32* %5
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %49
24: ; preds = %20
%25 = load i32, i32* %3
%26 = mul nsw i32 2, %25
%27 = add nsw i32 %26, 2
%28 = sext i32 %27 to i64
%29 = mul i64 1, %28
%30 = trunc i64 %29 to i32
%31 = call i64 @malloc(i32 %30)
%32 = inttoptr i64 %31 to i8*
%33 = load i8**, i8*** %6
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
store i8* %32, i8** %36
%37 = load i8**, i8*** %6
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
%41 = load i8*, i8** %40
%42 = load i32, i32* %3
%43 = mul nsw i32 2, %42
%44 = add nsw i32 %43, 2
%45 = call i32 @memset(i8* %41, i8 signext 0, i32 %44)
br label %46
46: ; preds = %24
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %20
49: ; preds = %20
%50 = load i32*, i32** %4
store i32 0, i32* %50
%51 = load i32, i32* %3
%52 = mul nsw i32 2, %51
%53 = add nsw i32 %52, 2
%54 = sext i32 %53 to i64
%55 = mul i64 1, %54
%56 = trunc i64 %55 to i32
%57 = call i64 @malloc(i32 %56)
%58 = inttoptr i64 %57 to i8*
store i8* %58, i8** %8
%59 = load i8*, i8** %8
%60 = load i32, i32* %3
%61 = mul nsw i32 2, %60
%62 = add nsw i32 %61, 2
%63 = call i32 @memset(i8* %59, i8 signext 0, i32 %62)
%64 = load i32, i32* %3
%65 = load i8*, i8** %8
%66 = load i8**, i8*** %6
%67 = load i32*, i32** %4
%68 = call i32 @recur(i32 %64, i32 0, i8* %65, i8** %66, i32* %67)
%69 = load i8**, i8*** %6
ret i8** %69
}

LLVM IR (-O2):
define i8** @generateParenthesis(i32 %0, i32* %1) {
%3 = shl nsw i32 %0, 1
%4 = sitofp i32 %3 to double
%5 = tail call i64 @pow(double 2.000000e+00, double %4)
%6 = trunc i64 %5 to i32
%7 = shl i32 %6, 3
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8**
%10 = icmp sgt i32 %6, 0
%11 = add nsw i32 %3, 2
br i1 %10, label %12, label %22
12: ; preds = %2
%13 = and i64 %5, 4294967295
br label %14
14: ; preds = %12, %14
%15 = phi i64 [ 0, %12 ], [ %20, %14 ]
%16 = tail call i64 @malloc(i32 %11)
%17 = inttoptr i64 %16 to i8*
%18 = getelementptr inbounds i8*, i8** %9, i64 %15
store i8* %17, i8** %18
%19 = tail call i32 @memset(i8* %17, i8 signext 0, i32 %11)
%20 = add nuw nsw i64 %15, 1
%21 = icmp eq i64 %20, %13
br i1 %21, label %22, label %14
22: ; preds = %14, %2
store i32 0, i32* %1
%23 = tail call i64 @malloc(i32 %11)
%24 = inttoptr i64 %23 to i8*
%25 = tail call i32 @memset(i8* %24, i8 signext 0, i32 %11)
%26 = tail call i32 @recur(i32 %0, i32 0, i8* %24, i8** %9, i32* %1)
ret i8** %9
}