#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 */
struct ParseState {
  int dummy;
};

/* Variables and functions */
void *HeapAllocMem(int);
void *HeapAllocStack(int);
int /*<<< orphan*/ ProgramFail(struct ParseState *, char *);
void *VariableAlloc(struct ParseState *Parser, int Size, int OnHeap) {
  void *NewValue;
  if (OnHeap)
    NewValue = HeapAllocMem(Size);
  else
    NewValue = HeapAllocStack(Size);
  if (NewValue == 0)
    ProgramFail(Parser, "me quede sin memoria x_x");
  return NewValue;
}


x86 assembly (clang, -O0):
<VariableAlloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     115d <VariableAlloc+0x2d>
mov    -0xc(%rbp),%edi
call   1030 <HeapAllocMem@plt>
mov    %rax,-0x18(%rbp)
jmp    1169 <VariableAlloc+0x39>
mov    -0xc(%rbp),%edi
call   1050 <HeapAllocStack@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1184 <VariableAlloc+0x54>
mov    -0x8(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1040 <ProgramFail@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<VariableAlloc>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %esi,%edi
test   %edx,%edx
je     1144 <VariableAlloc+0x14>
call   1030 <HeapAllocMem@plt>
jmp    1149 <VariableAlloc+0x19>
call   1050 <HeapAllocStack@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1160 <VariableAlloc+0x30>
lea    0xea8(%rip),%rsi
mov    %r14,%rdi
call   1040 <ProgramFail@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.ParseState = type { i32 }
@.str = [25 x i8] c"me quede sin memoria x_x\00"
define i8* @VariableAlloc(%struct.ParseState* %0, i32 %1, i32 %2) {
%4 = alloca %struct.ParseState*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store %struct.ParseState* %0, %struct.ParseState** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %6
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load i32, i32* %5
%12 = call i8* @HeapAllocMem(i32 %11)
store i8* %12, i8** %7
br label %16
13: ; preds = %3
%14 = load i32, i32* %5
%15 = call i8* @HeapAllocStack(i32 %14)
store i8* %15, i8** %7
br label %16
16: ; preds = %13, %10
%17 = load i8*, i8** %7
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load %struct.ParseState*, %struct.ParseState** %4
%21 = call i32 @ProgramFail(%struct.ParseState* %20, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %19, %16
%23 = load i8*, i8** %7
ret i8* %23
}

LLVM IR (-O2):
%struct.ParseState = type { i32 }
@.str = [25 x i8] c"me quede sin memoria x_x\00"
define i8* @VariableAlloc(%struct.ParseState* %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %7, label %5
5: ; preds = %3
%6 = tail call i8* @HeapAllocMem(i32 %1)
br label %9
7: ; preds = %3
%8 = tail call i8* @HeapAllocStack(i32 %1)
br label %9
9: ; preds = %7, %5
%10 = phi i8* [ %6, %5 ], [ %8, %7 ]
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @ProgramFail(%struct.ParseState* %0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %9
ret i8* %10
}