#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);
char *strcpy(char *, char *);
int strlen(char *);
char *extend_str_space(char *string, int extend_by) {
  char *ext;
  int len, i;
  len = strlen(string) + 1;
  ext = malloc((len + extend_by) * sizeof(char));
  if (!ext)
    return NULL;
  ext = strcpy(ext, string);
  for (i = len - 1; i < len + extend_by - 1; i++) {
    ext[i] = ' ';
  }
  ext[len + extend_by - 1] = '\0';
  return ext;
}


x86 assembly (clang, -O0):
<extend_str_space>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    -0x14(%rbp),%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117d <extend_str_space+0x4d>
movq   $0x0,-0x8(%rbp)
jmp    11e1 <extend_str_space+0xb1>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x24(%rbp),%ecx
add    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11c5 <extend_str_space+0x95>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1197 <extend_str_space+0x67>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extend_str_space>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %eax,%r15d
lea    (%r15,%r14,1),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11a3 <extend_str_space+0x63>
lea    (%r15,%r14,1),%ebp
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
cmp    %ebp,%r15d
jge    119c <extend_str_space+0x5c>
movslq %r15d,%rax
mov    %rbx,%rdi
add    %rax,%rdi
add    $0xffffffff,%r14d
add    $0x1,%r14
mov    $0x20,%esi
mov    %r14,%rdx
call   1050 <memset@plt>
movslq %ebp,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @extend_str_space(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = add nsw i32 %10, 1
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = load i32, i32* %5
%14 = add nsw i32 %12, %13
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 1
%17 = trunc i64 %16 to i32
%18 = call i8* @malloc(i32 %17)
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %2
store i8* null, i8** %3
br label %52
22: ; preds = %2
%23 = load i8*, i8** %6
%24 = load i8*, i8** %4
%25 = call i8* @strcpy(i8* %23, i8* %24)
store i8* %25, i8** %6
%26 = load i32, i32* %7
%27 = sub nsw i32 %26, 1
store i32 %27, i32* %8
br label %28
28: ; preds = %40, %22
%29 = load i32, i32* %8
%30 = load i32, i32* %7
%31 = load i32, i32* %5
%32 = add nsw i32 %30, %31
%33 = sub nsw i32 %32, 1
%34 = icmp slt i32 %29, %33
br i1 %34, label %35, label %43
35: ; preds = %28
%36 = load i8*, i8** %6
%37 = load i32, i32* %8
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 32, i8* %39
br label %40
40: ; preds = %35
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %28
43: ; preds = %28
%44 = load i8*, i8** %6
%45 = load i32, i32* %7
%46 = load i32, i32* %5
%47 = add nsw i32 %45, %46
%48 = sub nsw i32 %47, 1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %44, i64 %49
store i8 0, i8* %50
%51 = load i8*, i8** %6
store i8* %51, i8** %3
br label %52
52: ; preds = %43, %21
%53 = load i8*, i8** %3
ret i8* %53
}

LLVM IR (-O2):
define i8* @extend_str_space(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add i32 %3, %1
%5 = add i32 %4, 1
%6 = tail call i8* @malloc(i32 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %20, label %8
8: ; preds = %2
%9 = tail call i8* @strcpy(i8* %6, i8* dereferenceable(1) %0)
%10 = icmp slt i32 %3, %4
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = sext i32 %3 to i64
%13 = getelementptr i8, i8* %6, i64 %12
%14 = add i32 %1, -1
%15 = zext i32 %14 to i64
%16 = add nuw nsw i64 %15, 1
br label %17
17: ; preds = %11, %8
%18 = sext i32 %4 to i64
%19 = getelementptr inbounds i8, i8* %6, i64 %18
store i8 0, i8* %19
br label %20
20: ; preds = %2, %17
ret i8* %6
}