#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*/ memcpy(char *, char *, int);
int strlen(char *);
char *write(char *, char);
char *rpad(char *out, char *in, int size, char pad_char) {
  int n = strlen(in);
  for (int i = 0; i < size - n; i++) {
    out = write(out, pad_char);
  }
  memcpy(out, in, n);
  return out + n;
}


x86 assembly (clang, -O0):
<rpad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %cl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %al,-0x15(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
cmp    %ecx,%eax
jge    118b <rpad+0x5b>
mov    -0x8(%rbp),%rdi
movsbl -0x15(%rbp),%esi
call   1030 <write@plt>
mov    %rax,-0x8(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    115b <rpad+0x2b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rpad>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r12d
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
sub    %eax,%ebp
test   %ebp,%ebp
jle    1173 <rpad+0x43>
movsbl %r12b,%r12d
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r12d,%esi
call   1030 <write@plt>
mov    %rax,%rbx
add    $0xffffffff,%ebp
jne    1160 <rpad+0x30>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1050 <memcpy@plt>
movslq %r15d,%rax
add    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @rpad(i8* %0, i8* %1, i32 %2, i8 signext %3) {
%5 = tail call i32 @strlen(i8* %1)
%6 = sub i32 %2, %5
%7 = icmp sgt i32 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %13, %4
%9 = phi i8* [ %0, %4 ], [ %16, %13 ]
%10 = tail call i32 @memcpy(i8* %9, i8* %1, i32 %5)
%11 = sext i32 %5 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
ret i8* %12
13: ; preds = %4, %13
%14 = phi i32 [ %17, %13 ], [ 0, %4 ]
%15 = phi i8* [ %16, %13 ], [ %0, %4 ]
%16 = tail call i8* @write(i8* %15, i8 signext %3)
%17 = add nuw nsw i32 %14, 1
%18 = icmp eq i32 %17, %6
br i1 %18, label %8, label %13
}