#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 /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int *);
scalar_t__ realloc(int *, int);
int main(int argc, char **argv) {
  int A[5];
  int *B;
  int *C;
  int *tmp;
  int n = 10;
  int i;
  for (i = 0; i < 5; i++)
    A[i] = i;
  printf("A: %p\n", A);
  B = (int *)malloc(sizeof(int) * 5);
  for (i = 0; i < 5; i++)
    B[i] = i;
  C = (int *)malloc(sizeof(int) * n);
  for (i = 0; i < n; i++)
    C[i] = 1;
  tmp = B;
  B = C;
  C = tmp;
  C = (int *)realloc(C, sizeof(int) * (5 * 2));
  for (i = 5; i < (5 * 2); i++)
    C[i] = i;
  free(B);
  free(C);
  B = C = tmp = NULL;
  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)
movl   $0xa,-0x4c(%rbp)
movl   $0x0,-0x50(%rbp)
cmpl   $0x5,-0x50(%rbp)
jge    1187 <main+0x47>
mov    -0x50(%rbp),%ecx
movslq -0x50(%rbp),%rax
mov    %ecx,-0x30(%rbp,%rax,4)
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    1164 <main+0x24>
lea    -0x30(%rbp),%rsi
lea    0xe6e(%rip),%rdi
call   1040 <printf@plt>
mov    $0x14,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x50(%rbp)
cmpl   $0x5,-0x50(%rbp)
jge    11d2 <main+0x92>
mov    -0x50(%rbp),%edx
mov    -0x38(%rbp),%rax
movslq -0x50(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    11ac <main+0x6c>
movslq -0x4c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x4c(%rbp),%eax
jge    1215 <main+0xd5>
mov    -0x40(%rbp),%rax
movslq -0x50(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    11ec <main+0xac>
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    $0x28,%esi
call   1060 <realloc@plt>
mov    %rax,-0x40(%rbp)
movl   $0x5,-0x50(%rbp)
cmpl   $0xa,-0x50(%rbp)
jge    126c <main+0x12c>
mov    -0x50(%rbp),%edx
mov    -0x40(%rbp),%rax
movslq -0x50(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    1246 <main+0x106>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x38(%rbp)
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movaps 0xeb2(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x4,0x10(%rsp)
lea    0xecf(%rip),%rdi
mov    %rsp,%rsi
call   1040 <printf@plt>
mov    $0x14,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
movaps 0xe83(%rip),%xmm0
movups %xmm0,(%rax)
movl   $0x4,0x10(%rax)
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movaps 0xe75(%rip),%xmm0
movups %xmm0,(%rax)
movups %xmm0,0x10(%rax)
movabs $0x100000001,%rax
mov    %rax,0x20(%rbx)
mov    %r14,%rdi
mov    $0x28,%esi
call   1060 <realloc@plt>
mov    %rax,%r14
movaps 0xe59(%rip),%xmm0
movups %xmm0,0x14(%rax)
movl   $0x9,0x24(%rax)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c"A: %p\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [5 x i32]
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 10, i32* %10
store i32 0, i32* %11
br label %12
12: ; preds = %20, %2
%13 = load i32, i32* %11
%14 = icmp slt i32 %13, 5
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = load i32, i32* %11
%17 = load i32, i32* %11
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 %18
store i32 %16, i32* %19
br label %20
20: ; preds = %15
%21 = load i32, i32* %11
%22 = add nsw i32 %21, 1
store i32 %22, i32* %11
br label %12
23: ; preds = %12
%24 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 0
%25 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %24)
%26 = call i64 @malloc(i32 20)
%27 = inttoptr i64 %26 to i32*
store i32* %27, i32** %7
store i32 0, i32* %11
br label %28
28: ; preds = %37, %23
%29 = load i32, i32* %11
%30 = icmp slt i32 %29, 5
br i1 %30, label %31, label %40
31: ; preds = %28
%32 = load i32, i32* %11
%33 = load i32*, i32** %7
%34 = load i32, i32* %11
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
store i32 %32, i32* %36
br label %37
37: ; preds = %31
%38 = load i32, i32* %11
%39 = add nsw i32 %38, 1
store i32 %39, i32* %11
br label %28
40: ; preds = %28
%41 = load i32, i32* %10
%42 = sext i32 %41 to i64
%43 = mul i64 4, %42
%44 = trunc i64 %43 to i32
%45 = call i64 @malloc(i32 %44)
%46 = inttoptr i64 %45 to i32*
store i32* %46, i32** %8
store i32 0, i32* %11
br label %47
47: ; preds = %56, %40
%48 = load i32, i32* %11
%49 = load i32, i32* %10
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %59
51: ; preds = %47
%52 = load i32*, i32** %8
%53 = load i32, i32* %11
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i32, i32* %52, i64 %54
store i32 1, i32* %55
br label %56
56: ; preds = %51
%57 = load i32, i32* %11
%58 = add nsw i32 %57, 1
store i32 %58, i32* %11
br label %47
59: ; preds = %47
%60 = load i32*, i32** %7
store i32* %60, i32** %9
%61 = load i32*, i32** %8
store i32* %61, i32** %7
%62 = load i32*, i32** %9
store i32* %62, i32** %8
%63 = load i32*, i32** %8
%64 = call i64 @realloc(i32* %63, i32 40)
%65 = inttoptr i64 %64 to i32*
store i32* %65, i32** %8
store i32 5, i32* %11
br label %66
66: ; preds = %75, %59
%67 = load i32, i32* %11
%68 = icmp slt i32 %67, 10
br i1 %68, label %69, label %78
69: ; preds = %66
%70 = load i32, i32* %11
%71 = load i32*, i32** %8
%72 = load i32, i32* %11
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i32, i32* %71, i64 %73
store i32 %70, i32* %74
br label %75
75: ; preds = %69
%76 = load i32, i32* %11
%77 = add nsw i32 %76, 1
store i32 %77, i32* %11
br label %66
78: ; preds = %66
%79 = load i32*, i32** %7
%80 = call i32 @free(i32* %79)
%81 = load i32*, i32** %8
%82 = call i32 @free(i32* %81)
store i32* null, i32** %9
store i32* null, i32** %8
store i32* null, i32** %7
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"A: %p\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [5 x i32]
%4 = bitcast [5 x i32]* %3 to i8*
%5 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 0
%6 = bitcast [5 x i32]* %3 to <4 x i32>*
store <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32>* %6
%7 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 4
store i32 4, i32* %7
%8 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %5)
%9 = call i64 @malloc(i32 20)
%10 = inttoptr i64 %9 to i32*
%11 = inttoptr i64 %9 to <4 x i32>*
store <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32>* %11
%12 = getelementptr inbounds i32, i32* %10, i64 4
store i32 4, i32* %12
%13 = call i64 @malloc(i32 40)
%14 = inttoptr i64 %13 to i32*
%15 = inttoptr i64 %13 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %15
%16 = getelementptr inbounds i32, i32* %14, i64 4
%17 = bitcast i32* %16 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %17
%18 = getelementptr inbounds i32, i32* %14, i64 8
store i32 1, i32* %18
%19 = getelementptr inbounds i32, i32* %14, i64 9
store i32 1, i32* %19
%20 = call i64 @realloc(i32* %10, i32 40)
%21 = inttoptr i64 %20 to i32*
%22 = getelementptr inbounds i32, i32* %21, i64 5
%23 = bitcast i32* %22 to <4 x i32>*
store <4 x i32> <i32 5, i32 6, i32 7, i32 8>, <4 x i32>* %23
%24 = getelementptr inbounds i32, i32* %21, i64 9
store i32 9, i32* %24
%25 = call i32 @free(i32* %14)
%26 = call i32 @free(i32* %21)
ret i32 0
}