#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int pad_leading_characters(char *d, char *s, int number_characters_to_pad,
                           char c_to_pad) {
  if (!d) {
    fprintf(stderr, "pad_leading_characters() got null for a destination\n");
    exit(1);
  }
  while (number_characters_to_pad--)
    *d++ = c_to_pad;
  strcpy(d, s);
  return 1;
}


x86 assembly (clang, -O0):
<pad_leading_characters>:
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)
cmpq   $0x0,-0x8(%rbp)
jne    1172 <pad_leading_characters+0x42>
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
lea    0xe9d(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    1177 <pad_leading_characters+0x47>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     11a4 <pad_leading_characters+0x74>
mov    -0x15(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    1177 <pad_leading_characters+0x47>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pad_leading_characters>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     1183 <pad_leading_characters+0x43>
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
test   %edx,%edx
je     116d <pad_leading_characters+0x2d>
mov    %ebx,%edx
movzbl %cl,%esi
mov    %r15,%rdi
call   1040 <memset@plt>
add    $0xffffffff,%ebx
add    %rbx,%r15
add    $0x1,%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [53 x i8] c"pad_leading_characters() got null for a destination\0A\00"
define i32 @pad_leading_characters(i8* %0, i8* %1, i32 %2, i8 signext %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8 %3, i8* %8
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %15, label %11
11: ; preds = %4
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %4
br label %16
16: ; preds = %20, %15
%17 = load i32, i32* %7
%18 = add nsw i32 %17, -1
store i32 %18, i32* %7
%19 = icmp ne i32 %17, 0
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i8, i8* %8
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %5
store i8 %21, i8* %22
br label %16
24: ; preds = %16
%25 = load i8*, i8** %5
%26 = load i8*, i8** %6
%27 = call i32 @strcpy(i8* %25, i8* %26)
ret i32 1
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [53 x i8] c"pad_leading_characters() got null for a destination\0A\00"
define i32 @pad_leading_characters(i8* %0, i8* %1, i32 %2, i8 signext %3) {
%5 = icmp eq i8* %0, null
br i1 %5, label %14, label %6
6: ; preds = %4
%7 = icmp eq i32 %2, 0
br i1 %7, label %18, label %8
8: ; preds = %6
%9 = zext i32 %2 to i64
%10 = add i32 %2, -1
%11 = zext i32 %10 to i64
%12 = add nuw nsw i64 %11, 1
%13 = getelementptr i8, i8* %0, i64 %12
br label %18
14: ; preds = %4
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %8, %6
%19 = phi i8* [ %0, %6 ], [ %13, %8 ]
%20 = tail call i32 @strcpy(i8* %19, i8* %1)
ret i32 1
}