#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 */
void *gc_alloc_space(int);
int /*<<< orphan*/ gc_clear_mark();
int /*<<< orphan*/ gc_mark();
int /*<<< orphan*/ printf(char *);
void *gc_alloc(int size) {
  void *o = gc_alloc_space(size);
  if (NULL == o) {
    gc_clear_mark();
    gc_mark();
    o = gc_alloc_space(size);
    if (o == NULL) {
      if (1)
        printf("memory is full");
      return NULL;
    }
  }
  return o;
}


x86 assembly (clang, -O0):
<gc_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <gc_alloc_space@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    11a6 <gc_alloc+0x66>
mov    $0x0,%al
call   1050 <gc_clear_mark@plt>
mov    $0x0,%al
call   1030 <gc_mark@plt>
mov    -0xc(%rbp),%edi
call   1060 <gc_alloc_space@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a1 <gc_alloc+0x61>
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ae <gc_alloc+0x6e>
jmp    11a6 <gc_alloc+0x66>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gc_alloc>:
push   %rbx
mov    %edi,%ebx
call   1060 <gc_alloc_space@plt>
test   %rax,%rax
je     114f <gc_alloc+0xf>
pop    %rbx
ret
xor    %eax,%eax
call   1050 <gc_clear_mark@plt>
xor    %eax,%eax
call   1030 <gc_mark@plt>
mov    %ebx,%edi
call   1060 <gc_alloc_space@plt>
test   %rax,%rax
jne    114d <gc_alloc+0xd>
lea    0xe90(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"memory is full\00"
define i8* @gc_alloc(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i8* @gc_alloc_space(i32 %5)
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp eq i8* null, %7
br i1 %8, label %9, label %19
9: ; preds = %1
%10 = call i32 (...) @gc_clear_mark()
%11 = call i32 (...) @gc_mark()
%12 = load i32, i32* %3
%13 = call i8* @gc_alloc_space(i32 %12)
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %21
18: ; preds = %9
br label %19
19: ; preds = %18, %1
%20 = load i8*, i8** %4
store i8* %20, i8** %2
br label %21
21: ; preds = %19, %16
%22 = load i8*, i8** %2
ret i8* %22
}

LLVM IR (-O2):
@.str = [15 x i8] c"memory is full\00"
define i8* @gc_alloc(i32 %0) {
%2 = tail call i8* @gc_alloc_space(i32 %0)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %11
4: ; preds = %1
%5 = tail call i32 (...) @gc_clear_mark()
%6 = tail call i32 (...) @gc_mark()
%7 = tail call i8* @gc_alloc_space(i32 %0)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %1, %4, %9
%12 = phi i8* [ null, %9 ], [ %7, %4 ], [ %2, %1 ]
ret i8* %12
}