#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 *calloc(int, int);
int /*<<< orphan*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int *realloc(int *, int);
int main() {
  int *int_pointer = malloc(sizeof(int));
  printf("Garbage value in *int_pointer: %d\n", *int_pointer);
  *int_pointer = 50;
  printf("After assigning 50 to *int_pointer, this is its value: %d\n\n",
         *int_pointer);
  free(int_pointer);
  int *int_array = malloc(3 * sizeof(int));
  int_array[0] = 10;
  int_array[1] = 20;
  int_array[2] = 30;
  for (size_t i = 0; i < 3; i++) {
    printf("int_array[%d] = %d\n", i, int_array[i]);
  }
  printf("\nAnother way of printing the array: \n");
  printf("*int_array = %d\n", *int_array);
  printf("*(int_array + 1) = %d\n", *(int_array + 1));
  printf("*(int_array + 2) = %d\n", *(int_array + 2));
  int_array = calloc(5, sizeof(int));
  int_array[0] = 100;
  int_array[1] = 200;
  for (size_t i = 0; i < 10; i++) {
    printf("int_array[%d] = %d\n", i, int_array[i]);
  }
  int_array = realloc(int_array, 5 * sizeof(int));
  int_array[4] = 500;
  for (size_t i = 0; i < 5; i++) {
    printf("int_array[%d] = %d\n", i, int_array[i]);
  }
  free(int_array);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
movl   $0x32,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0xc,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0xa,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x14,0x4(%rax)
mov    -0x18(%rbp),%rax
movl   $0x1e,0x8(%rax)
movq   $0x0,-0x20(%rbp)
cmpq   $0x3,-0x20(%rbp)
jae    1217 <main+0xc7>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11de <main+0x8e>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%esi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%esi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x5,%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x64,(%rax)
mov    -0x18(%rbp),%rax
movl   $0xc8,0x4(%rax)
movq   $0x0,-0x28(%rbp)
cmpq   $0xa,-0x28(%rbp)
jae    12cc <main+0x17c>
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1293 <main+0x143>
mov    -0x18(%rbp),%rdi
mov    $0x14,%esi
call   1070 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x1f4,0x10(%rax)
movq   $0x0,-0x30(%rbp)
cmpq   $0x5,-0x30(%rbp)
jae    132a <main+0x1da>
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xd4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    12f1 <main+0x1a1>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    (%rax),%esi
lea    0xe86(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x32,(%rbx)
lea    0xe95(%rip),%rdi
mov    $0x32,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0xc,%edi
call   1070 <malloc@plt>
lea    0xeac(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xa,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%esi
mov    %r14,%rdi
mov    $0x14,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x2,%esi
mov    %r14,%rdi
mov    $0x1e,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xebf(%rip),%rdi
call   1040 <puts@plt>
lea    0xe74(%rip),%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe72(%rip),%rdi
mov    $0x14,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe76(%rip),%rdi
mov    $0x1e,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x5,%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
movabs $0xc800000064,%rax
mov    %rax,(%rbx)
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x64,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%esi
mov    %r14,%rdi
mov    $0xc8,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%edx
mov    $0x2,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rbx),%edx
mov    $0x3,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rbx),%edx
mov    $0x4,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x14(%rbx),%edx
mov    $0x5,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%rbx),%edx
mov    $0x6,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x1c(%rbx),%edx
mov    $0x7,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x20(%rbx),%edx
mov    $0x8,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x24(%rbx),%edx
mov    $0x9,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x14,%esi
call   1080 <realloc@plt>
mov    %rax,%rbx
movl   $0x1f4,0x10(%rax)
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rbx),%edx
mov    $0x1,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%edx
mov    $0x2,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rbx),%edx
mov    $0x3,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rbx),%edx
mov    $0x4,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [35 x i8] c"Garbage value in *int_pointer: %d\0A\00"
@.str.1 = [60 x i8] c"After assigning 50 to *int_pointer, this is its value: %d\0A\0A\00"
@.str.2 = [20 x i8] c"int_array[%d] = %d\0A\00"
@.str.3 = [38 x i8] c"\0AAnother way of printing the array: \0A\00"
@.str.4 = [17 x i8] c"*int_array = %d\0A\00"
@.str.5 = [23 x i8] c"*(int_array + 1) = %d\0A\00"
@.str.6 = [23 x i8] c"*(int_array + 2) = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i32 0, i32* %1
%7 = call i32* @malloc(i32 4)
store i32* %7, i32** %2
%8 = load i32*, i32** %2
%9 = load i32, i32* %8
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i32*, i32** %2
store i32 50, i32* %11
%12 = load i32*, i32** %2
%13 = load i32, i32* %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i32*, i32** %2
%16 = call i32 @free(i32* %15)
%17 = call i32* @malloc(i32 12)
store i32* %17, i32** %3
%18 = load i32*, i32** %3
%19 = getelementptr inbounds i32, i32* %18, i64 0
store i32 10, i32* %19
%20 = load i32*, i32** %3
%21 = getelementptr inbounds i32, i32* %20, i64 1
store i32 20, i32* %21
%22 = load i32*, i32** %3
%23 = getelementptr inbounds i32, i32* %22, i64 2
store i32 30, i32* %23
store i64 0, i64* %4
br label %24
24: ; preds = %34, %0
%25 = load i64, i64* %4
%26 = icmp ult i64 %25, 3
br i1 %26, label %27, label %37
27: ; preds = %24
%28 = load i64, i64* %4
%29 = load i32*, i32** %3
%30 = load i64, i64* %4
%31 = getelementptr inbounds i32, i32* %29, i64 %30
%32 = load i32, i32* %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 %28, i32 %32)
br label %34
34: ; preds = %27
%35 = load i64, i64* %4
%36 = add i64 %35, 1
store i64 %36, i64* %4
br label %24
37: ; preds = %24
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
%39 = load i32*, i32** %3
%40 = load i32, i32* %39
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %40)
%42 = load i32*, i32** %3
%43 = getelementptr inbounds i32, i32* %42, i64 1
%44 = load i32, i32* %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %44)
%46 = load i32*, i32** %3
%47 = getelementptr inbounds i32, i32* %46, i64 2
%48 = load i32, i32* %47
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 %48)
%50 = call i32* @calloc(i32 5, i32 4)
store i32* %50, i32** %3
%51 = load i32*, i32** %3
%52 = getelementptr inbounds i32, i32* %51, i64 0
store i32 100, i32* %52
%53 = load i32*, i32** %3
%54 = getelementptr inbounds i32, i32* %53, i64 1
store i32 200, i32* %54
store i64 0, i64* %5
br label %55
55: ; preds = %65, %37
%56 = load i64, i64* %5
%57 = icmp ult i64 %56, 10
br i1 %57, label %58, label %68
58: ; preds = %55
%59 = load i64, i64* %5
%60 = load i32*, i32** %3
%61 = load i64, i64* %5
%62 = getelementptr inbounds i32, i32* %60, i64 %61
%63 = load i32, i32* %62
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 %59, i32 %63)
br label %65
65: ; preds = %58
%66 = load i64, i64* %5
%67 = add i64 %66, 1
store i64 %67, i64* %5
br label %55
68: ; preds = %55
%69 = load i32*, i32** %3
%70 = call i32* @realloc(i32* %69, i32 20)
store i32* %70, i32** %3
%71 = load i32*, i32** %3
%72 = getelementptr inbounds i32, i32* %71, i64 4
store i32 500, i32* %72
store i64 0, i64* %6
br label %73
73: ; preds = %83, %68
%74 = load i64, i64* %6
%75 = icmp ult i64 %74, 5
br i1 %75, label %76, label %86
76: ; preds = %73
%77 = load i64, i64* %6
%78 = load i32*, i32** %3
%79 = load i64, i64* %6
%80 = getelementptr inbounds i32, i32* %78, i64 %79
%81 = load i32, i32* %80
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 %77, i32 %81)
br label %83
83: ; preds = %76
%84 = load i64, i64* %6
%85 = add i64 %84, 1
store i64 %85, i64* %6
br label %73
86: ; preds = %73
%87 = load i32*, i32** %3
%88 = call i32 @free(i32* %87)
ret i32 0
}

LLVM IR (-O2):
@.str = [35 x i8] c"Garbage value in *int_pointer: %d\0A\00"
@.str.1 = [60 x i8] c"After assigning 50 to *int_pointer, this is its value: %d\0A\0A\00"
@.str.2 = [20 x i8] c"int_array[%d] = %d\0A\00"
@.str.4 = [17 x i8] c"*int_array = %d\0A\00"
@.str.5 = [23 x i8] c"*(int_array + 1) = %d\0A\00"
@.str.6 = [23 x i8] c"*(int_array + 2) = %d\0A\00"
@str = [37 x i8] c"\0AAnother way of printing the array: \00"
define i32 @main() {
%1 = tail call i32* @malloc(i32 4)
%2 = load i32, i32* %1
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %2)
store i32 50, i32* %1
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i32 50)
%5 = tail call i32 @free(i32* %1)
%6 = tail call i32* @malloc(i32 12)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 0, i32 10)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 1, i32 20)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 2, i32 30)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 10)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 20)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 30)
%14 = tail call i32* @calloc(i32 5, i32 4)
store i32 100, i32* %14
%15 = getelementptr inbounds i32, i32* %14, i64 1
store i32 200, i32* %15
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 0, i32 100)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 1, i32 200)
%18 = getelementptr inbounds i32, i32* %14, i64 2
%19 = load i32, i32* %18
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 2, i32 %19)
%21 = getelementptr inbounds i32, i32* %14, i64 3
%22 = load i32, i32* %21
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 3, i32 %22)
%24 = getelementptr inbounds i32, i32* %14, i64 4
%25 = load i32, i32* %24
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 4, i32 %25)
%27 = getelementptr inbounds i32, i32* %14, i64 5
%28 = load i32, i32* %27
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 5, i32 %28)
%30 = getelementptr inbounds i32, i32* %14, i64 6
%31 = load i32, i32* %30
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 6, i32 %31)
%33 = getelementptr inbounds i32, i32* %14, i64 7
%34 = load i32, i32* %33
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 7, i32 %34)
%36 = getelementptr inbounds i32, i32* %14, i64 8
%37 = load i32, i32* %36
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 8, i32 %37)
%39 = getelementptr inbounds i32, i32* %14, i64 9
%40 = load i32, i32* %39
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 9, i32 %40)
%42 = tail call i32* @realloc(i32* %14, i32 20)
%43 = getelementptr inbounds i32, i32* %42, i64 4
store i32 500, i32* %43
%44 = load i32, i32* %42
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 0, i32 %44)
%46 = getelementptr inbounds i32, i32* %42, i64 1
%47 = load i32, i32* %46
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 1, i32 %47)
%49 = getelementptr inbounds i32, i32* %42, i64 2
%50 = load i32, i32* %49
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 2, i32 %50)
%52 = getelementptr inbounds i32, i32* %42, i64 3
%53 = load i32, i32* %52
%54 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 3, i32 %53)
%55 = load i32, i32* %43
%56 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 4, i32 %55)
%57 = tail call i32 @free(i32* %42)
ret i32 0
}