#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int /*<<< orphan*/ printf(char *, void *);
void *sbrk(intptr_t const);
int /*<<< orphan*/ stderr;
char *strerror(int);
int main(void) {
  static const intptr_t size_incr = 15;
  void *pb_old_addr, *pb_current_addr;
  if ((pb_old_addr = sbrk(0)) == (void *)-1) {
    fprintf(stderr, "Err.(%d) old sbrk(0): %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (sbrk(size_incr) == (void *)-1) {
    fprintf(stderr, "Err.(%d) sbrk(): %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  if ((pb_current_addr = sbrk(0)) == (void *)-1) {
    fprintf(stderr, "Err.(%d) cur sbrk(0): %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  printf("    (old) 'program break' address: %p\n", pb_old_addr);
  printf("(current) 'program break' address: %p\n", pb_current_addr);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <sbrk@plt>
mov    %rax,-0x10(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    11c5 <main+0x75>
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%edx
mov    %rax,%rcx
lea    0xe56(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    $0xf,%edi
call   1040 <sbrk@plt>
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    1228 <main+0xd8>
mov    0x2dfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2de6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%edx
mov    %rax,%rcx
lea    0xe0d(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <sbrk@plt>
mov    %rax,-0x18(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    128e <main+0x13e>
mov    0x2d94(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%edx
mov    %rax,%rcx
lea    0xdbc(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rsi
lea    0xdb8(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xdcf(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d13(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %edi,%edi
call   1040 <sbrk@plt>
cmp    $0xffffffffffffffff,%rax
je     11b0 <main+0x60>
mov    %rax,%r14
mov    $0xf,%edi
call   1040 <sbrk@plt>
cmp    $0xffffffffffffffff,%rax
je     11d2 <main+0x82>
xor    %edi,%edi
call   1040 <sbrk@plt>
cmp    $0xffffffffffffffff,%rax
je     11f4 <main+0xa4>
mov    %rax,%rbx
lea    0xebe(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
lea    0xed6(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e29(%rip),%rax
mov    (%rax),%ebx
mov    0x2e18(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1070 <strerror@plt>
lea    0xe30(%rip),%rsi
jmp    1214 <main+0xc4>
mov    0x2e07(%rip),%rax
mov    (%rax),%ebx
mov    0x2df6(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1070 <strerror@plt>
lea    0xe28(%rip),%rsi
jmp    1214 <main+0xc4>
mov    0x2de5(%rip),%rax
mov    (%rax),%ebx
mov    0x2dd4(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1070 <strerror@plt>
lea    0xe1b(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@main.size_incr = internal constant i64 15
@stderr = global i32 0
@.str = [26 x i8] c"Err.(%d) old sbrk(0): %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [21 x i8] c"Err.(%d) sbrk(): %s\0A\00"
@.str.2 = [26 x i8] c"Err.(%d) cur sbrk(0): %s\0A\00"
@.str.3 = [39 x i8] c" (old) 'program break' address: %p\0A\00"
@.str.4 = [39 x i8] c"(current) 'program break' address: %p\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i8* @sbrk(i64 0)
store i8* %4, i8** %2
%5 = icmp eq i8* %4, inttoptr (i64 -1 to i8*)
br i1 %5, label %6, label %14
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = load i32, i32* @errno
%10 = call i8* @strerror(i32 %9)
%11 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %8, i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %0
%15 = call i8* @sbrk(i64 15)
%16 = icmp eq i8* %15, inttoptr (i64 -1 to i8*)
br i1 %16, label %17, label %25
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = load i32, i32* @errno
%21 = call i8* @strerror(i32 %20)
%22 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %19, i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %14
%26 = call i8* @sbrk(i64 0)
store i8* %26, i8** %3
%27 = icmp eq i8* %26, inttoptr (i64 -1 to i8*)
br i1 %27, label %28, label %36
28: ; preds = %25
%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 ([26 x i8], [26 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 = %25
%37 = load i8*, i8** %2
%38 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %37)
%39 = load i8*, i8** %3
%40 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8* %39)
%41 = load i32, i32* @EXIT_SUCCESS
ret i32 %41
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"Err.(%d) old sbrk(0): %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [21 x i8] c"Err.(%d) sbrk(): %s\0A\00"
@.str.2 = [26 x i8] c"Err.(%d) cur sbrk(0): %s\0A\00"
@.str.3 = [39 x i8] c" (old) 'program break' address: %p\0A\00"
@.str.4 = [39 x i8] c"(current) 'program break' address: %p\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i8* @sbrk(i64 0)
%2 = icmp eq i8* %1, inttoptr (i64 -1 to i8*)
br i1 %2, label %3, label %10
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = load i32, i32* @errno
%6 = tail call i8* @strerror(i32 %5)
%7 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %5, i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %0
%11 = tail call i8* @sbrk(i64 15)
%12 = icmp eq i8* %11, inttoptr (i64 -1 to i8*)
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = tail call i8* @strerror(i32 %15)
%17 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %15, i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %10
%21 = tail call i8* @sbrk(i64 0)
%22 = icmp eq i8* %21, inttoptr (i64 -1 to i8*)
br i1 %22, label %23, label %30
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = load i32, i32* @errno
%26 = tail call i8* @strerror(i32 %25)
%27 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %25, i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = tail call i32 @exit(i32 %28)
unreachable
30: ; preds = %20
%31 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%32 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8* %21)
%33 = load i32, i32* @EXIT_SUCCESS
ret i32 %33
}