#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 *_get_from_sar_array(long);
char *_get_new_sar(long, long);
int /*<<< orphan*/ init_PR_var();
long s_align_to(long);
long s_align_to_page(long);
void *shalloc(long size) {
  long align_size;
  char *ret;
  if (size <= 0)
    return (void *)0;
  size = s_align_to_page(size);
  align_size = s_align_to(size);
  if ((long)(*(long *)(0x200100000)) == 0) {
    init_PR_var();
    ret = _get_new_sar(size, align_size);
  } else {
    ret = _get_from_sar_array(size);
    if (ret == (char *)0) {
      if ((long)((*(long *)(0x300003000)) + 24) < (long)(0x300183008)) {
        *(long *)(0x300003000) = (*(long *)(0x300003000)) + 24;
        ret = _get_new_sar(size, align_size);
      } else
        ret = (char *)0;
    }
  }
  return (void *)ret;
}


x86 assembly (clang, -O0):
<shalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jg     1174 <shalloc+0x24>
movq   $0x0,-0x8(%rbp)
jmp    1249 <shalloc+0xf9>
mov    -0x10(%rbp),%rdi
call   1030 <s_align_to_page@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <s_align_to@plt>
mov    %rax,-0x18(%rbp)
movabs $0x200100000,%rax
cmpq   $0x0,(%rax)
jne    11bf <shalloc+0x6f>
mov    $0x0,%al
call   1040 <init_PR_var@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <_get_new_sar@plt>
mov    %rax,-0x20(%rbp)
jmp    1241 <shalloc+0xf1>
mov    -0x10(%rbp),%rdi
call   1060 <_get_from_sar_array@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    123c <shalloc+0xec>
movabs $0x300003000,%rax
mov    (%rax),%rax
add    $0x18,%rax
movabs $0x300183008,%rcx
cmp    %rcx,%rax
jge    122f <shalloc+0xdf>
movabs $0x300003000,%rax
mov    (%rax),%rcx
add    $0x18,%rcx
movabs $0x300003000,%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <_get_new_sar@plt>
mov    %rax,-0x20(%rbp)
jmp    1237 <shalloc+0xe7>
movq   $0x0,-0x20(%rbp)
jmp    123c <shalloc+0xec>
jmp    1241 <shalloc+0xf1>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shalloc>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
jle    11ab <shalloc+0x5b>
call   1030 <s_align_to_page@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <s_align_to@plt>
mov    %rax,%r14
movabs $0x200100000,%rax
cmpq   $0x0,(%rax)
je     11b5 <shalloc+0x65>
mov    %rbx,%rdi
call   1060 <_get_from_sar_array@plt>
test   %rax,%rax
jne    11ad <shalloc+0x5d>
movabs $0x300003000,%rax
mov    (%rax),%rcx
lea    0x17fff0(%rax),%rdx
cmp    %rdx,%rcx
jge    11ab <shalloc+0x5b>
add    $0x18,%rcx
mov    %rcx,(%rax)
jmp    11bc <shalloc+0x6c>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
call   1040 <init_PR_var@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <_get_new_sar@plt>

LLVM IR (-O0):
define i8* @shalloc(i64 %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
store i64 %0, i64* %3
%6 = load i64, i64* %3
%7 = icmp sle i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i8* null, i8** %2
br label %41
9: ; preds = %1
%10 = load i64, i64* %3
%11 = call i64 @s_align_to_page(i64 %10)
store i64 %11, i64* %3
%12 = load i64, i64* %3
%13 = call i64 @s_align_to(i64 %12)
store i64 %13, i64* %4
%14 = load i64, i64* inttoptr (i64 8590983168 to i64*)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %9
%17 = call i32 (...) @init_PR_var()
%18 = load i64, i64* %3
%19 = load i64, i64* %4
%20 = call i8* @_get_new_sar(i64 %18, i64 %19)
store i8* %20, i8** %5
br label %39
21: ; preds = %9
%22 = load i64, i64* %3
%23 = call i8* @_get_from_sar_array(i64 %22)
store i8* %23, i8** %5
%24 = load i8*, i8** %5
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %38
26: ; preds = %21
%27 = load i64, i64* inttoptr (i64 12884914176 to i64*)
%28 = add nsw i64 %27, 24
%29 = icmp slt i64 %28, 12886487048
br i1 %29, label %30, label %36
30: ; preds = %26
%31 = load i64, i64* inttoptr (i64 12884914176 to i64*)
%32 = add nsw i64 %31, 24
store i64 %32, i64* inttoptr (i64 12884914176 to i64*)
%33 = load i64, i64* %3
%34 = load i64, i64* %4
%35 = call i8* @_get_new_sar(i64 %33, i64 %34)
store i8* %35, i8** %5
br label %37
36: ; preds = %26
store i8* null, i8** %5
br label %37
37: ; preds = %36, %30
br label %38
38: ; preds = %37, %21
br label %39
39: ; preds = %38, %16
%40 = load i8*, i8** %5
store i8* %40, i8** %2
br label %41
41: ; preds = %39, %8
%42 = load i8*, i8** %2
ret i8* %42
}

LLVM IR (-O2):
define i8* @shalloc(i64 %0) {
%2 = icmp slt i64 %0, 1
br i1 %2, label %20, label %3
3: ; preds = %1
%4 = tail call i64 @s_align_to_page(i64 %0)
%5 = tail call i64 @s_align_to(i64 %4)
%6 = load i64, i64* inttoptr (i64 8590983168 to i64*)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 (...) @init_PR_var()
br label %18
10: ; preds = %3
%11 = tail call i8* @_get_from_sar_array(i64 %4)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load i64, i64* inttoptr (i64 12884914176 to i64*)
%15 = icmp slt i64 %14, 12886487024
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = add nsw i64 %14, 24
store i64 %17, i64* inttoptr (i64 12884914176 to i64*)
br label %18
18: ; preds = %16, %8
%19 = tail call i8* @_get_new_sar(i64 %4, i64 %5)
br label %20
20: ; preds = %18, %10, %13, %1
%21 = phi i8* [ null, %1 ], [ %11, %10 ], [ null, %13 ], [ %19, %18 ]
ret i8* %21
}