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


x86 assembly (clang, -O0):
<parentheses>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1166 <parentheses+0x26>
lea    0xea4(%rip),%rdi
call   1040 <printf@plt>
jmp    1196 <parentheses+0x56>
mov    -0x4(%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
xor    %ecx,%ecx
mov    %ecx,%edx
call   1060 <generateParentheses@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parentheses>:
test   %edi,%edi
js     1172 <parentheses+0x32>
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    (%rbx,%rbx,1),%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %ebx,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <generateParentheses@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>
lea    0xe87(%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) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %21
8: ; preds = %1
%9 = load i32, i32* %2
%10 = mul nsw i32 2, %9
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 1
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %3
%16 = load i8*, i8** %3
%17 = load i32, i32* %2
%18 = call i32 @generateParentheses(i8* %16, i32 %17, i32 0, i32 0)
%19 = load i8*, i8** %3
%20 = call i32 @free(i8* %19)
br label %21
21: ; preds = %8, %6
ret void
}

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