#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 */
typedef void uint8_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int brk(void *);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int /*<<< orphan*/ printf(char *, void *, ...);
void *sbrk(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int);
int main(int argc, char *argv[]) {
  void *addr_a, *addr_b, *addr_c;
  intptr_t size_incr = 32;
  if ((addr_a = sbrk(0)) == (void *)-1) {
    fprintf(stderr, "Err.(%d) sbrk(0): %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  printf("%p - Current program break address (starting program) \n", addr_a);
  if (brk(((uint8_t *)addr_a + size_incr)) == -1) {
    fprintf(stderr, "Err.(%d) brk(): %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  if ((addr_b = sbrk(0)) == (void *)-1) {
    fprintf(stderr, "Err.(%d) sbrk(0): %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  printf("%p - Current program break address (after %d byte allocation) \n",
         addr_b, size_incr);
  if (brk(addr_a) == -1) {
    fprintf(stderr, "Err.(%d) brk(): %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  if ((addr_c = sbrk(0)) == (void *)-1) {
    fprintf(stderr, "Err.(%d) sbrk(0): %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  printf("%p - Current program break address (after %d byte deallocation)\n",
         addr_c, size_incr);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x20,-0x30(%rbp)
xor    %edi,%edi
call   1050 <sbrk@plt>
mov    %rax,-0x18(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    11e2 <main+0x82>
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2e2c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    -0x34(%rbp),%edx
mov    %rax,%rcx
lea    0xe31(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rsi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
add    -0x30(%rbp),%rdi
call   1040 <brk@plt>
cmp    $0xffffffff,%eax
jne    1253 <main+0xf3>
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2dbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x40(%rbp),%edi
mov    -0x3c(%rbp),%edx
mov    %rax,%rcx
lea    0xe0e(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
xor    %edi,%edi
call   1050 <sbrk@plt>
mov    %rax,-0x20(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    12b7 <main+0x157>
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2d57(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    -0x44(%rbp),%edx
mov    %rax,%rcx
lea    0xd5c(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <brk@plt>
cmp    $0xffffffff,%eax
jne    1328 <main+0x1c8>
mov    0x2cfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    0x2ce6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x50(%rbp),%edi
mov    -0x4c(%rbp),%edx
mov    %rax,%rcx
lea    0xd39(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2caf(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
xor    %edi,%edi
call   1050 <sbrk@plt>
mov    %rax,-0x28(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    138c <main+0x22c>
mov    0x2c96(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    0x2c82(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    0x2c76(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x58(%rbp),%edi
mov    -0x54(%rbp),%edx
mov    %rax,%rcx
lea    0xc87(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2c4b(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xd07(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2c1f(%rip),%rax
mov    (%rax),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %edi,%edi
call   1050 <sbrk@plt>
cmp    $0xffffffffffffffff,%rax
je     1200 <main+0xa0>
mov    %rax,%rbx
lea    0xe98(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
add    $0x20,%rdi
call   1040 <brk@plt>
cmp    $0xffffffff,%eax
je     1222 <main+0xc2>
xor    %edi,%edi
call   1050 <sbrk@plt>
cmp    $0xffffffffffffffff,%rax
je     1200 <main+0xa0>
lea    0xeb1(%rip),%rdi
mov    $0x20,%edx
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1040 <brk@plt>
cmp    $0xffffffff,%eax
je     1222 <main+0xc2>
xor    %edi,%edi
call   1050 <sbrk@plt>
cmp    $0xffffffffffffffff,%rax
je     1200 <main+0xa0>
lea    0xec1(%rip),%rdi
mov    $0x20,%edx
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2dd9(%rip),%rax
mov    (%rax),%ebx
mov    0x2dc8(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1080 <strerror@plt>
lea    0xde0(%rip),%rsi
jmp    1242 <main+0xe2>
mov    0x2db7(%rip),%rax
mov    (%rax),%ebx
mov    0x2da6(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1080 <strerror@plt>
lea    0xe0c(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
call   1060 <fprintf@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"Err.(%d) sbrk(0): %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [56 x i8] c"%p - Current program break address (starting program) \0A\00"
@.str.2 = [20 x i8] c"Err.(%d) brk(): %s\0A\00"
@.str.3 = [64 x i8] c"%p - Current program break address (after %d byte allocation) \0A\00"
@.str.4 = [65 x i8] c"%p - Current program break address (after %d byte deallocation)\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 32, i64* %9
%10 = call i8* @sbrk(i32 0)
store i8* %10, i8** %6
%11 = icmp eq i8* %10, inttoptr (i64 -1 to i8*)
br i1 %11, label %12, label %20
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %14, i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = load i8*, i8** %6
%22 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %6
%24 = load i64, i64* %9
%25 = getelementptr i8, i8* %23, i64 %24
%26 = call i32 @brk(i8* %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %36
28: ; preds = %20
%29 = load i32, i32* @stderr
%30 = load i32, i32* @errno
%31 = load i32, i32* @errno
%32 = call i8* @strerror(i32 %31)
%33 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %30, i8* %32)
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %20
%37 = call i8* @sbrk(i32 0)
store i8* %37, i8** %7
%38 = icmp eq i8* %37, inttoptr (i64 -1 to i8*)
br i1 %38, label %39, label %47
39: ; preds = %36
%40 = load i32, i32* @stderr
%41 = load i32, i32* @errno
%42 = load i32, i32* @errno
%43 = call i8* @strerror(i32 %42)
%44 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %41, i8* %43)
%45 = load i32, i32* @EXIT_FAILURE
%46 = call i32 @exit(i32 %45)
unreachable
47: ; preds = %36
%48 = load i8*, i8** %7
%49 = load i64, i64* %9
%50 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0), i8* %48, i64 %49)
%51 = load i8*, i8** %6
%52 = call i32 @brk(i8* %51)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %62
54: ; preds = %47
%55 = load i32, i32* @stderr
%56 = load i32, i32* @errno
%57 = load i32, i32* @errno
%58 = call i8* @strerror(i32 %57)
%59 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %56, i8* %58)
%60 = load i32, i32* @EXIT_FAILURE
%61 = call i32 @exit(i32 %60)
unreachable
62: ; preds = %47
%63 = call i8* @sbrk(i32 0)
store i8* %63, i8** %8
%64 = icmp eq i8* %63, inttoptr (i64 -1 to i8*)
br i1 %64, label %65, label %73
65: ; preds = %62
%66 = load i32, i32* @stderr
%67 = load i32, i32* @errno
%68 = load i32, i32* @errno
%69 = call i8* @strerror(i32 %68)
%70 = call i32 @fprintf(i32 %66, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %67, i8* %69)
%71 = load i32, i32* @EXIT_FAILURE
%72 = call i32 @exit(i32 %71)
unreachable
73: ; preds = %62
%74 = load i8*, i8** %8
%75 = load i64, i64* %9
%76 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.4, i64 0, i64 0), i8* %74, i64 %75)
%77 = load i32, i32* @EXIT_SUCCESS
ret i32 %77
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"Err.(%d) sbrk(0): %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [56 x i8] c"%p - Current program break address (starting program) \0A\00"
@.str.2 = [20 x i8] c"Err.(%d) brk(): %s\0A\00"
@.str.3 = [64 x i8] c"%p - Current program break address (after %d byte allocation) \0A\00"
@.str.4 = [65 x i8] c"%p - Current program break address (after %d byte deallocation)\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i8* @sbrk(i32 0)
%4 = icmp eq i8* %3, inttoptr (i64 -1 to i8*)
br i1 %4, label %5, label %12
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %7, i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%14 = getelementptr i8, i8* %3, i64 32
%15 = tail call i32 @brk(i8* %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %24
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %19, i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %12
%25 = tail call i8* @sbrk(i32 0)
%26 = icmp eq i8* %25, inttoptr (i64 -1 to i8*)
br i1 %26, label %27, label %34
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = load i32, i32* @errno
%30 = tail call i8* @strerror(i32 %29)
%31 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %29, i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = tail call i32 @exit(i32 %32)
unreachable
34: ; preds = %24
%35 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0), i8* %25, i64 32)
%36 = tail call i32 @brk(i8* %3)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %45
38: ; preds = %34
%39 = load i32, i32* @stderr
%40 = load i32, i32* @errno
%41 = tail call i8* @strerror(i32 %40)
%42 = tail call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %40, i8* %41)
%43 = load i32, i32* @EXIT_FAILURE
%44 = tail call i32 @exit(i32 %43)
unreachable
45: ; preds = %34
%46 = tail call i8* @sbrk(i32 0)
%47 = icmp eq i8* %46, inttoptr (i64 -1 to i8*)
br i1 %47, label %48, label %55
48: ; preds = %45
%49 = load i32, i32* @stderr
%50 = load i32, i32* @errno
%51 = tail call i8* @strerror(i32 %50)
%52 = tail call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %50, i8* %51)
%53 = load i32, i32* @EXIT_FAILURE
%54 = tail call i32 @exit(i32 %53)
unreachable
55: ; preds = %45
%56 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.4, i64 0, i64 0), i8* %46, i64 32)
%57 = load i32, i32* @EXIT_SUCCESS
ret i32 %57
}