#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*/ memmove(char *, char *, size_t);
int /*<<< orphan*/ memset(char *, char, size_t);
char *realloc(char *, size_t);
char *pad_front(char *string, char padding, size_t old_length,
                size_t new_length) {
  char *result = realloc(string, new_length);
  memmove(result + new_length - old_length, result, old_length);
  memset(result, padding, new_length - old_length);
  return result;
}


x86 assembly (clang, -O0):
<pad_front>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
add    -0x20(%rbp),%rdi
xor    %eax,%eax
sub    -0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <memmove@plt>
mov    -0x28(%rbp),%rdi
mov    -0x9(%rbp),%al
mov    -0x20(%rbp),%rdx
sub    -0x18(%rbp),%rdx
movsbl %al,%esi
call   1030 <memset@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pad_front>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rcx,%rsi
call   1040 <realloc@plt>
mov    %rax,%rbp
lea    (%rax,%rbx,1),%rdi
sub    %r14,%rdi
mov    %rax,%rsi
mov    %r14,%rdx
call   1050 <memmove@plt>
sub    %r14,%rbx
mov    %rbp,%rdi
mov    %r15d,%esi
mov    %rbx,%rdx
call   1030 <memset@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @pad_front(i8* %0, i8 signext %1, i64 %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %5
store i8 %1, i8* %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%10 = load i8*, i8** %5
%11 = load i64, i64* %8
%12 = call i8* @realloc(i8* %10, i64 %11)
store i8* %12, i8** %9
%13 = load i8*, i8** %9
%14 = load i64, i64* %8
%15 = getelementptr inbounds i8, i8* %13, i64 %14
%16 = load i64, i64* %7
%17 = sub i64 0, %16
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8*, i8** %9
%20 = load i64, i64* %7
%21 = call i32 @memmove(i8* %18, i8* %19, i64 %20)
%22 = load i8*, i8** %9
%23 = load i8, i8* %6
%24 = load i64, i64* %8
%25 = load i64, i64* %7
%26 = sub i64 %24, %25
%27 = call i32 @memset(i8* %22, i8 signext %23, i64 %26)
%28 = load i8*, i8** %9
ret i8* %28
}

LLVM IR (-O2):
define i8* @pad_front(i8* nocapture %0, i8 signext %1, i64 %2, i64 %3) {
%5 = tail call i8* @realloc(i8* %0, i64 %3)
%6 = getelementptr inbounds i8, i8* %5, i64 %3
%7 = sub i64 0, %2
%8 = getelementptr inbounds i8, i8* %6, i64 %7
%9 = tail call i32 @memmove(i8* %8, i8* %5, i64 %2)
%10 = sub i64 %3, %2
%11 = tail call i32 @memset(i8* %5, i8 signext %1, i64 %10)
ret i8* %5
}