#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*/ free(char *);
int /*<<< orphan*/ generateParentheses(char *, int, int /*<<< orphan*/,
                                       int /*<<< orphan*/, int,
                                       int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
void parentheses(int n1, int n2) {
  if (n1 < 0 || n2 < 0) {
    printf("ERROR: Invalid number of parenthesis.\n");
    return;
  }
  char *str = (char *)malloc(2 * (n1 + n2) * sizeof(char));
  generateParentheses(str, n1, 0, 0, n2, 0, 0);
  free(str);
}


x86 assembly (clang, -O0):
<parentheses>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     1162 <parentheses+0x22>
cmpl   $0x0,-0x8(%rbp)
jge    1173 <parentheses+0x33>
lea    0xe97(%rip),%rdi
call   1040 <printf@plt>
jmp    11b6 <parentheses+0x76>
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
shl    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%edx
mov    %r9d,%ecx
movl   $0x0,(%rsp)
call   1060 <generateParentheses@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parentheses>:
mov    %esi,%eax
or     %edi,%eax
js     118e <parentheses+0x4e>
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %edi,%ebx
lea    (%r14,%rbx,1),%edi
add    %edi,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
movl   $0x0,(%rsp)
mov    %rax,%rdi
mov    %ebx,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r14d,%r8d
xor    %r9d,%r9d
call   1060 <generateParentheses@plt>
mov    %r15,%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>
lea    0xe6b(%rip),%rdi
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [39 x i8] c"ERROR: Invalid number of parenthesis.\0A\00"
define void @parentheses(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8, %2
%12 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %29
13: ; preds = %8
%14 = load i32, i32* %3
%15 = load i32, i32* %4
%16 = add nsw i32 %14, %15
%17 = mul nsw i32 2, %16
%18 = sext i32 %17 to i64
%19 = mul i64 %18, 1
%20 = trunc i64 %19 to i32
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %5
%23 = load i8*, i8** %5
%24 = load i32, i32* %3
%25 = load i32, i32* %4
%26 = call i32 @generateParentheses(i8* %23, i32 %24, i32 0, i32 0, i32 %25, i32 0, i32 0)
%27 = load i8*, i8** %5
%28 = call i32 @free(i8* %27)
br label %29
29: ; preds = %13, %11
ret void
}

LLVM IR (-O2):
@str = [38 x i8] c"ERROR: Invalid number of parenthesis.\00"
define void @parentheses(i32 %0, i32 %1) {
%3 = or i32 %1, %0
%4 = icmp sgt i32 %3, -1
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
br label %14
7: ; preds = %2
%8 = add nsw i32 %1, %0
%9 = shl nsw i32 %8, 1
%10 = tail call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
%12 = tail call i32 @generateParentheses(i8* %11, i32 %0, i32 0, i32 0, i32 %1, i32 0, i32 0)
%13 = tail call i32 @free(i8* %11)
br label %14
14: ; preds = %7, %5
ret void
}