#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 *, ...);
void mem() {
  int *pos;
  pos = malloc(sizeof(int) * 8 * 1024 * 1024);
  printf("%p\n", &pos);
  printf("%d\n", *pos);
  int *secpos;
  secpos = calloc(8 * 1024 * 1024, sizeof(int) * 8);
  printf("%p\n", &secpos);
  printf("%d\n", *secpos);
  free(pos);
  free(secpos);
}


x86 assembly (clang, -O0):
<mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x2000000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x8(%rbp)
lea    0xea3(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x800000,%edi
mov    $0x20,%esi
call   1050 <calloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xe6a(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mem>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    $0x2000000,%edi
call   1060 <malloc@plt>
mov    %rax,0x10(%rsp)
lea    0xea3(%rip),%r14
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%rax
mov    (%rax),%esi
lea    0xe8a(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x800000,%edi
mov    $0x20,%esi
call   1050 <calloc@plt>
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%p\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define void @mem() {
%1 = alloca i32*
%2 = alloca i32*
%3 = call i32* @malloc(i32 33554432)
store i32* %3, i32** %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32** %1)
%5 = load i32*, i32** %1
%6 = load i32, i32* %5
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = call i32* @calloc(i32 8388608, i32 32)
store i32* %8, i32** %2
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32** %2)
%10 = load i32*, i32** %2
%11 = load i32, i32* %10
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = load i32*, i32** %1
%14 = call i32 @free(i32* %13)
%15 = load i32*, i32** %2
%16 = call i32 @free(i32* %15)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%p\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define void @mem() {
%1 = alloca i32*
%2 = alloca i32*
%3 = bitcast i32** %1 to i8*
%4 = tail call i32* @malloc(i32 33554432)
store i32* %4, i32** %1
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32** %1)
%6 = load i32*, i32** %1
%7 = load i32, i32* %6
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = bitcast i32** %2 to i8*
%10 = call i32* @calloc(i32 8388608, i32 32)
store i32* %10, i32** %2
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32** %2)
%12 = load i32*, i32** %2
%13 = load i32, i32* %12
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i32*, i32** %1
%16 = call i32 @free(i32* %15)
%17 = load i32*, i32** %2
%18 = call i32 @free(i32* %17)
ret void
}