#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(int /*<<< orphan*/);
int /*<<< orphan*/ getenv(char *);
int *malloc(int);
int /*<<< orphan*/ printf(char *, int, int);
int main(int argc, char const *argv[]) {
  int a[10];
  int *b;
  b = malloc(10 * sizeof(int));
  int index = atoi(getenv("SOMEVAR"));
  printf("Trying to acces %i-th position = %i\n", index, b[index]);
  b[index] = 1;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,-0x48(%rbp)
lea    0xe95(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
call   1060 <atoi@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%esi
mov    -0x48(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
mov    -0x48(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xeab(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
call   1060 <atoi@plt>
movslq %eax,%rsi
mov    (%rbx,%rsi,4),%edx
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"SOMEVAR\00"
@.str.1 = [37 x i8] c"Trying to acces %i-th position = %i\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [10 x i32]
%7 = alloca i32*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32* @malloc(i32 40)
store i32* %9, i32** %7
%10 = call i32 @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @atoi(i32 %10)
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = load i32*, i32** %7
%14 = load i32, i32* %8
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %13, i64 %15
%17 = load i32, i32* %16
%18 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 %17)
%19 = load i32*, i32** %7
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
store i32 1, i32* %22
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"SOMEVAR\00"
@.str.1 = [37 x i8] c"Trying to acces %i-th position = %i\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @malloc(i32 40)
%4 = tail call i32 @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @atoi(i32 %4)
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i32, i32* %3, i64 %6
%8 = load i32, i32* %7
%9 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %5, i32 %8)
ret i32 0
}