#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 *);
void *sbrk(int /*<<< orphan*/);
int main(int argc, char **argv) {
  (void)argc;
  (void)argv;
  void *stack = sbrk(0);
  int *small = calloc(sizeof(int), 1);
  int i = 1234;
  *small = i;
  int *big = malloc(1 << 28);
  printf("my stack is around:               %016p\n", stack);
  printf("the address of a local variable:  %016p\n", &i);
  printf("address of a small allocation:    %016p\n", small);
  printf("address of a big allocation:      %016p\n", big);
  free(small);
  small = NULL;
  free(big);
  big = NULL;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %edi,%edi
call   1050 <sbrk@plt>
mov    %rax,-0x18(%rbp)
mov    $0x4,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x4d2,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    $0x10000000,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe53(%rip),%rdi
call   1040 <printf@plt>
lea    0xe70(%rip),%rdi
lea    -0x24(%rbp),%rsi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe85(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    0xe9e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x30(%rbp)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
call   1050 <sbrk@plt>
mov    %rax,%r15
mov    $0x4,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
movl   $0x4d2,0xc(%rsp)
movl   $0x4d2,(%rax)
mov    $0x10000000,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
lea    0xe69(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
lea    0xe83(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <printf@plt>
lea    0xe9b(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0xeb5(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [41 x i8] c"my stack is around: %016p\0A\00"
@.str.1 = [41 x i8] c"the address of a local variable: %016p\0A\00"
@.str.2 = [41 x i8] c"address of a small allocation: %016p\0A\00"
@.str.3 = [41 x i8] c"address of a big allocation: %016p\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = load i8**, i8*** %5
%12 = call i8* @sbrk(i32 0)
store i8* %12, i8** %6
%13 = call i32* @calloc(i32 4, i32 1)
store i32* %13, i32** %7
store i32 1234, i32* %8
%14 = load i32, i32* %8
%15 = load i32*, i32** %7
store i32 %14, i32* %15
%16 = call i32* @malloc(i32 268435456)
store i32* %16, i32** %9
%17 = load i8*, i8** %6
%18 = bitcast i8* %17 to i32*
%19 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32* %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32* %8)
%21 = load i32*, i32** %7
%22 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32* %21)
%23 = load i32*, i32** %9
%24 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32* %23)
%25 = load i32*, i32** %7
%26 = call i32 @free(i32* %25)
store i32* null, i32** %7
%27 = load i32*, i32** %9
%28 = call i32 @free(i32* %27)
store i32* null, i32** %9
ret i32 0
}

LLVM IR (-O2):
@.str = [41 x i8] c"my stack is around: %016p\0A\00"
@.str.1 = [41 x i8] c"the address of a local variable: %016p\0A\00"
@.str.2 = [41 x i8] c"address of a small allocation: %016p\0A\00"
@.str.3 = [41 x i8] c"address of a big allocation: %016p\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = tail call i8* @sbrk(i32 0)
%5 = tail call i32* @calloc(i32 4, i32 1)
%6 = bitcast i32* %3 to i8*
store i32 1234, i32* %3
store i32 1234, i32* %5
%7 = tail call i32* @malloc(i32 268435456)
%8 = bitcast i8* %4 to i32*
%9 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32* %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%11 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%12 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32* %7)
%13 = call i32 @free(i32* %5)
%14 = call i32 @free(i32* %7)
ret i32 0
}