#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 /*<<< orphan*/ assert(int);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
void *sbrk(size_t);
int /*<<< orphan*/ stderr;
char *strerror(int);
void *basic_malloc(size_t size) {
  void *ptr = sbrk(0);
  void *increment = sbrk(size);
  if (increment == (void *)-1) {
    fprintf(stderr, "Err.(%d) sbrk(): %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  } else {
    assert(ptr == increment);
    return ptr;
  }
}


x86 assembly (clang, -O0):
<basic_malloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1030 <sbrk@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <sbrk@plt>
mov    %rax,-0x18(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x18(%rbp)
jne    11d0 <basic_malloc+0x80>
mov    0x2e52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%edx
mov    %rax,%rcx
lea    0xe43(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<basic_malloc>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %edi,%edi
call   1030 <sbrk@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <sbrk@plt>
cmp    $0xffffffffffffffff,%rax
je     1185 <basic_malloc+0x35>
xor    %edi,%edi
cmp    %rax,%rbx
sete   %dil
call   1040 <assert@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e54(%rip),%rax
mov    (%rax),%ebx
mov    0x2e43(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1070 <strerror@plt>
lea    0xe5b(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [21 x i8] c"Err.(%d) sbrk(): %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i8* @basic_malloc(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i8*
store i64 %0, i64* %2
%5 = call i8* @sbrk(i64 0)
store i8* %5, i8** %3
%6 = load i64, i64* %2
%7 = call i8* @sbrk(i64 %6)
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, inttoptr (i64 -1 to i8*)
br i1 %9, label %10, label %18
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %12, i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %1
%19 = load i8*, i8** %3
%20 = load i8*, i8** %4
%21 = icmp eq i8* %19, %20
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = load i8*, i8** %3
ret i8* %24
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"Err.(%d) sbrk(): %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i8* @basic_malloc(i64 %0) {
%2 = tail call i8* @sbrk(i64 0)
%3 = tail call i8* @sbrk(i64 %0)
%4 = icmp eq i8* %3, inttoptr (i64 -1 to i8*)
br i1 %4, label %5, label %12
5: ; preds = %1
%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 ([21 x i8], [21 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 = %1
%13 = icmp eq i8* %2, %3
%14 = zext i1 %13 to i32
%15 = tail call i32 @assert(i32 %14)
ret i8* %2
}