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


x86 assembly (clang, -O0):
<str_fill_spaces_right>:
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_right+0x3d>
xor    %eax,%eax
mov    %eax,-0x20(%rbp)
jmp    1173 <str_fill_spaces_right+0x43>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
cmpl   $0x0,-0x1c(%rbp)
je     11af <str_fill_spaces_right+0x7f>
mov    -0x8(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
movslq -0x1c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edx
mov    $0x20,%esi
call   1050 <memset@plt>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
add    %rcx,%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_fill_spaces_right>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%rbp
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
sub    %eax,%ebx
mov    %r14,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
xor    %ebp,%ebp
movslq %r15d,%r15
test   %ebx,%ebx
cmovns %ebx,%ebp
jle    1173 <str_fill_spaces_right+0x43>
lea    (%r14,%r15,1),%rdi
mov    $0x20,%esi
mov    %ebp,%edx
call   1050 <memset@plt>
add    %r15,%r14
mov    %ebp,%eax
movb   $0x0,(%rax,%r14,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @str_fill_spaces_right(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 i8*, i8** %4
%22 = load i8*, i8** %5
%23 = call i32 @strcpy(i8* %21, i8* %22)
%24 = load i32, i32* %8
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %36
26: ; preds = %19
%27 = load i8*, i8** %4
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = mul i64 1, %32
%34 = trunc i64 %33 to i32
%35 = call i32 @memset(i8* %30, i8 signext 32, i32 %34)
br label %36
36: ; preds = %26, %19
%37 = load i8*, i8** %4
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
store i8 0, i8* %43
ret void
}

LLVM IR (-O2):
define void @str_fill_spaces_right(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
%8 = tail call i32 @strcpy(i8* %0, i8* %1)
%9 = sext i32 %4 to i64
br i1 %6, label %10, label %13
10: ; preds = %3
%11 = getelementptr inbounds i8, i8* %0, i64 %9
%12 = tail call i32 @memset(i8* %11, i8 signext 32, i32 %7)
br label %13
13: ; preds = %3, %10
%14 = getelementptr inbounds i8, i8* %0, i64 %9
%15 = zext i32 %7 to i64
%16 = getelementptr inbounds i8, i8* %14, i64 %15
store i8 0, i8* %16
ret void
}