#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*/ brk(int *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ sbrk(int);
int main() {
  int *p1 = (int *)sbrk(4);
  int *p2 = (int *)sbrk(200);
  int *p3 = (int *)sbrk(0);
  int *p4 = (int *)sbrk(-4);
  int *p5 = (int *)sbrk(-4);
  printf("p1 = %p\n", p1);
  printf("p2 = %p\n", p2);
  printf("p3 = %p\n", p3);
  printf("p4 = %p\n", p4);
  printf("p5 = %p\n", p5);
  printf("---------------\n");
  int *q = (int *)sbrk(0);
  brk(q + 1);
  *q = 8888;
  brk(q);
  printf("%d,%p\n", *q, q);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4,%edi
call   1050 <sbrk@plt>
mov    %rax,-0x10(%rbp)
mov    $0xc8,%edi
call   1050 <sbrk@plt>
mov    %rax,-0x18(%rbp)
xor    %edi,%edi
call   1050 <sbrk@plt>
mov    %rax,-0x20(%rbp)
mov    $0xfffffffc,%edi
call   1050 <sbrk@plt>
mov    %rax,-0x28(%rbp)
mov    $0xfffffffc,%edi
call   1050 <sbrk@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <sbrk@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
add    $0x4,%rdi
call   1040 <brk@plt>
mov    -0x38(%rbp),%rax
movl   $0x22b8,(%rax)
mov    -0x38(%rbp),%rdi
call   1040 <brk@plt>
mov    -0x38(%rbp),%rax
mov    (%rax),%esi
mov    -0x38(%rbp),%rdx
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    $0x4,%edi
call   1060 <sbrk@plt>
mov    %rax,%rbx
mov    $0xc8,%edi
call   1060 <sbrk@plt>
mov    %rax,%r12
xor    %edi,%edi
call   1060 <sbrk@plt>
mov    %rax,%r13
mov    $0xfffffffc,%edi
call   1060 <sbrk@plt>
mov    %rax,%r15
mov    $0xfffffffc,%edi
call   1060 <sbrk@plt>
mov    %rax,%r14
lea    0xe72(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe6a(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe62(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe5a(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe52(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe51(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <sbrk@plt>
mov    %rax,%rbx
lea    0x4(%rax),%rdi
call   1050 <brk@plt>
movl   $0x22b8,(%rbx)
mov    %rbx,%rdi
call   1050 <brk@plt>
mov    (%rbx),%esi
lea    0xe1b(%rip),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"p1 = %p\0A\00"
@.str.1 = [9 x i8] c"p2 = %p\0A\00"
@.str.2 = [9 x i8] c"p3 = %p\0A\00"
@.str.3 = [9 x i8] c"p4 = %p\0A\00"
@.str.4 = [9 x i8] c"p5 = %p\0A\00"
@.str.5 = [17 x i8] c"---------------\0A\00"
@.str.6 = [7 x i8] c"%d,%p\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
store i32 0, i32* %1
%8 = call i64 @sbrk(i32 4)
%9 = inttoptr i64 %8 to i32*
store i32* %9, i32** %2
%10 = call i64 @sbrk(i32 200)
%11 = inttoptr i64 %10 to i32*
store i32* %11, i32** %3
%12 = call i64 @sbrk(i32 0)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %4
%14 = call i64 @sbrk(i32 -4)
%15 = inttoptr i64 %14 to i32*
store i32* %15, i32** %5
%16 = call i64 @sbrk(i32 -4)
%17 = inttoptr i64 %16 to i32*
store i32* %17, i32** %6
%18 = load i32*, i32** %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %18)
%20 = load i32*, i32** %3
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %20)
%22 = load i32*, i32** %4
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %22)
%24 = load i32*, i32** %5
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32* %24)
%26 = load i32*, i32** %6
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32* %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%29 = call i64 @sbrk(i32 0)
%30 = inttoptr i64 %29 to i32*
store i32* %30, i32** %7
%31 = load i32*, i32** %7
%32 = getelementptr inbounds i32, i32* %31, i64 1
%33 = call i32 @brk(i32* %32)
%34 = load i32*, i32** %7
store i32 8888, i32* %34
%35 = load i32*, i32** %7
%36 = call i32 @brk(i32* %35)
%37 = load i32*, i32** %7
%38 = load i32, i32* %37
%39 = load i32*, i32** %7
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %38, i32* %39)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"p1 = %p\0A\00"
@.str.1 = [9 x i8] c"p2 = %p\0A\00"
@.str.2 = [9 x i8] c"p3 = %p\0A\00"
@.str.3 = [9 x i8] c"p4 = %p\0A\00"
@.str.4 = [9 x i8] c"p5 = %p\0A\00"
@.str.6 = [7 x i8] c"%d,%p\0A\00"
@str = [16 x i8] c"---------------\00"
define i32 @main() {
%1 = tail call i64 @sbrk(i32 4)
%2 = inttoptr i64 %1 to i32*
%3 = tail call i64 @sbrk(i32 200)
%4 = inttoptr i64 %3 to i32*
%5 = tail call i64 @sbrk(i32 0)
%6 = inttoptr i64 %5 to i32*
%7 = tail call i64 @sbrk(i32 -4)
%8 = inttoptr i64 %7 to i32*
%9 = tail call i64 @sbrk(i32 -4)
%10 = inttoptr i64 %9 to i32*
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %2)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32* %8)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32* %10)
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%17 = tail call i64 @sbrk(i32 0)
%18 = inttoptr i64 %17 to i32*
%19 = getelementptr inbounds i32, i32* %18, i64 1
%20 = tail call i32 @brk(i32* %19)
store i32 8888, i32* %18
%21 = tail call i32 @brk(i32* %18)
%22 = load i32, i32* %18
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %22, i32* %18)
ret i32 0
}