// File: /workspace/github_c_makefile_star2_O1/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 $0x28, %rsp
movl %ecx, %r12d
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %rbx
leaq -0x1(%rdi), %r13
movl $0x1, %ecx
cmpl $-0x1, %r12d
jne 0x4084f2
movq %rbx, %rax
xorq %r13, %rax
cmpq %r13, %rax
jbe 0x408851
callq 0x4083a0
movl $0x22, %ecx
cmpq %rbx, %rax
jae 0x4084f2
bsrq %rbx, %rcx
shll $0x1a, %ecx
movl $0x40022, %eax          # imm = 0x40022
orl %eax, %ecx
cmpq $0x2, %rbx
cmovbl %eax, %ecx
addq %r14, %r13
movq %rbx, %r15
negq %r15
andq %r13, %r15
xorl %edi, %edi
movq %r15, %rsi
movl $0x3, %edx
movl %r12d, %r8d
xorl %r9d, %r9d
callq 0x467440
movq %rax, 0x8(%rsp)
cmpq $-0x1, %rax
je 0x40881e
cmpl $-0x1, %r12d
setne %al
movl %ebp, %ecx
xorb $0x1, %cl
orb %al, %cl
jne 0x4085db
leaq 0xcae29(%rip), %rdi     # 0x4d3366
callq 0x40886f
movq %rax, %r14
leaq 0xcae46(%rip), %rdi     # 0x4d3392
callq 0x40886f
movq %rax, %r13
leaq 0xcae62(%rip), %rsi     # 0x4d33bd
movq %r14, %rdi
callq 0x4010b8
testl %eax, %eax
je 0x408586
leaq 0xcae58(%rip), %rsi     # 0x4d33c6
movq %r14, %rdi
callq 0x4010b8
testl %eax, %eax
je 0x408586
leaq 0xcade5(%rip), %rdi     # 0x4d3366
callq 0x40892f
leaq 0xcae30(%rip), %rsi     # 0x4d33bd
movq %r13, %rdi
callq 0x4010b8
testl %eax, %eax
je 0x4085cb
leaq 0xcae30(%rip), %rsi     # 0x4d33d0
movq %r13, %rdi
callq 0x4010b8
testl %eax, %eax
je 0x4085cb
leaq 0xcae13(%rip), %rsi     # 0x4d33c6
movq %r13, %rdi
callq 0x4010b8
testl %eax, %eax
je 0x4085cb
leaq 0xcadcc(%rip), %rdi     # 0x4d3392
callq 0x40892f
movq %r14, %rdi
callq 0x435860
movq %r13, %rdi
callq 0x435860
cmpl $-0x1, %r12d
setne %r14b
callq 0x4083a0
cmpq %rbx, %rax
setb %al
orb %r14b, %al
jne 0x408619
movzbl %bpl, %edx
xorl $0xf, %edx
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x467500
testl %eax, %eax
je 0x408622
leaq 0xcacd5(%rip), %rdi     # 0x4d32e7
callq 0x413570
jmp 0x408622
testb %bpl, %bpl
jne 0x40884c
movq $0x50b314, %rax         # imm = 0x50B314
cmpl $0x0, (%rax)
je 0x408800
movl $0x200, %edi            # imm = 0x200
callq 0x435520
testq %rax, %rax
je 0x408823
movq %rax, %r12
movq $0x50b320, %rax         # imm = 0x50B320
movzwl (%rax), %ecx
decq %rcx
movq %rcx, (%r12)
movl $0x1, %edx
movzwl (%rax,%rdx,2), %esi
addq %rsi, %rcx
movq %rcx, (%r12,%rdx,8)
incq %rdx
cmpq $0x40, %rdx
jne 0x40865e
movq 0x1f8(%r12), %r13
movq $0x0, 0x20(%rsp)
movl $0x1, %edi
movl $0x20, %esi
callq 0x436970
movq %rax, %r14
movq $-0x60, %rax
movq %r14, %fs:(%rax)
movl $0x1, %edi
movl $0x30, %esi
callq 0x436970
movq $-0x58, %rbp
movq %rax, %fs:(%rbp)
testq %rax, %rax
je 0x408828
movl $0x20, %edx
movl $0x1, %edi
movq %r14, %rsi
movq %rax, %rcx
callq 0x412700
testl %eax, %eax
jne 0x408847
testq %r15, %r15
jle 0x4087f8
movq 0x8(%rsp), %rax
movq %rax, %r14
addq %r15, %r14
incl %r13d
movslq %r13d, %r15
movq %rax, %r13
movq %fs:(%rbp), %rdi
leaq 0x1c(%rsp), %rsi
callq 0x4129a0
testl %eax, %eax
jne 0x408814
movq %fs:(%rbp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x4129a0
testl %eax, %eax
jne 0x408814
movq %fs:(%rbp), %rdi
leaq 0x14(%rsp), %rsi
callq 0x4129a0
testl %eax, %eax
jne 0x408814
movq %fs:(%rbp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x4129a0
testl %eax, %eax
jne 0x408814
movzwl 0x1c(%rsp), %eax
movl 0x18(%rsp), %ecx
shll $0x10, %ecx
orq %rax, %rcx
movl 0x14(%rsp), %eax
movzwl %ax, %eax
shlq $0x20, %rax
orq %rcx, %rax
movl 0x10(%rsp), %ecx
shlq $0x30, %rcx
orq %rax, %rcx
movq %rcx, %rax
subq $-0x7fffffff, %rax      # imm = 0x80000001
cmovbq %rcx, %rax
xorl %edx, %edx
divq %r15
movl %edx, %eax
xorl %ecx, %ecx
cmpq %rax, (%r12,%rcx,8)
jge 0x4087ac
incq %rcx
cmpq $0x40, %rcx
jne 0x408798
movl $0x40, %ecx
movl $0x1, %eax
shll %cl, %eax
cltq
movq %rax, 0x20(%rsp)
movl $0x1, (%rsp)
movl $0xed, %edi
movl $0x40, %r9d
movq %r13, %rsi
movq %rbx, %rdx
movl $0x2, %ecx
leaq 0x20(%rsp), %r8
xorl %eax, %eax
callq 0x467400
testl %eax, %eax
jne 0x408819
movb $0x0, (%r13)
addq %rbx, %r13
cmpq %r14, %r13
jb 0x4086fe
movq %r12, %rdi
callq 0x435860
movq 0x8(%rsp), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4012f5
callq 0x40130a
callq 0x401344
callq 0x40131f
leaq 0xca742(%rip), %rdi     # 0x4d2f71
leaq 0xca746(%rip), %rsi     # 0x4d2f7c
leaq 0xca74f(%rip), %rcx     # 0x4d2f8c
movl $0x5d, %edx
callq 0x40bc10
callq 0x4012e0
callq 0x4012bb
movq %rbx, %rdi
callq 0x401297