#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 padBuffer(char *buf, unsigned int len) {
  if (strlen(buf) < len) {
    for (unsigned int j = strlen(buf); j < len; j++)
      buf[j] = ' ';
  }
  buf[len] = '\0';
  return;
}


x86 assembly (clang, -O0):
<padBuffer>:
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
jae    1167 <padBuffer+0x57>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1162 <padBuffer+0x52>
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    113d <padBuffer+0x2d>
jmp    1167 <padBuffer+0x57>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<padBuffer>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmp    %ebp,%eax
jae    1157 <padBuffer+0x37>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %ebp,%eax
jae    1157 <padBuffer+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 @padBuffer(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 ult i32 %7, %8
br i1 %9, label %10, label %26
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %5
br label %13
13: ; preds = %22, %10
%14 = load i32, i32* %5
%15 = load i32, i32* %4
%16 = icmp ult i32 %14, %15
br i1 %16, label %17, label %25
17: ; preds = %13
%18 = load i8*, i8** %3
%19 = load i32, i32* %5
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
store i8 32, i8* %21
br label %22
22: ; preds = %17
%23 = load i32, i32* %5
%24 = add i32 %23, 1
store i32 %24, i32* %5
br label %13
25: ; preds = %13
br label %26
26: ; preds = %25, %2
%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
ret void
}

LLVM IR (-O2):
define void @padBuffer(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp ult i32 %3, %1
br i1 %4, label %5, label %15
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, %2
%16 = zext i32 %1 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
store i8 0, i8* %17
ret void
}