#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 length(char const *);
int /*<<< orphan*/ stderr;
char charAtIndex(const char *a, int index) {
  if (a == NULL) {
    fprintf(stderr, "NULL Pointer Exception at charAtIndex\n");
    exit(-1);
  }
  if (index < 0 || index > length(a)) {
    fprintf(stderr, "Index out of Bounds Exception at charAtIndex\n");
    exit(-1);
  }
  return a[index];
}


x86 assembly (clang, -O0):
<charAtIndex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1169 <charAtIndex+0x39>
mov    0x2e8f(%rip),%rax
mov    (%rax),%edi
lea    0xea6(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
cmpl   $0x0,-0xc(%rbp)
jl     118f <charAtIndex+0x5f>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <length@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
jle    11ae <charAtIndex+0x7e>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    0xe88(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<charAtIndex>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     1168 <charAtIndex+0x38>
mov    %esi,%ebp
test   %esi,%esi
js     1156 <charAtIndex+0x26>
mov    %rdi,%rbx
call   1030 <length@plt>
cmp    %ebp,%eax
jl     1156 <charAtIndex+0x26>
mov    %ebp,%eax
mov    (%rbx,%rax,1),%al
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
lea    0xec1(%rip),%rsi
jmp    1178 <charAtIndex+0x48>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    0xe88(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"NULL Pointer Exception at charAtIndex\0A\00"
@.str.1 = [46 x i8] c"Index out of Bounds Exception at charAtIndex\0A\00"
define signext i8 @charAtIndex(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 -1)
unreachable
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %11
%15 = load i32, i32* %4
%16 = load i8*, i8** %3
%17 = call i32 @length(i8* %16)
%18 = icmp sgt i32 %15, %17
br i1 %18, label %19, label %23
19: ; preds = %14, %11
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %14
%24 = load i8*, i8** %3
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
ret i8 %28
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"NULL Pointer Exception at charAtIndex\0A\00"
@.str.1 = [46 x i8] c"Index out of Bounds Exception at charAtIndex\0A\00"
define signext i8 @charAtIndex(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %2
%9 = icmp slt i32 %1, 0
br i1 %9, label %13, label %10
10: ; preds = %8
%11 = tail call i32 @length(i8* %0)
%12 = icmp slt i32 %11, %1
br i1 %12, label %13, label %17
13: ; preds = %10, %8
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @exit(i32 -1)
unreachable
17: ; preds = %10
%18 = zext i32 %1 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
ret i8 %20
}