#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ padit(unsigned char **, int, unsigned char *, int);
int /*<<< orphan*/ printf(char *, char *);
char *tohex(unsigned char *, int);
int main() {
  unsigned char *memory;
  memory = (unsigned char *)calloc(5, 1);
  unsigned char pad[] = {0x02, 0x03, 0x04};
  padit(&memory, 5, pad, 3);
  char *hex = tohex(memory, 5);
  printf("String: \"%s\"\n", hex);
  free(hex);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x5,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x8(%rbp)
mov    0xe8e(%rip),%ax
mov    %ax,-0xb(%rbp)
mov    0xe86(%rip),%al
mov    %al,-0x9(%rbp)
lea    -0xb(%rbp),%rdx
lea    -0x8(%rbp),%rdi
mov    $0x5,%esi
mov    $0x3,%ecx
call   1060 <padit@plt>
mov    -0x8(%rbp),%rdi
mov    $0x5,%esi
call   1070 <tohex@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe50(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    $0x5,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,0x8(%rsp)
movb   $0x4,0x6(%rsp)
movw   $0x302,0x4(%rsp)
lea    0x8(%rsp),%rdi
lea    0x4(%rsp),%rdx
mov    $0x5,%esi
mov    $0x3,%ecx
call   1060 <padit@plt>
mov    0x8(%rsp),%rdi
mov    $0x5,%esi
call   1070 <tohex@plt>
mov    %rax,%rbx
lea    0xe5c(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.pad = [3 x i8] c"\02\03\04"
@.str = [14 x i8] c"String: \22%s\22\0A\00"
define i32 @main() {
%1 = alloca i8*
%2 = alloca [3 x i8]
%3 = alloca i8*
%4 = call i64 @calloc(i32 5, i32 1)
%5 = inttoptr i64 %4 to i8*
store i8* %5, i8** %1
%6 = bitcast [3 x i8]* %2 to i8*
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%8 = call i32 @padit(i8** %1, i32 5, i8* %7, i32 3)
%9 = load i8*, i8** %1
%10 = call i8* @tohex(i8* %9, i32 5)
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i8*, i8** %3
%14 = call i32 @free(i8* %13)
ret i32 0
}

LLVM IR (-O2):
@__const.main.pad = [3 x i8] c"\02\03\04"
@.str = [14 x i8] c"String: \22%s\22\0A\00"
define i32 @main() {
%1 = alloca i8*
%2 = alloca [3 x i8]
%3 = bitcast i8** %1 to i8*
%4 = tail call i64 @calloc(i32 5, i32 1)
%5 = inttoptr i64 %4 to i8*
store i8* %5, i8** %1
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%7 = call i32 @padit(i8** %1, i32 5, i8* %6, i32 3)
%8 = load i8*, i8** %1
%9 = call i8* @tohex(i8* %8, i32 5)
%10 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = call i32 @free(i8* %9)
ret i32 0
}