#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 */
scalar_t__ EINVAL;
scalar_t__ ENOMEM;
scalar_t__ calloc(int, unsigned int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned int);
int /*<<< orphan*/ nrerror(char *);
int /*<<< orphan*/ stderr;
void *space(unsigned size) {
  void *pointer;
  if ((pointer = (void *)calloc(1, size)) == NULL) {
    if (errno == EINVAL) {
      fprintf(stderr, "SPACE: requested size: %d\n", size);
      nrerror("SPACE allocation failure -> EINVAL");
    }
    if (errno == ENOMEM)
      nrerror("SPACE allocation failure -> no memory");
  }
  return pointer;
}


x86 assembly (clang, -O0):
<space>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%esi
mov    $0x1,%edi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11bf <space+0x8f>
mov    0x2e73(%rip),%rax
mov    (%rax),%rax
mov    0x2e61(%rip),%rcx
cmp    (%rcx),%rax
jne    1194 <space+0x64>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe7d(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe8c(%rip),%rdi
call   1030 <nrerror@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%rax
mov    0x2e3b(%rip),%rcx
cmp    (%rcx),%rax
jne    11ba <space+0x8a>
lea    0xe89(%rip),%rdi
call   1030 <nrerror@plt>
jmp    11bf <space+0x8f>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<space>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
mov    $0x1,%edi
mov    %ebp,%esi
call   1040 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    119e <space+0x6e>
mov    0x2e7f(%rip),%r14
mov    (%r14),%rax
mov    0x2e6d(%rip),%rcx
cmp    (%rcx),%rax
jne    1186 <space+0x56>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    0xe90(%rip),%rsi
mov    %ebp,%edx
call   1050 <fprintf@plt>
lea    0xe9d(%rip),%rdi
call   1030 <nrerror@plt>
mov    (%r14),%rax
mov    0x2e53(%rip),%rcx
cmp    (%rcx),%rax
jne    119e <space+0x6e>
lea    0xea5(%rip),%rdi
call   1030 <nrerror@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EINVAL = global i64 0
@stderr = global i32 0
@.str = [27 x i8] c"SPACE: requested size: %d\0A\00"
@.str.1 = [35 x i8] c"SPACE allocation failure -> EINVAL\00"
@ENOMEM = global i64 0
@.str.2 = [38 x i8] c"SPACE allocation failure -> no memory\00"
define i8* @space(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i64 @calloc(i32 1, i32 %4)
%6 = inttoptr i64 %5 to i8*
store i8* %6, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %24
8: ; preds = %1
%9 = load i64, i64* @errno
%10 = load i64, i64* @EINVAL
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = load i32, i32* %2
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = call i32 @nrerror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %12, %8
%18 = load i64, i64* @errno
%19 = load i64, i64* @ENOMEM
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @nrerror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %17
br label %24
24: ; preds = %23, %1
%25 = load i8*, i8** %3
ret i8* %25
}

LLVM IR (-O2):
@errno = global i64 0
@EINVAL = global i64 0
@stderr = global i32 0
@.str = [27 x i8] c"SPACE: requested size: %d\0A\00"
@.str.1 = [35 x i8] c"SPACE allocation failure -> EINVAL\00"
@ENOMEM = global i64 0
@.str.2 = [38 x i8] c"SPACE allocation failure -> no memory\00"
define i8* @space(i32 %0) {
%2 = tail call i64 @calloc(i32 1, i32 %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %19
4: ; preds = %1
%5 = load i64, i64* @errno
%6 = load i64, i64* @EINVAL
%7 = icmp eq i64 %5, %6
br i1 %7, label %8, label %13
8: ; preds = %4
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %0)
%11 = tail call i32 @nrerror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%12 = load i64, i64* @errno
br label %13
13: ; preds = %8, %4
%14 = phi i64 [ %12, %8 ], [ %5, %4 ]
%15 = load i64, i64* @ENOMEM
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = tail call i32 @nrerror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %13, %17, %1
%20 = inttoptr i64 %2 to i8*
ret i8* %20
}