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


x86 assembly (clang, -O0):
<shalloc_ext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jg     1168 <shalloc_ext+0x28>
movq   $0x0,-0x8(%rbp)
jmp    1240 <shalloc_ext+0x100>
mov    -0x10(%rbp),%rdi
call   1030 <s_align_to_page@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <s_align_to_ext@plt>
mov    %rax,-0x20(%rbp)
movabs $0x200100000,%rax
cmpq   $0x0,(%rax)
jne    11b7 <shalloc_ext+0x77>
mov    $0x0,%al
call   1040 <init_PR_var@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <_get_new_sar_ext@plt>
mov    %rax,-0x28(%rbp)
jmp    1238 <shalloc_ext+0xf8>
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1233 <shalloc_ext+0xf3>
movabs $0x300003000,%rax
mov    (%rax),%rax
add    $0x18,%rax
movabs $0x300183008,%rcx
cmp    %rcx,%rax
jge    1226 <shalloc_ext+0xe6>
movabs $0x300003000,%rax
mov    (%rax),%rcx
add    $0x18,%rcx
movabs $0x300003000,%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <_get_new_sar_ext@plt>
mov    %rax,-0x28(%rbp)
jmp    122e <shalloc_ext+0xee>
movq   $0x0,-0x28(%rbp)
jmp    1233 <shalloc_ext+0xf3>
jmp    1238 <shalloc_ext+0xf8>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shalloc_ext>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
jle    1192 <shalloc_ext+0x52>
mov    %rsi,%r14
call   1030 <s_align_to_page@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <s_align_to_ext@plt>
mov    %rax,%r15
movabs $0x200100000,%rax
cmpq   $0x0,(%rax)
je     1196 <shalloc_ext+0x56>
movabs $0x300003000,%rax
mov    (%rax),%rcx
lea    0x17fff0(%rax),%rdx
cmp    %rdx,%rcx
jge    1192 <shalloc_ext+0x52>
add    $0x18,%rcx
mov    %rcx,(%rax)
jmp    119d <shalloc_ext+0x5d>
xor    %eax,%eax
jmp    11ab <shalloc_ext+0x6b>
xor    %eax,%eax
call   1040 <init_PR_var@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1050 <_get_new_sar_ext@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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