#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 */
struct mallinfo {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(void *);
int /*<<< orphan*/ getchar();
struct mallinfo mallinfo();
void *malloc(int);
int /*<<< orphan*/ malloc_status(struct mallinfo);
int /*<<< orphan*/ printf(char *);
int main() {
  struct mallinfo status;
  void *ptr;
  printf("default heap status \n");
  status = mallinfo();
  malloc_status(status);
  getchar();
  printf("status after 1 page dynamic allocation \n");
  ptr = malloc(4096);
  status = mallinfo();
  malloc_status(status);
  getchar();
  printf("status after free call to first allocation\n");
  free(ptr);
  status = mallinfo();
  malloc_status(status);
  getchar();
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <mallinfo@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <malloc_status@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
lea    0xe65(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1050 <mallinfo@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <malloc_status@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
lea    0xe55(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1050 <mallinfo@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <malloc_status@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xe88(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1050 <mallinfo@plt>
mov    %eax,%edi
call   1070 <malloc_status@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
lea    0xe7c(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1000,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <mallinfo@plt>
mov    %eax,%edi
call   1070 <malloc_status@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
lea    0xe76(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
call   1050 <mallinfo@plt>
mov    %eax,%edi
call   1070 <malloc_status@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.mallinfo = type { i32 }
@.str = [22 x i8] c"default heap status \0A\00"
@.str.1 = [41 x i8] c"status after 1 page dynamic allocation \0A\00"
@.str.2 = [44 x i8] c"status after free call to first allocation\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.mallinfo
%3 = alloca i8*
%4 = alloca %struct.mallinfo
%5 = alloca %struct.mallinfo
%6 = alloca %struct.mallinfo
store i32 0, i32* %1
%7 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (...) @mallinfo()
%9 = getelementptr inbounds %struct.mallinfo, %struct.mallinfo* %4, i32 0, i32 0
store i32 %8, i32* %9
%10 = bitcast %struct.mallinfo* %2 to i8*
%11 = bitcast %struct.mallinfo* %4 to i8*
%12 = getelementptr inbounds %struct.mallinfo, %struct.mallinfo* %2, i32 0, i32 0
%13 = load i32, i32* %12
%14 = call i32 @malloc_status(i32 %13)
%15 = call i32 (...) @getchar()
%16 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%17 = call i8* @malloc(i32 4096)
store i8* %17, i8** %3
%18 = call i32 (...) @mallinfo()
%19 = getelementptr inbounds %struct.mallinfo, %struct.mallinfo* %5, i32 0, i32 0
store i32 %18, i32* %19
%20 = bitcast %struct.mallinfo* %2 to i8*
%21 = bitcast %struct.mallinfo* %5 to i8*
%22 = getelementptr inbounds %struct.mallinfo, %struct.mallinfo* %2, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @malloc_status(i32 %23)
%25 = call i32 (...) @getchar()
%26 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%27 = load i8*, i8** %3
%28 = call i32 @free(i8* %27)
%29 = call i32 (...) @mallinfo()
%30 = getelementptr inbounds %struct.mallinfo, %struct.mallinfo* %6, i32 0, i32 0
store i32 %29, i32* %30
%31 = bitcast %struct.mallinfo* %2 to i8*
%32 = bitcast %struct.mallinfo* %6 to i8*
%33 = getelementptr inbounds %struct.mallinfo, %struct.mallinfo* %2, i32 0, i32 0
%34 = load i32, i32* %33
%35 = call i32 @malloc_status(i32 %34)
%36 = call i32 (...) @getchar()
%37 = load i32, i32* @EXIT_SUCCESS
%38 = call i32 @exit(i32 %37)
unreachable
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
@str = [21 x i8] c"default heap status \00"
@str.3 = [40 x i8] c"status after 1 page dynamic allocation \00"
@str.4 = [43 x i8] c"status after free call to first allocation\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 (...) @mallinfo()
%3 = tail call i32 @malloc_status(i32 %2)
%4 = tail call i32 (...) @getchar()
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.3, i64 0, i64 0))
%6 = tail call dereferenceable_or_null(4096) i8* @malloc(i32 4096)
%7 = tail call i32 (...) @mallinfo()
%8 = tail call i32 @malloc_status(i32 %7)
%9 = tail call i32 (...) @getchar()
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.4, i64 0, i64 0))
%11 = tail call i32 @free(i8* %6)
%12 = tail call i32 (...) @mallinfo()
%13 = tail call i32 @malloc_status(i32 %12)
%14 = tail call i32 (...) @getchar()
%15 = load i32, i32* @EXIT_SUCCESS
%16 = tail call i32 @exit(i32 %15)
unreachable
}