#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 *);
void *malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char **towerBuilder(int nFloors) {
  char **res = malloc(sizeof(char *) * nFloors);
  int i;
  for (i = 0; i < nFloors; ++i)
    res[i] = malloc(sizeof(char) * (2 * nFloors));
  char *temp = malloc(sizeof(char) * (2 * nFloors));
  for (i = 0; i < nFloors; ++i) {
    memset(temp, ' ', nFloors - i - 1);
    strcat(res[i], temp);
    strcpy(temp, "");
    memset(temp, '*', i * 2 + 1);
    strcat(res[i], temp);
    strcpy(temp, "");
    memset(temp, ' ', nFloors - i - 1);
    strcat(res[i], temp);
    strcpy(temp, "");
  }
  free(temp);
  return res;
}


x86 assembly (clang, -O0):
<towerBuilder>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11b1 <towerBuilder+0x61>
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1175 <towerBuilder+0x25>
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    129d <towerBuilder+0x14d>
mov    -0x20(%rbp),%rdi
mov    -0x4(%rbp),%edx
sub    -0x14(%rbp),%edx
sub    $0x1,%edx
mov    $0x20,%esi
call   1050 <memset@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xdee(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
shl    $0x1,%edx
add    $0x1,%edx
mov    $0x2a,%esi
call   1050 <memset@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xdb2(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x4(%rbp),%edx
sub    -0x14(%rbp),%edx
sub    $0x1,%edx
mov    $0x20,%esi
call   1050 <memset@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xd76(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11cf <towerBuilder+0x7f>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<towerBuilder>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r15d
lea    0x0(,%r15,8),%edi
call   1060 <malloc@plt>
mov    %rax,%r13
lea    (%r15,%r15,1),%ebx
test   %r15d,%r15d
jle    125d <towerBuilder+0x10d>
mov    %r15d,%r14d
xor    %ebp,%ebp
mov    %ebx,%edi
call   1060 <malloc@plt>
mov    %rax,0x0(%r13,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1180 <towerBuilder+0x30>
mov    %ebx,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %r15d,%r15d
jle    1267 <towerBuilder+0x117>
add    $0xffffffff,%r15d
add    %r14,%r14
xor    %r12d,%r12d
mov    %r14,(%rsp)
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x20,%esi
mov    %r15d,%edx
call   1050 <memset@plt>
mov    %r13,%rbp
mov    0x0(%r13,%r12,4),%r13
mov    %r13,%rdi
mov    %rbx,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
lea    0xe13(%rip),%r14
mov    %r14,%rsi
call   1040 <strcpy@plt>
lea    0x1(%r12),%edx
mov    %rbx,%rdi
mov    $0x2a,%esi
call   1050 <memset@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    $0x20,%esi
mov    %r15d,%edx
call   1050 <memset@plt>
mov    %r13,%rdi
mov    %rbp,%r13
mov    %rbx,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    (%rsp),%r14
call   1040 <strcpy@plt>
add    $0x2,%r12
add    $0xffffffff,%r15d
cmp    %r12,%r14
jne    11c0 <towerBuilder+0x70>
jmp    1267 <towerBuilder+0x117>
mov    %ebx,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8** @towerBuilder(i32 %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i8*
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = sext i32 %6 to i64
%8 = mul i64 8, %7
%9 = trunc i64 %8 to i32
%10 = call i8* @malloc(i32 %9)
%11 = bitcast i8* %10 to i8**
store i8** %11, i8*** %3
store i32 0, i32* %4
br label %12
12: ; preds = %27, %1
%13 = load i32, i32* %4
%14 = load i32, i32* %2
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %30
16: ; preds = %12
%17 = load i32, i32* %2
%18 = mul nsw i32 2, %17
%19 = sext i32 %18 to i64
%20 = mul i64 1, %19
%21 = trunc i64 %20 to i32
%22 = call i8* @malloc(i32 %21)
%23 = load i8**, i8*** %3
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
store i8* %22, i8** %26
br label %27
27: ; preds = %16
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %12
30: ; preds = %12
%31 = load i32, i32* %2
%32 = mul nsw i32 2, %31
%33 = sext i32 %32 to i64
%34 = mul i64 1, %33
%35 = trunc i64 %34 to i32
%36 = call i8* @malloc(i32 %35)
store i8* %36, i8** %5
store i32 0, i32* %4
br label %37
37: ; preds = %86, %30
%38 = load i32, i32* %4
%39 = load i32, i32* %2
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %89
41: ; preds = %37
%42 = load i8*, i8** %5
%43 = load i32, i32* %2
%44 = load i32, i32* %4
%45 = sub nsw i32 %43, %44
%46 = sub nsw i32 %45, 1
%47 = call i32 @memset(i8* %42, i8 signext 32, i32 %46)
%48 = load i8**, i8*** %3
%49 = load i32, i32* %4
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
%52 = load i8*, i8** %51
%53 = load i8*, i8** %5
%54 = call i32 @strcat(i8* %52, i8* %53)
%55 = load i8*, i8** %5
%56 = call i32 @strcpy(i8* %55, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%57 = load i8*, i8** %5
%58 = load i32, i32* %4
%59 = mul nsw i32 %58, 2
%60 = add nsw i32 %59, 1
%61 = call i32 @memset(i8* %57, i8 signext 42, i32 %60)
%62 = load i8**, i8*** %3
%63 = load i32, i32* %4
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8*, i8** %62, i64 %64
%66 = load i8*, i8** %65
%67 = load i8*, i8** %5
%68 = call i32 @strcat(i8* %66, i8* %67)
%69 = load i8*, i8** %5
%70 = call i32 @strcpy(i8* %69, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%71 = load i8*, i8** %5
%72 = load i32, i32* %2
%73 = load i32, i32* %4
%74 = sub nsw i32 %72, %73
%75 = sub nsw i32 %74, 1
%76 = call i32 @memset(i8* %71, i8 signext 32, i32 %75)
%77 = load i8**, i8*** %3
%78 = load i32, i32* %4
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8*, i8** %77, i64 %79
%81 = load i8*, i8** %80
%82 = load i8*, i8** %5
%83 = call i32 @strcat(i8* %81, i8* %82)
%84 = load i8*, i8** %5
%85 = call i32 @strcpy(i8* %84, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %86
86: ; preds = %41
%87 = load i32, i32* %4
%88 = add nsw i32 %87, 1
store i32 %88, i32* %4
br label %37
89: ; preds = %37
%90 = load i8*, i8** %5
%91 = call i32 @free(i8* %90)
%92 = load i8**, i8*** %3
ret i8** %92
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define noalias i8** @towerBuilder(i32 %0) {
%2 = shl i32 %0, 3
%3 = tail call i8* @malloc(i32 %2)
%4 = bitcast i8* %3 to i8**
%5 = icmp sgt i32 %0, 0
%6 = shl nsw i32 %0, 1
br i1 %5, label %9, label %7
7: ; preds = %1
%8 = tail call i8* @malloc(i32 %6)
br label %42
9: ; preds = %1
%10 = zext i32 %0 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ 0, %9 ], [ %15, %11 ]
%13 = tail call i8* @malloc(i32 %6)
%14 = getelementptr inbounds i8*, i8** %4, i64 %12
store i8* %13, i8** %14
%15 = add nuw nsw i64 %12, 1
%16 = icmp eq i64 %15, %10
br i1 %16, label %17, label %11
17: ; preds = %11
%18 = tail call i8* @malloc(i32 %6)
br i1 %5, label %19, label %42
19: ; preds = %17
%20 = zext i32 %0 to i64
br label %21
21: ; preds = %19, %21
%22 = phi i64 [ 0, %19 ], [ %40, %21 ]
%23 = trunc i64 %22 to i32
%24 = xor i32 %23, -1
%25 = add i32 %24, %0
%26 = tail call i32 @memset(i8* %18, i8 signext 32, i32 %25)
%27 = getelementptr inbounds i8*, i8** %4, i64 %22
%28 = load i8*, i8** %27
%29 = tail call i32 @strcat(i8* %28, i8* %18)
%30 = tail call i32 @strcpy(i8* %18, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%31 = trunc i64 %22 to i32
%32 = shl i32 %31, 1
%33 = or i32 %32, 1
%34 = tail call i32 @memset(i8* %18, i8 signext 42, i32 %33)
%35 = tail call i32 @strcat(i8* %28, i8* %18)
%36 = tail call i32 @strcpy(i8* %18, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%37 = tail call i32 @memset(i8* %18, i8 signext 32, i32 %25)
%38 = tail call i32 @strcat(i8* %28, i8* %18)
%39 = tail call i32 @strcpy(i8* %18, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%40 = add nuw nsw i64 %22, 1
%41 = icmp eq i64 %40, %20
br i1 %41, label %42, label %21
42: ; preds = %21, %7, %17
%43 = phi i8* [ %8, %7 ], [ %18, %17 ], [ %18, %21 ]
%44 = tail call i32 @free(i8* %43)
ret i8** %4
}