#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 *);
void padto(char *str, int to) {
  int needspace = to - strlen(str);
  str += strlen(str);
  while (needspace > 0)
    *str++ = ' ', needspace--;
  *str = 0;
}


x86 assembly (clang, -O0):
<padto>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    117b <padto+0x6b>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x20,(%rax)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1151 <padto+0x41>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<padto>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
movslq %eax,%rbp
lea    (%r14,%rbp,1),%rdi
cmp    %r15d,%ebx
jge    1166 <padto+0x46>
not    %ebx
add    %r15d,%ebx
lea    0x1(%rbx),%rdx
mov    $0x20,%esi
call   1040 <memset@plt>
add    %rbx,%rbp
lea    (%r14,%rbp,1),%rdi
add    $0x1,%rdi
movb   $0x0,(%rdi)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @padto(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 i32, i32* %4
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
%9 = sub nsw i32 %6, %8
store i32 %9, i32* %5
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
%12 = load i8*, i8** %3
%13 = sext i32 %11 to i64
%14 = getelementptr inbounds i8, i8* %12, i64 %13
store i8* %14, i8** %3
br label %15
15: ; preds = %18, %2
%16 = load i32, i32* %5
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %3
store i8 32, i8* %19
%21 = load i32, i32* %5
%22 = add nsw i32 %21, -1
store i32 %22, i32* %5
br label %15
23: ; preds = %15
%24 = load i8*, i8** %3
store i8 0, i8* %24
ret void
}

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