// File: /workspace/github_c_makefile_star2_O1/mrkite[P]regs/src/omf.cc
// Function: OMF::mapSegments()
bool OMF::mapSegments() {
  // use a memory map that denotes runs of available ram
  std::vector<uint32_t> memory;
  memory.push_back(0x300);  // min
  memory.push_back(0x7f0000);  // max
  // first map any segments that know where they belong
  for (auto &seg : segments) {
    seg.map(memory, false);
    std::sort(memory.begin(), memory.end());
  }

  // now map everything else by first fit
  for (auto &seg : segments) {  // map.true
    seg.map(memory, true);
    std::sort(memory.begin(), memory.end());
  }
  // create direct-page if it doesn't exist
  bool found = false;
  for (auto &seg : segments) {
    if (seg.isDPS()) {
      found = true;
    }
  }
  if (!found) {
    Segment seg;
    seg.initDPS();
    seg.map(memory, true);
    segments.push_back(seg);
  }
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movl $0x300, 0x20(%rsp)      # imm = 0x300
movq 0x8(%rsp), %rsi
testq %rsi, %rsi
je 0x71ad
movl $0x300, (%rsi)          # imm = 0x300
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x71ba
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
callq 0x9276
movl $0x7f0000, 0x20(%rsp)   # imm = 0x7F0000
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x71df
movl $0x7f0000, (%rsi)       # imm = 0x7F0000
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x71ec
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
callq 0x9276
movq 0x10(%rbx), %r14
movq 0x18(%rbx), %rbp
cmpq %rbp, %r14
je 0x724d
movq %rsp, %r15
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x7c0c
movq (%rsp), %r12
movq 0x8(%rsp), %r13
cmpq %r13, %r12
je 0x7244
movq %r13, %rax
subq %r12, %rax
sarq $0x2, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r12, %rdi
movq %r13, %rsi
callq 0x93b1
movq %r12, %rdi
movq %r13, %rsi
callq 0x9494
addq $0x68, %r14
cmpq %rbp, %r14
jne 0x71fc
movq 0x10(%rbx), %r14
movq 0x18(%rbx), %rbp
cmpq %rbp, %r14
je 0x72b1
movq %rsp, %r15
movq %r14, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0x7c0c
movq (%rsp), %r12
movq 0x8(%rsp), %r13
cmpq %r13, %r12
je 0x72a8
movq %r13, %rax
subq %r12, %rax
sarq $0x2, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r12, %rdi
movq %r13, %rsi
callq 0x93b1
movq %r12, %rdi
movq %r13, %rsi
callq 0x9494
addq $0x68, %r14
cmpq %rbp, %r14
jne 0x725d
movq 0x10(%rbx), %rax
movq 0x18(%rbx), %rcx
cmpq %rcx, %rax
je 0x72e8
xorl %edx, %edx
movl $0x1, %esi
movzwl 0x10(%rax), %edi
andl $0x1f, %edi
cmpw $0x12, %di
movzbl %dl, %edx
cmovel %esi, %edx
addq $0x68, %rax
cmpq %rcx, %rax
jne 0x72c5
testb $0x1, %dl
jne 0x7386
leaq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %r14
movq %r14, -0x10(%r14)
movq $0x0, -0x8(%r14)
movb $0x0, (%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%r14)
movw $0x12, -0x28(%r14)
movl $0x400, -0x30(%r14)     # imm = 0x400
movabsq $0x40000000000, %rax    # imm = 0x40000000000
movq %rax, -0x38(%r14)
leaq 0xff0e(%rip), %rcx      # 0x1723c
movl $0x6, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x5360
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
movl $0x1, %edx
callq 0x7c0c
addq $0x10, %rbx
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x7ea8
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x736f
callq 0x6752
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0x7386
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x5230
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x739c
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x5230
movb $0x1, %al
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x73c5
jmp 0x73c5
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x7ed2
jmp 0x73c8
jmp 0x73c5
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x73de
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x5230
movq %rbx, %rdi
callq 0x53e0