#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 */
unsigned int strlen(char *);
void fill_space(char *str, unsigned int n) {
  unsigned int i;
  if (strlen(str) >= n)
    return;
  for (i = strlen(str); i < n; i++) {
    str[i] = ' ';
  }
  str[n] = '\0';
}


x86 assembly (clang, -O0):
<fill_space>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    -0xc(%rbp),%eax
jb     1136 <fill_space+0x26>
jmp    1172 <fill_space+0x62>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1167 <fill_space+0x57>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
movb   $0x20,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1142 <fill_space+0x32>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_space>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmp    %ebp,%eax
jae    115d <fill_space+0x3d>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %ebp,%eax
jae    1157 <fill_space+0x37>
mov    %eax,%edi
add    %rbx,%rdi
not    %eax
add    %ebp,%eax
add    $0x1,%rax
mov    $0x20,%esi
mov    %rax,%rdx
call   1040 <memset@plt>
mov    %ebp,%eax
movb   $0x0,(%rbx,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define void @fill_space(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp ult i32 %3, %1
br i1 %4, label %5, label %18
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp ult i32 %6, %1
br i1 %7, label %8, label %15
8: ; preds = %5
%9 = zext i32 %6 to i64
%10 = getelementptr i8, i8* %0, i64 %9
%11 = xor i32 %6, -1
%12 = add i32 %11, %1
%13 = zext i32 %12 to i64
%14 = add nuw nsw i64 %13, 1
br label %15
15: ; preds = %8, %5
%16 = zext i32 %1 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
store i8 0, i8* %17
br label %18
18: ; preds = %2, %15
ret void
}