#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 int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int brk(int /*<<< orphan*/ *);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, int);
void *sbrk(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int);
intptr_t strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  void *pb_old_addr, *pb_cur_addr;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <size>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  intptr_t size_incr = strtol(argv[1], NULL, 10);
  if ((pb_old_addr = sbrk(0)) == (void *)-1) {
    fprintf(stderr, "Err.(%d) old sbrk(0): %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (brk(((uint8_t *)pb_old_addr + size_incr)) == -1) {
    fprintf(stderr, "Err.(%d) brk(): %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  if ((pb_cur_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_cur_addr);
  printf("                 Allocated memory: %d byte\n",
         ((int)pb_cur_addr - (int)pb_old_addr));
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11bc <main+0x4c>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,-0x28(%rbp)
xor    %edi,%edi
call   1050 <sbrk@plt>
mov    %rax,-0x18(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    123c <main+0xcc>
mov    0x2de8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%edx
mov    %rax,%rcx
lea    0xdeb(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
call   1040 <brk@plt>
cmp    $0xffffffff,%eax
jne    12a4 <main+0x134>
mov    0x2d80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    -0x34(%rbp),%edx
mov    %rax,%rcx
lea    0xd9d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
xor    %edi,%edi
call   1050 <sbrk@plt>
mov    %rax,-0x20(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    130a <main+0x19a>
mov    0x2d1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2d06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x40(%rbp),%edi
mov    -0x3c(%rbp),%edx
mov    %rax,%rcx
lea    0xd4b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %eax,%esi
lea    0xd43(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %eax,%esi
lea    0xd58(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rax
sub    %eax,%esi
lea    0xd67(%rip),%rdi
call   1030 <printf@plt>
mov    0x2c7b(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    1206 <main+0x96>
mov    0x8(%rsi),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,%rbx
xor    %edi,%edi
call   1050 <sbrk@plt>
cmp    $0xffffffffffffffff,%rax
je     1222 <main+0xb2>
mov    %rax,%r14
lea    (%rax,%rbx,4),%rdi
call   1040 <brk@plt>
cmp    $0xffffffff,%eax
je     1244 <main+0xd4>
xor    %edi,%edi
call   1050 <sbrk@plt>
cmp    $0xffffffffffffffff,%rax
je     1266 <main+0xf6>
mov    %rax,%rbx
lea    0xe89(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
lea    0xea1(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
sub    %r14d,%ebx
lea    0xeb7(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    0x2dc9(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xde7(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1294 <main+0x124>
mov    0x2db7(%rip),%rax
mov    (%rax),%ebx
mov    0x2da6(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1090 <strerror@plt>
lea    0xdd0(%rip),%rsi
jmp    1286 <main+0x116>
mov    0x2d95(%rip),%rax
mov    (%rax),%ebx
mov    0x2d84(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1090 <strerror@plt>
lea    0xdc8(%rip),%rsi
jmp    1286 <main+0x116>
mov    0x2d73(%rip),%rax
mov    (%rax),%ebx
mov    0x2d62(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1090 <strerror@plt>
lea    0xdba(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s <size>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [26 x i8] c"Err.(%d) old sbrk(0): %s\0A\00"
@errno = global i32 0
@.str.2 = [20 x i8] c"Err.(%d) brk(): %s\0A\00"
@.str.3 = [26 x i8] c"Err.(%d) cur sbrk(0): %s\0A\00"
@.str.4 = [39 x i8] c" (old) 'program break' address: %p\0A\00"
@.str.5 = [39 x i8] c"(current) 'program break' address: %p\0A\00"
@.str.6 = [44 x i8] c" Allocated memory: %d byte\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 i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @strtol(i8* %22, i32* null, i32 10)
store i64 %23, i64* %8
%24 = call i8* @sbrk(i32 0)
store i8* %24, i8** %6
%25 = icmp eq i8* %24, inttoptr (i64 -1 to i8*)
br i1 %25, label %26, label %34
26: ; preds = %19
%27 = load i32, i32* @stderr
%28 = load i32, i32* @errno
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %28, i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %19
%35 = load i8*, i8** %6
%36 = bitcast i8* %35 to i32*
%37 = load i64, i64* %8
%38 = getelementptr inbounds i32, i32* %36, i64 %37
%39 = call i32 @brk(i32* %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %49
41: ; preds = %34
%42 = load i32, i32* @stderr
%43 = load i32, i32* @errno
%44 = load i32, i32* @errno
%45 = call i8* @strerror(i32 %44)
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %43, i8* %45)
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %34
%50 = call i8* @sbrk(i32 0)
store i8* %50, i8** %7
%51 = icmp eq i8* %50, inttoptr (i64 -1 to i8*)
br i1 %51, label %52, label %60
52: ; preds = %49
%53 = load i32, i32* @stderr
%54 = load i32, i32* @errno
%55 = load i32, i32* @errno
%56 = call i8* @strerror(i32 %55)
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %54, i8* %56)
%58 = load i32, i32* @EXIT_FAILURE
%59 = call i32 @exit(i32 %58)
unreachable
60: ; preds = %49
%61 = load i8*, i8** %6
%62 = ptrtoint i8* %61 to i32
%63 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %62)
%64 = load i8*, i8** %7
%65 = ptrtoint i8* %64 to i32
%66 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i32 %65)
%67 = load i8*, i8** %7
%68 = ptrtoint i8* %67 to i32
%69 = load i8*, i8** %6
%70 = ptrtoint i8* %69 to i32
%71 = sub nsw i32 %68, %70
%72 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), i32 %71)
%73 = load i32, i32* @EXIT_SUCCESS
ret i32 %73
}

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