#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*/ ENOMEM;
int /*<<< orphan*/ errno;
void *_sbrk(int nbytes) {
  extern int ___heap_start;
  extern int ___heap_end;
  static void *heap_ptr = (void *)&___heap_start;
  if ((heap_ptr + nbytes) < (void *)&___heap_end) {
    void *base = heap_ptr;
    heap_ptr += nbytes;
    return base;
  } else {
    errno = ENOMEM;
    return (void *)-1;
  }
}


x86 assembly (clang, -O0):
<_sbrk>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
mov    0x2f12(%rip),%rax
movslq -0xc(%rbp),%rcx
add    %rcx,%rax
mov    0x2ebc(%rip),%rcx
cmp    %rcx,%rax
jae    1154 <_sbrk+0x54>
mov    0x2ef4(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%ecx
mov    0x2ee6(%rip),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,0x2ed9(%rip)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1171 <_sbrk+0x71>
mov    0x2e85(%rip),%rax
mov    (%rax),%ecx
mov    0x2e6c(%rip),%rax
mov    %ecx,(%rax)
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<_sbrk>:
mov    0x2f19(%rip),%rax
movslq %edi,%rcx
add    %rax,%rcx
cmp    0x2ec4(%rip),%rcx
jae    111e <_sbrk+0x1e>
mov    %rcx,0x2f03(%rip)
ret
mov    0x2ebb(%rip),%rax
mov    (%rax),%eax
mov    0x2ea2(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffffffffffff,%rax
ret

LLVM IR (-O0):
@_sbrk.heap_ptr = internal global i8* bitcast (i32* @___heap_start to i8*)
@___heap_start = external global i32
@___heap_end = external global i32
@ENOMEM = global i32 0
@errno = global i32 0
define i8* @_sbrk(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
%5 = load i8*, i8** @_sbrk.heap_ptr
%6 = load i32, i32* %3
%7 = sext i32 %6 to i64
%8 = getelementptr i8, i8* %5, i64 %7
%9 = icmp ult i8* %8, bitcast (i32* @___heap_end to i8*)
br i1 %9, label %10, label %17
10: ; preds = %1
%11 = load i8*, i8** @_sbrk.heap_ptr
store i8* %11, i8** %4
%12 = load i32, i32* %3
%13 = load i8*, i8** @_sbrk.heap_ptr
%14 = sext i32 %12 to i64
%15 = getelementptr i8, i8* %13, i64 %14
store i8* %15, i8** @_sbrk.heap_ptr
%16 = load i8*, i8** %4
store i8* %16, i8** %2
br label %19
17: ; preds = %1
%18 = load i32, i32* @ENOMEM
store i32 %18, i32* @errno
store i8* inttoptr (i64 -1 to i8*), i8** %2
br label %19
19: ; preds = %17, %10
%20 = load i8*, i8** %2
ret i8* %20
}

LLVM IR (-O2):
@_sbrk.heap_ptr = internal unnamed_addr global i8* bitcast (i32* @___heap_start to i8*)
@___heap_start = external global i32
@___heap_end = external global i32
@ENOMEM = global i32 0
@errno = global i32 0
define i8* @_sbrk(i32 %0) {
%2 = load i8*, i8** @_sbrk.heap_ptr
%3 = sext i32 %0 to i64
%4 = getelementptr i8, i8* %2, i64 %3
%5 = icmp ult i8* %4, bitcast (i32* @___heap_end to i8*)
br i1 %5, label %6, label %7
6: ; preds = %1
store i8* %4, i8** @_sbrk.heap_ptr
br label %9
7: ; preds = %1
%8 = load i32, i32* @ENOMEM
store i32 %8, i32* @errno
br label %9
9: ; preds = %7, %6
%10 = phi i8* [ %2, %6 ], [ inttoptr (i64 -1 to i8*), %7 ]
ret i8* %10
}