#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 *, int, int);
int /*<<< orphan*/ strlcpy(char *, char *, int);
int strlen(char *);
void copy_right_padded(char *dst, char *src, int size_of_dst) {
  strlcpy(dst, src, size_of_dst);
  if (strlen(src) < size_of_dst) {
    memset(dst + strlen(src), 32, size_of_dst - strlen(src));
  }
}


x86 assembly (clang, -O0):
<copy_right_padded>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <strlcpy@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    -0x14(%rbp),%eax
jge    11a8 <copy_right_padded+0x78>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rdi
sub    %eax,%edx
mov    $0x20,%esi
call   1040 <memset@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_right_padded>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
call   1050 <strlcpy@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %ebp,%eax
jge    1177 <copy_right_padded+0x47>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%r14
mov    %rbx,%rdi
call   1030 <strlen@plt>
sub    %eax,%ebp
mov    %r14,%rdi
mov    $0x20,%esi
mov    %ebp,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <memset@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define void @copy_right_padded(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlcpy(i8* %0, i8* %1, i32 %2)
%5 = tail call i32 @strlen(i8* %1)
%6 = icmp slt i32 %5, %2
br i1 %6, label %7, label %14
7: ; preds = %3
%8 = tail call i32 @strlen(i8* %1)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = tail call i32 @strlen(i8* %1)
%12 = sub nsw i32 %2, %11
%13 = tail call i32 @memset(i8* %10, i32 32, i32 %12)
br label %14
14: ; preds = %7, %3
ret void
}