#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 strlen(char *);
char *pad_string(char *string_to_pad, int pad_width) {
  char *padding = "                                " +
                  strlen("                                ");
  if ((pad_width <= strlen("                                ")) &&
      (strlen(string_to_pad) < pad_width)) {
    padding = padding - pad_width + strlen(string_to_pad);
  }
  return (padding);
}


x86 assembly (clang, -O0):
<pad_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeda(%rip),%rdi
call   1030 <strlen@plt>
movslq %eax,%rcx
lea    0xecb(%rip),%rax
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    0xeb7(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jg     119a <pad_string+0x8a>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    -0xc(%rbp),%eax
jge    119a <pad_string+0x8a>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rdx
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pad_string>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
lea    0xedc(%rip),%rbp
mov    %rbp,%rdi
call   1030 <strlen@plt>
movslq %eax,%rbx
add    %rbp,%rbx
mov    %rbp,%rdi
call   1030 <strlen@plt>
cmp    %r15d,%eax
jl     115f <pad_string+0x4f>
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    %r15d,%eax
jge    115f <pad_string+0x4f>
movslq %r15d,%rax
sub    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c" \00"
define i8* @pad_string(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = call i32 @strlen(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i64 %7
store i8* %8, i8** %5
%9 = load i32, i32* %4
%10 = call i32 @strlen(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%11 = icmp sle i32 %9, %10
br i1 %11, label %12, label %27
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = call i32 @strlen(i8* %13)
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %27
17: ; preds = %12
%18 = load i8*, i8** %5
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = sub i64 0, %20
%22 = getelementptr inbounds i8, i8* %18, i64 %21
%23 = load i8*, i8** %3
%24 = call i32 @strlen(i8* %23)
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
store i8* %26, i8** %5
br label %27
27: ; preds = %17, %12, %2
%28 = load i8*, i8** %5
ret i8* %28
}

LLVM IR (-O2):
@.str = [33 x i8] c" \00"
define i8* @pad_string(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds [33 x i8], [33 x i8]* @.str, i64 0, i64 %4
%6 = tail call i32 @strlen(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%7 = icmp slt i32 %6, %1
br i1 %7, label %18, label %8
8: ; preds = %2
%9 = tail call i32 @strlen(i8* %0)
%10 = icmp slt i32 %9, %1
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = sext i32 %1 to i64
%13 = sub nsw i64 0, %12
%14 = getelementptr inbounds i8, i8* %5, i64 %13
%15 = tail call i32 @strlen(i8* %0)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
br label %18
18: ; preds = %11, %8, %2
%19 = phi i8* [ %17, %11 ], [ %5, %8 ], [ %5, %2 ]
ret i8* %19
}