#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stderr;
int main() {
  char buffer[12] = "hello world";
  int i;
  printf("Enter the character you want: ");
  scanf("%i", &i);
  if (i >= sizeof(buffer)) {
    fprintf(stderr,
            "Error: %i is greater than or equal to the range which is %i", i,
            sizeof(buffer));
    exit(0);
  }
  printf("You asked for character %i which is %c", i, buffer[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeaa(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xea8(%rip),%eax
mov    %eax,-0x8(%rbp)
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeec(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <scanf@plt>
movslq -0x14(%rbp),%rax
cmp    $0xc,%rax
jb     11b3 <main+0x73>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe89(%rip),%rsi
mov    $0xc,%ecx
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x14(%rbp),%esi
movslq -0x14(%rbp),%rax
movsbl -0x10(%rbp,%rax,1),%edx
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xec4(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf0e(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    $0xc,%rax
jae    1189 <main+0x49>
lea    0xe8f(%rip),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xeeb(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    0x2e50(%rip),%rcx
mov    (%rcx),%edi
lea    0xe92(%rip),%rsi
mov    %eax,%edx
mov    $0xc,%ecx
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@__const.main.buffer = [12 x i8] c"hello world\00"
@.str = [31 x i8] c"Enter the character you want: \00"
@.str.1 = [3 x i8] c"%i\00"
@stderr = global i32 0
@.str.2 = [60 x i8] c"Error: %i is greater than or equal to the range which is %i\00"
@.str.3 = [39 x i8] c"You asked for character %i which is %c\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [12 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = bitcast [12 x i8]* %2 to i8*
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = icmp uge i64 %8, 12
br i1 %9, label %10, label %15
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = load i32, i32* %3
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0), i32 %12, i32 12)
%14 = call i32 @exit(i32 0)
unreachable
15: ; preds = %0
%16 = load i32, i32* %3
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 %16, i32 %21)
ret i32 0
}

LLVM IR (-O2):
@__const.main.buffer = [12 x i8] c"hello world\00"
@.str = [31 x i8] c"Enter the character you want: \00"
@.str.1 = [3 x i8] c"%i\00"
@stderr = global i32 0
@.str.2 = [60 x i8] c"Error: %i is greater than or equal to the range which is %i\00"
@.str.3 = [39 x i8] c"You asked for character %i which is %c\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp ugt i32 %5, 11
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0), i32 %5, i32 12)
%10 = call i32 @exit(i32 0)
unreachable
11: ; preds = %0
%12 = zext i32 %5 to i64
%13 = getelementptr inbounds [12 x i8], [12 x i8]* @__const.main.buffer, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 %5, i32 %15)
ret i32 0
}