#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);
char *copy_n_pad_message(char *padded_message, char *message, int message_size,
                         int n_padding) {
  int i;
  memcpy(padded_message, message, message_size);
  for (i = message_size; i < message_size + n_padding; ++i) {
    padded_message[i] = n_padding;
  }
  return padded_message;
}


x86 assembly (clang, -O0):
<copy_n_pad_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    -0x18(%rbp),%ecx
cmp    %ecx,%eax
jge    116b <copy_n_pad_message+0x5b>
mov    -0x18(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113c <copy_n_pad_message+0x2c>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_n_pad_message>:
push   %r15
push   %r14
push   %rbx
mov    %ecx,%r15d
mov    %edx,%ebx
mov    %rdi,%r14
call   1040 <memcpy@plt>
test   %r15d,%r15d
jle    115c <copy_n_pad_message+0x3c>
lea    (%r15,%rbx,1),%eax
movslq %ebx,%rdi
add    %r14,%rdi
lea    0x1(%rbx),%ecx
cmp    %ecx,%eax
cmovg  %eax,%ecx
not    %ebx
add    %ecx,%ebx
add    $0x1,%rbx
mov    %r15d,%esi
mov    %rbx,%rdx
call   1030 <memset@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @copy_n_pad_message(i8* returned %0, i8* %1, i32 %2, i32 %3) {
%5 = tail call i32 @memcpy(i8* %0, i8* %1, i32 %2)
%6 = icmp sgt i32 %3, 0
br i1 %6, label %7, label %18
7: ; preds = %4
%8 = add i32 %3, %2
%9 = trunc i32 %3 to i8
%10 = sext i32 %2 to i64
%11 = getelementptr i8, i8* %0, i64 %10
%12 = add i32 %2, 1
%13 = call i32 @llvm.smax.i32(i32 %8, i32 %12)
%14 = xor i32 %2, -1
%15 = add i32 %13, %14
%16 = zext i32 %15 to i64
%17 = add nuw nsw i64 %16, 1
br label %18
18: ; preds = %7, %4
ret i8* %0
}