#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*/ traverse(char ***, int *, char *, int, int, int);
char **generateParenthesis(int n, int *returnSize) {
  if (!n)
    return NULL;
  char **arr = (char **)malloc(sizeof(char *));
  *returnSize = 0;
  char *stack = (char *)malloc(sizeof(char) * 2 * n);
  int top = -1;
  int leftCount = n;
  int rightCount = n;
  traverse(&arr, returnSize, stack, top, leftCount, rightCount);
  return arr;
}


x86 assembly (clang, -O0):
<generateParenthesis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1146 <generateParenthesis+0x26>
movq   $0x0,-0x8(%rbp)
jmp    11a8 <generateParenthesis+0x88>
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
movslq -0xc(%rbp),%rax
shl    $0x1,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
mov    -0x30(%rbp),%r8d
mov    -0x34(%rbp),%r9d
lea    -0x20(%rbp),%rdi
call   1030 <traverse@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generateParenthesis>:
test   %edi,%edi
je     116f <generateParenthesis+0x4f>
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,(%rsp)
movl   $0x0,(%r14)
lea    (%rbx,%rbx,1),%edi
call   1040 <malloc@plt>
mov    %rsp,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
mov    $0xffffffff,%ecx
mov    %ebx,%r8d
mov    %ebx,%r9d
call   1030 <traverse@plt>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i8** @generateParenthesis(i32 %0, i32* %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %2
store i8** null, i8*** %3
br label %33
14: ; preds = %2
%15 = call i64 @malloc(i32 8)
%16 = inttoptr i64 %15 to i8**
store i8** %16, i8*** %6
%17 = load i32*, i32** %5
store i32 0, i32* %17
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = mul i64 2, %19
%21 = trunc i64 %20 to i32
%22 = call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %7
store i32 -1, i32* %8
%24 = load i32, i32* %4
store i32 %24, i32* %9
%25 = load i32, i32* %4
store i32 %25, i32* %10
%26 = load i32*, i32** %5
%27 = load i8*, i8** %7
%28 = load i32, i32* %8
%29 = load i32, i32* %9
%30 = load i32, i32* %10
%31 = call i32 @traverse(i8*** %6, i32* %26, i8* %27, i32 %28, i32 %29, i32 %30)
%32 = load i8**, i8*** %6
store i8** %32, i8*** %3
br label %33
33: ; preds = %14, %13
%34 = load i8**, i8*** %3
ret i8** %34
}

LLVM IR (-O2):
define i8** @generateParenthesis(i32 %0, i32* %1) {
%3 = alloca i8**
%4 = icmp eq i32 %0, 0
br i1 %4, label %14, label %5
5: ; preds = %2
%6 = bitcast i8*** %3 to i8*
%7 = tail call i64 @malloc(i32 8)
%8 = inttoptr i64 %7 to i8**
store i8** %8, i8*** %3
store i32 0, i32* %1
%9 = shl i32 %0, 1
%10 = tail call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
%12 = call i32 @traverse(i8*** %3, i32* %1, i8* %11, i32 -1, i32 %0, i32 %0)
%13 = load i8**, i8*** %3
br label %14
14: ; preds = %2, %5
%15 = phi i8** [ %13, %5 ], [ null, %2 ]
ret i8** %15
}