#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 */
char *_obj_heap_alloc(char **heap_handle, char **stack_handle, const int size,
                      const int align_to) {
  char *heap_ptr = *heap_handle;
  char *stack_ptr = *stack_handle;
  char *address;
  heap_ptr += size;
  heap_ptr += ((unsigned long)(heap_ptr) % (align_to));
  if (heap_ptr < stack_ptr) {
    address = *heap_handle;
    *heap_handle = heap_ptr;
  } else {
    address = NULL;
  }
  return address;
}


x86 assembly (clang, -O0):
<_obj_heap_alloc>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
xor    %edx,%edx
div    %rcx
add    -0x20(%rbp),%rdx
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1177 <_obj_heap_alloc+0x77>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    117f <_obj_heap_alloc+0x7f>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<_obj_heap_alloc>:
mov    (%rdi),%r8
mov    (%rsi),%r9
movslq %edx,%rsi
add    %r8,%rsi
movslq %ecx,%r10
mov    %rsi,%rax
or     %r10,%rax
shr    $0x20,%rax
je     1125 <_obj_heap_alloc+0x25>
mov    %rsi,%rax
xor    %edx,%edx
div    %r10
jmp    112b <_obj_heap_alloc+0x2b>
mov    %esi,%eax
xor    %edx,%edx
div    %ecx
add    %rdx,%rsi
cmp    %r9,%rsi
jae    113a <_obj_heap_alloc+0x3a>
mov    %rsi,(%rdi)
mov    %r8,%rax
ret
xor    %r8d,%r8d
mov    %r8,%rax
ret

LLVM IR (-O0):
define i8* @_obj_heap_alloc(i8** %0, i8** %1, i32 %2, i32 %3) {
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
store i8** %0, i8*** %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i8**, i8*** %5
%13 = load i8*, i8** %12
store i8* %13, i8** %9
%14 = load i8**, i8*** %6
%15 = load i8*, i8** %14
store i8* %15, i8** %10
%16 = load i32, i32* %7
%17 = load i8*, i8** %9
%18 = sext i32 %16 to i64
%19 = getelementptr inbounds i8, i8* %17, i64 %18
store i8* %19, i8** %9
%20 = load i8*, i8** %9
%21 = ptrtoint i8* %20 to i64
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = urem i64 %21, %23
%25 = load i8*, i8** %9
%26 = getelementptr inbounds i8, i8* %25, i64 %24
store i8* %26, i8** %9
%27 = load i8*, i8** %9
%28 = load i8*, i8** %10
%29 = icmp ult i8* %27, %28
br i1 %29, label %30, label %35
30: ; preds = %4
%31 = load i8**, i8*** %5
%32 = load i8*, i8** %31
store i8* %32, i8** %11
%33 = load i8*, i8** %9
%34 = load i8**, i8*** %5
store i8* %33, i8** %34
br label %36
35: ; preds = %4
store i8* null, i8** %11
br label %36
36: ; preds = %35, %30
%37 = load i8*, i8** %11
ret i8* %37
}

LLVM IR (-O2):
define i8* @_obj_heap_alloc(i8** nocapture %0, i8** nocapture %1, i32 %2, i32 %3) {
%5 = load i8*, i8** %0
%6 = load i8*, i8** %1
%7 = sext i32 %2 to i64
%8 = getelementptr inbounds i8, i8* %5, i64 %7
%9 = ptrtoint i8* %8 to i64
%10 = sext i32 %3 to i64
%11 = urem i64 %9, %10
%12 = getelementptr inbounds i8, i8* %8, i64 %11
%13 = icmp ult i8* %12, %6
br i1 %13, label %14, label %15
14: ; preds = %4
store i8* %12, i8** %0
br label %15
15: ; preds = %4, %14
%16 = phi i8* [ %5, %14 ], [ null, %4 ]
ret i8* %16
}