#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 *malloc(int);
int /*<<< orphan*/ memcpy(int *, int *, int);
int /*<<< orphan*/ memset(int *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
void varTest() {
  float local_var = 2.99;
  printf("Accessing global_var: %f\n", local_var);
  printf("Pointers\n");
  int x = 10, *x_ptr;
  x_ptr = &x;
  printf("Accessing pointer: %d\n", *x_ptr);
  printf("Static Arrays\n");
  int arr[50];
  arr[0] = 0xAA;
  arr[1] = 0x11;
  arr[2] = 0x22;
  arr[x] = 0x33;
  printf("Accessing array: %d\n", arr[x]);
  printf("Dynamic Arrays\n");
  int *darr = malloc(10 * sizeof(int));
  memset(darr, 10 * sizeof(int), 0);
  memcpy(darr, arr, 5 * sizeof(int));
  darr[5] = 0xFF;
  printf("Accessing dyn array: %d\n", darr[5]);
  printf("Strings\n");
  char *str = "Hello String!", str2[32];
  strcpy(str2, str);
  printf("Accessing str: %s, str2: %s\n", str, str2);
}


x86 assembly (clang, -O0):
<varTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movss  0xe9d(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe8c(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xa,-0x8(%rbp)
lea    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xaa,-0xe0(%rbp)
movl   $0x11,-0xdc(%rbp)
movl   $0x22,-0xd8(%rbp)
movslq -0x8(%rbp),%rax
movl   $0x33,-0xe0(%rbp,%rax,4)
movslq -0x8(%rbp),%rax
mov    -0xe0(%rbp,%rax,4),%esi
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x28,%edi
call   1070 <malloc@plt>
mov    %rax,-0xe8(%rbp)
mov    -0xe8(%rbp),%rdi
mov    $0x28,%esi
xor    %edx,%edx
call   1050 <memset@plt>
mov    -0xe8(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
mov    $0x14,%edx
call   1060 <memcpy@plt>
mov    -0xe8(%rbp),%rax
movl   $0xff,0x14(%rax)
mov    -0xe8(%rbp),%rax
mov    0x14(%rax),%esi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe0c(%rip),%rax
mov    %rax,-0xf0(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0xf0(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0xf0(%rbp),%rsi
lea    -0x110(%rbp),%rdx
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<varTest>:
push   %r14
push   %rbx
sub    $0xe8,%rsp
lea    0xe97(%rip),%rdi
movsd  0xe87(%rip),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xf0b(%rip),%rdi
call   1040 <puts@plt>
lea    0xe8f(%rip),%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xef5(%rip),%rdi
call   1040 <puts@plt>
movabs $0x11000000aa,%rax
mov    %rax,0x20(%rsp)
movl   $0x22,0x28(%rsp)
movl   $0x33,0x48(%rsp)
lea    0xe68(%rip),%rdi
mov    $0x33,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xec5(%rip),%rdi
call   1040 <puts@plt>
mov    $0x28,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x28,%esi
xor    %edx,%edx
call   1060 <memset@plt>
lea    0x20(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x14,%edx
call   1070 <memcpy@plt>
movl   $0xff,0x14(%rbx)
lea    0xe29(%rip),%rdi
mov    $0xff,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe80(%rip),%rdi
call   1040 <puts@plt>
lea    0xe23(%rip),%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xe1c(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0xe8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Accessing global_var: %f\0A\00"
@.str.1 = [10 x i8] c"Pointers\0A\00"
@.str.2 = [23 x i8] c"Accessing pointer: %d\0A\00"
@.str.3 = [15 x i8] c"Static Arrays\0A\00"
@.str.4 = [21 x i8] c"Accessing array: %d\0A\00"
@.str.5 = [16 x i8] c"Dynamic Arrays\0A\00"
@.str.6 = [25 x i8] c"Accessing dyn array: %d\0A\00"
@.str.7 = [9 x i8] c"Strings\0A\00"
@.str.8 = [14 x i8] c"Hello String!\00"
@.str.9 = [29 x i8] c"Accessing str: %s, str2: %s\0A\00"
define void @varTest() {
%1 = alloca float
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [50 x i32]
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca [32 x i8]
store float 0x4007EB8520000000, float* %1
%8 = load float, float* %1
%9 = fpext float %8 to double
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i32 10, i32* %2
store i32* %2, i32** %3
%12 = load i32*, i32** %3
%13 = load i32, i32* %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%16 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 0
store i32 170, i32* %16
%17 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 1
store i32 17, i32* %17
%18 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 2
store i32 34, i32* %18
%19 = load i32, i32* %2
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 %20
store i32 51, i32* %21
%22 = load i32, i32* %2
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 %23
%25 = load i32, i32* %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%28 = call i32* @malloc(i32 40)
store i32* %28, i32** %5
%29 = load i32*, i32** %5
%30 = call i32 @memset(i32* %29, i32 40, i32 0)
%31 = load i32*, i32** %5
%32 = getelementptr inbounds [50 x i32], [50 x i32]* %4, i64 0, i64 0
%33 = call i32 @memcpy(i32* %31, i32* %32, i32 20)
%34 = load i32*, i32** %5
%35 = getelementptr inbounds i32, i32* %34, i64 5
store i32 255, i32* %35
%36 = load i32*, i32** %5
%37 = getelementptr inbounds i32, i32* %36, i64 5
%38 = load i32, i32* %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8** %6
%41 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%42 = load i8*, i8** %6
%43 = call i32 @strcpy(i8* %41, i8* %42)
%44 = load i8*, i8** %6
%45 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0), i8* %44, i8* %45)
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"Accessing global_var: %f\0A\00"
@.str.2 = [23 x i8] c"Accessing pointer: %d\0A\00"
@.str.4 = [21 x i8] c"Accessing array: %d\0A\00"
@.str.6 = [25 x i8] c"Accessing dyn array: %d\0A\00"
@.str.8 = [14 x i8] c"Hello String!\00"
@.str.9 = [29 x i8] c"Accessing str: %s, str2: %s\0A\00"
@str = [9 x i8] c"Pointers\00"
@str.10 = [14 x i8] c"Static Arrays\00"
@str.11 = [15 x i8] c"Dynamic Arrays\00"
@str.12 = [8 x i8] c"Strings\00"
define void @varTest() {
%1 = alloca [50 x i32]
%2 = alloca [32 x i8]
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double 0x4007EB8520000000)
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 10)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.10, i64 0, i64 0))
%7 = bitcast [50 x i32]* %1 to i8*
%8 = getelementptr inbounds [50 x i32], [50 x i32]* %1, i64 0, i64 0
store i32 170, i32* %8
%9 = getelementptr inbounds [50 x i32], [50 x i32]* %1, i64 0, i64 1
store i32 17, i32* %9
%10 = getelementptr inbounds [50 x i32], [50 x i32]* %1, i64 0, i64 2
store i32 34, i32* %10
%11 = getelementptr inbounds [50 x i32], [50 x i32]* %1, i64 0, i64 10
store i32 51, i32* %11
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 51)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.11, i64 0, i64 0))
%14 = tail call i32* @malloc(i32 40)
%15 = tail call i32 @memset(i32* %14, i32 40, i32 0)
%16 = call i32 @memcpy(i32* %14, i32* %8, i32 20)
%17 = getelementptr inbounds i32, i32* %14, i64 5
store i32 255, i32* %17
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 255)
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.12, i64 0, i64 0))
%20 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%21 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8* %20)
ret void
}