// File: /workspace/github_c_makefile_star2_O2/google[P]multichase/arena.c
// Function: alloc_arena_mmap
void *alloc_arena_mmap(size_t page_size, bool use_thp, size_t arena_size, int fd) {
  void *arena;
  size_t pagemask = page_size - 1;
  int flags;

  if (fd == -1)
    flags = MAP_PRIVATE | MAP_ANONYMOUS | get_page_size_flags(page_size);
  else
    flags = MAP_SHARED;

  arena_size = (arena_size + pagemask) & ~pagemask;
  arena = mmap(0, arena_size, PROT_READ | PROT_WRITE, flags, fd, 0);
  if (arena == MAP_FAILED) {
    perror("mmap");
    exit(1);
  }

  if (use_thp && fd == -1)
    check_thp_state();

  /* Explicitly disable THP for small pages. */
  if (!page_size_is_huge(page_size) && fd == -1) {
    if (madvise(arena, arena_size, use_thp ? MADV_HUGEPAGE : MADV_NOHUGEPAGE)) {
      perror("madvise");
    }
  } else if (use_thp) {
    fprintf(stderr,
            "Can't use transparent hugepages with a non-native page size.\n");
    exit(1);
  }

  if (is_weighted_mbind) {
    arena_weighted_mbind(page_size, arena, arena_size, mbind_weights,
                         MAX_MEM_NODES);
  }
  return arena;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, %r12d
movq %rdx, %r14
movl %esi, %r15d
movq %rdi, %rbx
leaq -0x1(%rdi), %r13
cmpl $-0x1, %ecx
je 0x407fc3
pushq $0x1
jmp 0x407ff7
movq %rbx, %rax
xorq %r13, %rax
cmpq %r13, %rax
jbe 0x408384
callq 0x407e9c
cmpq %rbx, %rax
jae 0x407ff5
movl $0x40022, %ecx          # imm = 0x40022
movq %rbx, %rax
cmpq $0x2, %rax
jb 0x407ff8
shrq %rax
addl $0x4000000, %ecx        # imm = 0x4000000
jmp 0x407fe4
pushq $0x22
popq %rcx
addq %r14, %r13
movq %rbx, %rsi
negq %rsi
andq %r13, %rsi
pushq $0x3
popq %rdx
xorl %edi, %edi
movq %rsi, 0x28(%rsp)
movl %r12d, %r8d
xorl %r9d, %r9d
callq 0x466fc0
movq %rax, 0x10(%rsp)
cmpq $-0x1, %rax
je 0x408322
cmpl $-0x1, %r12d
setne %al
movl %r15d, %ecx
xorb $0x1, %cl
orb %al, %cl
jne 0x4080e2
leaq 0xca322(%rip), %rdi     # 0x4d2366
callq 0x4083c7
movq %rax, %r14
leaq 0xca33f(%rip), %rdi     # 0x4d2392
callq 0x4083c7
movq %rax, %r13
leaq 0xca35b(%rip), %rsi     # 0x4d23bd
movq %r14, %rdi
callq 0x4010b8
testl %eax, %eax
je 0x40808d
leaq 0xca351(%rip), %rsi     # 0x4d23c6
movq %r14, %rdi
callq 0x4010b8
testl %eax, %eax
je 0x40808d
leaq 0xca2de(%rip), %rdi     # 0x4d2366
callq 0x40847b
leaq 0xca329(%rip), %rsi     # 0x4d23bd
movq %r13, %rdi
callq 0x4010b8
testl %eax, %eax
je 0x4080d2
leaq 0xca329(%rip), %rsi     # 0x4d23d0
movq %r13, %rdi
callq 0x4010b8
testl %eax, %eax
je 0x4080d2
leaq 0xca30c(%rip), %rsi     # 0x4d23c6
movq %r13, %rdi
callq 0x4010b8
testl %eax, %eax
je 0x4080d2
leaq 0xca2c5(%rip), %rdi     # 0x4d2392
callq 0x40847b
movq %r14, %rdi
callq 0x4353e0
movq %r13, %rdi
callq 0x4353e0
cmpl $-0x1, %r12d
setne %bpl
callq 0x407e9c
cmpq %rbx, %rax
setb %al
orb %bpl, %al
jne 0x408122
movzbl %r15b, %edx
xorl $0xf, %edx
movq 0x10(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x467080
testl %eax, %eax
je 0x40812b
leaq 0xca1cc(%rip), %rdi     # 0x4d22e7
callq 0x4130f0
jmp 0x40812b
testb %r15b, %r15b
jne 0x408366
movq $0x50a314, %rax         # imm = 0x50A314
cmpl $0x0, (%rax)
je 0x4082f1
movl $0x200, %edi            # imm = 0x200
callq 0x4350a0
testq %rax, %rax
je 0x40832b
movq %rax, %r12
movq $0x50a320, %rax         # imm = 0x50A320
movzwl (%rax), %ecx
decq %rcx
movq %rcx, (%r12)
pushq $0x1
popq %rdx
cmpq $0x40, %rdx
je 0x40817b
movzwl (%rax,%rdx,2), %esi
addq %rsi, %rcx
movq %rcx, (%r12,%rdx,8)
incq %rdx
jmp 0x408165
movq 0x1f8(%r12), %rbp
andq $0x0, 0x30(%rsp)
pushq $0x1
popq %r13
pushq $0x20
popq %rsi
movq %r13, %rdi
callq 0x4364f0
movq %rax, %r14
movq $-0x60, %rax
movq %r14, %fs:(%rax)
pushq $0x30
popq %rsi
movq %r13, %rdi
callq 0x4364f0
movq $-0x58, %r15
movq %rax, %fs:(%r15)
testq %rax, %rax
je 0x408340
pushq $0x1
popq %rdi
pushq $0x20
popq %rdx
movq %r14, %rsi
movq %rax, %rcx
callq 0x412280
testl %eax, %eax
jne 0x40835d
movq 0x10(%rsp), %rax
movq %rax, %r13
addq 0x28(%rsp), %r13
incl %ebp
movslq %ebp, %r14
movq %rax, %rbp
cmpq %r13, %rbp
jae 0x4082e9
movq %fs:(%r15), %rdi
leaq 0x24(%rsp), %rsi
callq 0x412520
testl %eax, %eax
jne 0x408305
movq %fs:(%r15), %rdi
leaq 0x20(%rsp), %rsi
callq 0x412520
testl %eax, %eax
jne 0x408305
movq %fs:(%r15), %rdi
leaq 0x1c(%rsp), %rsi
callq 0x412520
testl %eax, %eax
jne 0x408305
movq %fs:(%r15), %rdi
leaq 0x18(%rsp), %rsi
callq 0x412520
testl %eax, %eax
jne 0x408305
movzwl 0x24(%rsp), %eax
movl 0x20(%rsp), %ecx
shll $0x10, %ecx
orq %rax, %rcx
movl 0x1c(%rsp), %eax
movzwl %ax, %eax
shlq $0x20, %rax
orq %rcx, %rax
movl 0x18(%rsp), %ecx
shlq $0x30, %rcx
orq %rax, %rcx
movq %rcx, %rax
subq $-0x7fffffff, %rax      # imm = 0x80000001
cmovbq %rcx, %rax
xorl %edx, %edx
divq %r14
movl %edx, %eax
xorl %ecx, %ecx
cmpq $0x40, %rcx
je 0x4082a3
cmpq %rax, (%r12,%rcx,8)
jge 0x4082a8
incq %rcx
jmp 0x408292
pushq $0x40
popq %rax
movl %eax, %ecx
pushq $0x1
popq %rax
shll %cl, %eax
cltq
movq %rax, 0x30(%rsp)
movl $0x1, (%rsp)
movl $0xed, %edi
movq %rbp, %rsi
movq %rbx, %rdx
pushq $0x2
popq %rcx
leaq 0x30(%rsp), %r8
pushq $0x40
popq %r9
xorl %eax, %eax
callq 0x466f80
testl %eax, %eax
jne 0x40830e
movb $0x0, (%rbp)
addq %rbx, %rbp
jmp 0x4081f3
movq %r12, %rdi
callq 0x4353e0
movq 0x10(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc9eba(%rip), %rdi     # 0x4d21c6
jmp 0x408315
leaq 0xca180(%rip), %rdi     # 0x4d2495
callq 0x4130f0
pushq $0x1
popq %rdi
callq 0x411e30
leaq 0xc9fb9(%rip), %rdi     # 0x4d22e2
jmp 0x408315
movq $0x508708, %rax         # imm = 0x508708
movq (%rax), %rcx
leaq 0xca132(%rip), %rdi     # 0x4d246e
pushq $0x26
jmp 0x408379
leaq 0xc9c2a(%rip), %rdi     # 0x4d1f71
leaq 0xc9c2e(%rip), %rsi     # 0x4d1f7c
leaq 0xc9c37(%rip), %rcx     # 0x4d1f8c
pushq $0x5d
popq %rdx
callq 0x40b790
leaq 0xc9c44(%rip), %rdi     # 0x4d1fa8
jmp 0x408315
movq $0x508708, %rax         # imm = 0x508708
movq (%rax), %rcx
leaq 0xc9f78(%rip), %rdi     # 0x4d22ef
pushq $0x3d
popq %rsi
pushq $0x1
popq %rdx
callq 0x421e70
jmp 0x40831a
movq $0x508708, %rax         # imm = 0x508708
movq (%rax), %rdi
leaq 0xc9fac(%rip), %rsi     # 0x4d2341
movq %rbx, %rdx
xorl %eax, %eax
callq 0x412e00
jmp 0x40831a