#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*/ memset(char *, char, int);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
void str_fill_spaces_left(char *dest, const char *str, int n) {
  int len = strlen(str);
  int toFill = n - len;
  toFill = ((0) > (toFill) ? (0) : (toFill));
  if (toFill)
    memset(dest, ' ', sizeof(char) * toFill);
  strcpy(dest + toFill, str);
}


x86 assembly (clang, -O0):
<str_fill_spaces_left>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmp    -0x1c(%rbp),%eax
jle    116d <str_fill_spaces_left+0x3d>
xor    %eax,%eax
mov    %eax,-0x20(%rbp)
jmp    1173 <str_fill_spaces_left+0x43>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     119b <str_fill_spaces_left+0x6b>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edx
mov    $0x20,%esi
call   1050 <memset@plt>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_fill_spaces_left>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebx
xor    %ebp,%ebp
test   %ebx,%ebx
cmovns %ebx,%ebp
jle    1161 <str_fill_spaces_left+0x31>
mov    %r15,%rdi
mov    $0x20,%esi
mov    %ebp,%edx
call   1050 <memset@plt>
mov    %ebp,%eax
add    %rax,%r15
mov    %r15,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
define void @str_fill_spaces_left(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %7
%11 = load i32, i32* %6
%12 = load i32, i32* %7
%13 = sub nsw i32 %11, %12
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = icmp sgt i32 0, %14
br i1 %15, label %16, label %17
16: ; preds = %3
br label %19
17: ; preds = %3
%18 = load i32, i32* %8
br label %19
19: ; preds = %17, %16
%20 = phi i32 [ 0, %16 ], [ %18, %17 ]
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %19
%24 = load i8*, i8** %4
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = mul i64 1, %26
%28 = trunc i64 %27 to i32
%29 = call i32 @memset(i8* %24, i8 signext 32, i32 %28)
br label %30
30: ; preds = %23, %19
%31 = load i8*, i8** %4
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8*, i8** %5
%36 = call i32 @strcpy(i8* %34, i8* %35)
ret void
}

LLVM IR (-O2):
define void @str_fill_spaces_left(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %1)
%5 = sub nsw i32 %2, %4
%6 = icmp sgt i32 %5, 0
%7 = select i1 %6, i32 %5, i32 0
br i1 %6, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @memset(i8* %0, i8 signext 32, i32 %7)
br label %10
10: ; preds = %8, %3
%11 = zext i32 %7 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = tail call i32 @strcpy(i8* %12, i8* %1)
ret void
}