main() {
  int *i1, *i2;
  printf("sbrk(0) before malloc(4): 0x%x\n", sbrk(0));
  i1 = (int *)malloc(4);
  printf("sbrk(0) after `i1 = (int*)malloc(4)': 0x%x\n", sbrk(0));
  i2 = (int *)malloc(4);
  printf("sbrk(0) after `i2 = (int*)malloc(4)': 0x%x\n", sbrk(0));
  printf("i1 = 0x%x, i2 = 0x%x\n", i1, i2);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %edi,%edi
mov    $0x0,%al
call   1040 <sbrk@plt>
mov    %eax,%esi
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x8(%rbp)
xor    %edi,%edi
mov    $0x0,%al
call   1040 <sbrk@plt>
mov    %eax,%esi
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
xor    %edi,%edi
mov    $0x0,%al
call   1040 <sbrk@plt>
mov    %eax,%esi
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
xor    %eax,%eax
call   1040 <sbrk@plt>
lea    0xebc(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
xor    %edi,%edi
xor    %eax,%eax
call   1040 <sbrk@plt>
lea    0xeb6(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
xor    %eax,%eax
call   1040 <sbrk@plt>
lea    0xebc(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed8(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [32 x i8] c"sbrk(0) before malloc(4): 0x%x\0A\00"
@.str.1 = [44 x i8] c"sbrk(0) after `i1 = (int*)malloc(4)': 0x%x\0A\00"
@.str.2 = [44 x i8] c"sbrk(0) after `i2 = (int*)malloc(4)': 0x%x\0A\00"
@.str.3 = [22 x i8] c"i1 = 0x%x, i2 = 0x%x\0A\00"
define i32 @main() {
%1 = alloca i32*
%2 = alloca i32*
%3 = call i32 (i32, ...) bitcast (i32 (...)* @sbrk to i32 (i32, ...)*)(i32 0)
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = call i8* @malloc(i64 4)
%6 = bitcast i8* %5 to i32*
store i32* %6, i32** %1
%7 = call i32 (i32, ...) bitcast (i32 (...)* @sbrk to i32 (i32, ...)*)(i32 0)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = call i8* @malloc(i64 4)
%10 = bitcast i8* %9 to i32*
store i32* %10, i32** %2
%11 = call i32 (i32, ...) bitcast (i32 (...)* @sbrk to i32 (i32, ...)*)(i32 0)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = load i32*, i32** %1
%14 = load i32*, i32** %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32* %13, i32* %14)
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"sbrk(0) before malloc(4): 0x%x\0A\00"
@.str.1 = [44 x i8] c"sbrk(0) after `i1 = (int*)malloc(4)': 0x%x\0A\00"
@.str.2 = [44 x i8] c"sbrk(0) after `i2 = (int*)malloc(4)': 0x%x\0A\00"
@.str.3 = [22 x i8] c"i1 = 0x%x, i2 = 0x%x\0A\00"
define i32 @main() {
%1 = tail call i32 (i32, ...) bitcast (i32 (...)* @sbrk to i32 (i32, ...)*)(i32 0)
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call dereferenceable_or_null(4) i8* @malloc(i64 4)
%4 = tail call i32 (i32, ...) bitcast (i32 (...)* @sbrk to i32 (i32, ...)*)(i32 0)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = tail call dereferenceable_or_null(4) i8* @malloc(i64 4)
%7 = tail call i32 (i32, ...) bitcast (i32 (...)* @sbrk to i32 (i32, ...)*)(i32 0)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %3, i8* %6)
ret i32 0
}