#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 *MAP_FAILED;
int /*<<< orphan*/ lm_in_chunk_range(void *);
void *lm_mremap_helper(void *, size_t, size_t, int);
void *mremap(void *, size_t, size_t, int);
void *ljmm_mremap(void *old_addr, size_t old_size, size_t new_size, int flags) {
  if (!lm_in_chunk_range(old_addr)) {
    return mremap(old_addr, old_size, new_size, flags);
  }
  void *res = lm_mremap_helper(old_addr, old_size, new_size, flags);
  return res ? res : MAP_FAILED;
}


x86 assembly (clang, -O0):
<ljmm_mremap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <lm_in_chunk_range@plt>
cmp    $0x0,%eax
jne    1176 <ljmm_mremap+0x46>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1040 <mremap@plt>
mov    %rax,-0x8(%rbp)
jmp    11bc <ljmm_mremap+0x8c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1030 <lm_mremap_helper@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11a6 <ljmm_mremap+0x76>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    11b4 <ljmm_mremap+0x84>
mov    0x2e33(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ljmm_mremap>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%rbx
call   1050 <lm_in_chunk_range@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
test   %eax,%eax
je     1177 <ljmm_mremap+0x47>
call   1030 <lm_mremap_helper@plt>
test   %rax,%rax
jne    116c <ljmm_mremap+0x3c>
mov    0x2e77(%rip),%rax
mov    (%rax),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <mremap@plt>

LLVM IR (-O0):
@MAP_FAILED = global i8* null
define i8* @ljmm_mremap(i8* %0, i64 %1, i64 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i32 %3, i32* %9
%11 = load i8*, i8** %6
%12 = call i32 @lm_in_chunk_range(i8* %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %4
%15 = load i8*, i8** %6
%16 = load i64, i64* %7
%17 = load i64, i64* %8
%18 = load i32, i32* %9
%19 = call i8* @mremap(i8* %15, i64 %16, i64 %17, i32 %18)
store i8* %19, i8** %5
br label %34
20: ; preds = %4
%21 = load i8*, i8** %6
%22 = load i64, i64* %7
%23 = load i64, i64* %8
%24 = load i32, i32* %9
%25 = call i8* @lm_mremap_helper(i8* %21, i64 %22, i64 %23, i32 %24)
store i8* %25, i8** %10
%26 = load i8*, i8** %10
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %30
28: ; preds = %20
%29 = load i8*, i8** %10
br label %32
30: ; preds = %20
%31 = load i8*, i8** @MAP_FAILED
br label %32
32: ; preds = %30, %28
%33 = phi i8* [ %29, %28 ], [ %31, %30 ]
store i8* %33, i8** %5
br label %34
34: ; preds = %32, %14
%35 = load i8*, i8** %5
ret i8* %35
}

LLVM IR (-O2):
@MAP_FAILED = global i8* null
define i8* @ljmm_mremap(i8* %0, i64 %1, i64 %2, i32 %3) {
%5 = tail call i32 @lm_in_chunk_range(i8* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i8* @mremap(i8* %0, i64 %1, i64 %2, i32 %3)
br label %14
9: ; preds = %4
%10 = tail call i8* @lm_mremap_helper(i8* %0, i64 %1, i64 %2, i32 %3)
%11 = icmp eq i8* %10, null
%12 = load i8*, i8** @MAP_FAILED
%13 = select i1 %11, i8* %12, i8* %10
br label %14
14: ; preds = %9, %7
%15 = phi i8* [ %13, %9 ], [ %8, %7 ]
ret i8* %15
}