#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*/ abort();
char *sp;
int /*<<< orphan*/ write(int, char *, int);
char *_sbrk(int adj) {
  extern char end[];
  static char *heap = end;
  char *rv = heap;
  char *sp = (char *)&sp;
  if (heap + adj > sp) {
    write(1, "Heap and stack collision\n", sizeof "Heap and stack collision\n");
    abort();
  }
  heap += adj;
  return rv;
}


x86 assembly (clang, -O0):
<_sbrk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2efe(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2eeb(%rip),%rax
movslq -0x4(%rbp),%rcx
add    %rcx,%rax
cmp    -0x18(%rbp),%rax
jbe    1173 <_sbrk+0x53>
mov    $0x1,%edi
lea    0xe9e(%rip),%rsi
mov    $0x1a,%edx
call   1040 <write@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x4(%rbp),%ecx
mov    0x2eb3(%rip),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,0x2ea6(%rip)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_sbrk>:
push   %rax
mov    0x2f08(%rip),%rax
mov    %rsp,%rdx
mov    %rdx,(%rsp)
movslq %edi,%rcx
add    %rax,%rcx
cmp    %rdx,%rcx
ja     1143 <_sbrk+0x23>
mov    %rcx,0x2eef(%rip)
pop    %rcx
ret
lea    0xeb6(%rip),%rsi
mov    $0x1,%edi
mov    $0x1a,%edx
call   1040 <write@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@_sbrk.heap = internal global i8* getelementptr inbounds ([0 x i8], [0 x i8]* @end, i32 0, i32 0)
@end = external global [0 x i8]
@.str = [26 x i8] c"Heap and stack collision\0A\00"
@sp = global i8* null
define i8* @_sbrk(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i32 %0, i32* %2
%5 = load i8*, i8** @_sbrk.heap
store i8* %5, i8** %3
%6 = bitcast i8** %4 to i8*
store i8* %6, i8** %4
%7 = load i8*, i8** @_sbrk.heap
%8 = load i32, i32* %2
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = load i8*, i8** %4
%12 = icmp ugt i8* %10, %11
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = call i32 @write(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 26)
%15 = call i32 (...) @abort()
unreachable
16: ; preds = %1
%17 = load i32, i32* %2
%18 = load i8*, i8** @_sbrk.heap
%19 = sext i32 %17 to i64
%20 = getelementptr inbounds i8, i8* %18, i64 %19
store i8* %20, i8** @_sbrk.heap
%21 = load i8*, i8** %3
ret i8* %21
}

LLVM IR (-O2):
@_sbrk.heap = internal unnamed_addr global i8* getelementptr inbounds ([0 x i8], [0 x i8]* @end, i64 0, i64 0)
@end = external global [0 x i8]
@.str = [26 x i8] c"Heap and stack collision\0A\00"
@sp = global i8* null
define i8* @_sbrk(i32 %0) {
%2 = alloca i8*
%3 = load i8*, i8** @_sbrk.heap
%4 = bitcast i8** %2 to i8*
%5 = bitcast i8** %2 to i8***
store i8** %2, i8*** %5
%6 = sext i32 %0 to i64
%7 = getelementptr inbounds i8, i8* %3, i64 %6
%8 = icmp ugt i8* %7, %4
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = call i32 @write(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 26)
%11 = call i32 (...) @abort()
unreachable
12: ; preds = %1
store i8* %7, i8** @_sbrk.heap
ret i8* %3
}