#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 */
char *malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
char *generate_padding(int depth) {
  if (depth == 0)
    return NULL;
  char *re = malloc((3 * depth + 1) * sizeof(char));
  memset(re, ' ', 3 * depth * sizeof(char));
  re[3 * depth] = '\0';
  return re;
}


x86 assembly (clang, -O0):
<generate_padding>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1142 <generate_padding+0x22>
movq   $0x0,-0x8(%rbp)
jmp    118b <generate_padding+0x6b>
imul   $0x3,-0xc(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
imul   $0x3,-0xc(%rbp),%eax
cltq
shl    $0x0,%rax
mov    %eax,%edx
mov    $0x20,%esi
call   1030 <memset@plt>
mov    -0x18(%rbp),%rax
imul   $0x3,-0xc(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_padding>:
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
je     1152 <generate_padding+0x32>
movslq %edi,%rax
lea    (%rax,%rax,2),%r14
lea    0x1(%r14),%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x20,%esi
mov    %r14d,%edx
call   1030 <memset@plt>
movb   $0x0,(%rbx,%r14,1)
jmp    1154 <generate_padding+0x34>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i8* @generate_padding(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %10, label %3
3: ; preds = %1
%4 = mul nsw i32 %0, 3
%5 = add nsw i32 %4, 1
%6 = tail call i8* @malloc(i32 %5)
%7 = sext i32 %4 to i64
%8 = tail call i32 @memset(i8* %6, i8 signext 32, i32 %4)
%9 = getelementptr inbounds i8, i8* %6, i64 %7
store i8 0, i8* %9
br label %10
10: ; preds = %1, %3
%11 = phi i8* [ %6, %3 ], [ null, %1 ]
ret i8* %11
}