#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*/ foo(int, int, char **, char *, int, int);
scalar_t__ malloc(int);
char **generateParentheses(int n, int *returnSize) {
  char **res = NULL;
  char stack[2 * n];
  int top = 0;
  res = (char **)malloc(sizeof(char *) * 128);
  for (int i = 0; i < 128; i++) {
    res[i] = (char *)malloc(sizeof(char) * (n * 2 + 1));
  }
  *returnSize = 0;
  foo(n, n, res, stack, n, top);
  return res;
}


x86 assembly (clang, -O0):
<generateParentheses>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%eax
add    %eax,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    $0x400,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x80,-0x30(%rbp)
jge    11bb <generateParentheses+0x9b>
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    117b <generateParentheses+0x5b>
mov    -0x38(%rbp),%rcx
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x4(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
call   1040 <foo@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generateParentheses>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,-0x30(%rbp)
mov    %edi,%r12d
lea    (%r12,%r12,1),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    $0x400,%edi
call   1030 <malloc@plt>
mov    %rax,%r13
lea    (%r12,%r12,1),%ebx
add    $0x1,%ebx
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1030 <malloc@plt>
mov    %rax,0x0(%r13,%r14,8)
add    $0x1,%r14
cmp    $0x80,%r14
jne    1170 <generateParentheses+0x50>
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
mov    %r12d,%edi
mov    %r12d,%esi
mov    %r13,%rdx
mov    %r15,%rcx
mov    %r12d,%r8d
xor    %r9d,%r9d
call   1040 <foo@plt>
mov    %r13,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8** @generateParentheses(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
store i8** null, i8*** %5
%10 = load i32, i32* %3
%11 = mul nsw i32 2, %10
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %6
%14 = alloca i8, i64 %12
store i64 %12, i64* %7
store i32 0, i32* %8
%15 = call i64 @malloc(i32 1024)
%16 = inttoptr i64 %15 to i8**
store i8** %16, i8*** %5
store i32 0, i32* %9
br label %17
17: ; preds = %33, %2
%18 = load i32, i32* %9
%19 = icmp slt i32 %18, 128
br i1 %19, label %20, label %36
20: ; preds = %17
%21 = load i32, i32* %3
%22 = mul nsw i32 %21, 2
%23 = add nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = mul i64 1, %24
%26 = trunc i64 %25 to i32
%27 = call i64 @malloc(i32 %26)
%28 = inttoptr i64 %27 to i8*
%29 = load i8**, i8*** %5
%30 = load i32, i32* %9
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
store i8* %28, i8** %32
br label %33
33: ; preds = %20
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 1
store i32 %35, i32* %9
br label %17
36: ; preds = %17
%37 = load i32*, i32** %4
store i32 0, i32* %37
%38 = load i32, i32* %3
%39 = load i32, i32* %3
%40 = load i8**, i8*** %5
%41 = load i32, i32* %3
%42 = load i32, i32* %8
%43 = call i32 @foo(i32 %38, i32 %39, i8** %40, i8* %14, i32 %41, i32 %42)
%44 = load i8**, i8*** %5
%45 = load i8*, i8** %6
ret i8** %44
}

LLVM IR (-O2):
define i8** @generateParentheses(i32 %0, i32* nocapture writeonly %1) {
%3 = shl nsw i32 %0, 1
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = tail call i64 @malloc(i32 1024)
%7 = inttoptr i64 %6 to i8**
%8 = or i32 %3, 1
br label %11
9: ; preds = %11
store i32 0, i32* %1
%10 = call i32 @foo(i32 %0, i32 %0, i8** %7, i8* %5, i32 %0, i32 0)
ret i8** %7
11: ; preds = %2, %11
%12 = phi i64 [ 0, %2 ], [ %16, %11 ]
%13 = tail call i64 @malloc(i32 %8)
%14 = inttoptr i64 %13 to i8*
%15 = getelementptr inbounds i8*, i8** %7, i64 %12
store i8* %14, i8** %15
%16 = add nuw nsw i64 %12, 1
%17 = icmp eq i64 %16, 128
br i1 %17, label %9, label %11
}