#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 */
scalar_t__ malloc(int);
char *make_space(int width) {
  int i;
  char *copy;
  if ((copy = (char *)malloc(width + 1)) == NULL) {
    return NULL;
  }
  for (i = 0; i < width; i++) {
    copy[i] = ' ';
  }
  copy[width] = '\0';
  return copy;
}


x86 assembly (clang, -O0):
<make_space>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1141 <make_space+0x31>
movq   $0x0,-0x8(%rbp)
jmp    1182 <make_space+0x72>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    116e <make_space+0x5e>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1148 <make_space+0x38>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%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):
<make_space>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
lea    0x1(%r14),%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1156 <make_space+0x36>
mov    %rax,%rbx
test   %r14d,%r14d
jle    114d <make_space+0x2d>
mov    %r14d,%edx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1030 <memset@plt>
movslq %r14d,%rax
movb   $0x0,(%rbx,%rax,1)
jmp    1158 <make_space+0x38>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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