#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 atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char, ...);
int main(int argc, char *argv[]) {
  char *buf;
  int size = 800, index = 801;
  if (argc > 1)
    index = atoi(argv[1]);
  if (argc > 2)
    size = atoi(argv[2]);
  buf = malloc(size);
  printf("I allocated  %d bytes, I'm going to use the %d element\n", size,
         index);
  buf[index] = 1;
  printf("buf[index] = %d\n", buf[index]);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x320,-0x1c(%rbp)
movl   $0x321,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    117e <main+0x3e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    1198 <main+0x58>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x20(%rbp),%edx
lea    0xe4f(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x1,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
lea    0xe62(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x20,%r14b
mov    $0x321,%ebx
cmp    $0x2,%edi
jl     1165 <main+0x35>
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
call   1040 <atoi@plt>
mov    %eax,%ebx
cmp    $0x2,%ebp
je     1165 <main+0x35>
mov    0x10(%r15),%rdi
call   1040 <atoi@plt>
mov    %eax,%r14d
movsbl %r14b,%esi
lea    0xe90(%rip),%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeb8(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [56 x i8] c"I allocated %d bytes, I'm going to use the %d element\0A\00"
@.str.1 = [17 x i8] c"buf[index] = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 800, i32* %7
store i32 801, i32* %8
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @atoi(i8* %14)
store i32 %15, i32* %8
br label %16
16: ; preds = %11, %2
%17 = load i32, i32* %4
%18 = icmp sgt i32 %17, 2
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %7
br label %24
24: ; preds = %19, %16
%25 = load i32, i32* %7
%26 = call i8* @malloc(i32 %25)
store i8* %26, i8** %6
%27 = load i32, i32* %7
%28 = trunc i32 %27 to i8
%29 = load i32, i32* %8
%30 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8 signext %28, i32 %29)
%31 = load i8*, i8** %6
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 1, i8* %34
%35 = load i8*, i8** %6
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8, i8* %38
%40 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8 signext %39)
%41 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [56 x i8] c"I allocated %d bytes, I'm going to use the %d element\0A\00"
@.str.1 = [17 x i8] c"buf[index] = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %14
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = icmp eq i32 %0, 2
br i1 %8, label %14, label %9
9: ; preds = %4
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = trunc i32 %12 to i8
br label %14
14: ; preds = %2, %9, %4
%15 = phi i32 [ %7, %9 ], [ %7, %4 ], [ 801, %2 ]
%16 = phi i8 [ %13, %9 ], [ 32, %4 ], [ 32, %2 ]
%17 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8 signext %16, i32 %15)
%18 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8 signext 1)
%19 = tail call i32 @exit(i32 0)
unreachable
}