// File: /workspace/github_c_makefile_star2_O3/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
movq %rsp, %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
leaq 0x20(%rsp), %rdx
movl $0x300, (%rdx)          # imm = 0x300
xorl %esi, %esi
callq 0x907e
movq 0x8(%rsp), %rsi
movl $0x7f0000, 0x20(%rsp)   # imm = 0x7F0000
cmpq 0x10(%rsp), %rsi
je 0x71a0
movl $0x7f0000, (%rsi)       # imm = 0x7F0000
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x71ad
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
callq 0x907e
movq 0x10(%rbx), %r14
movq 0x18(%rbx), %rbp
cmpq %rbp, %r14
je 0x72a7
movq %rsp, %r15
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x7aea
movq (%rsp), %r12
movq 0x8(%rsp), %r13
cmpq %r13, %r12
je 0x7209
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 0x91b9
movq %r12, %rdi
movq %r13, %rsi
callq 0x929c
addq $0x68, %r14
cmpq %rbp, %r14
jne 0x71c1
movq 0x10(%rbx), %r14
movq 0x18(%rbx), %rbp
cmpq %rbp, %r14
je 0x727e
movq %rsp, %r15
movq %r14, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0x7aea
movq (%rsp), %r12
movq 0x8(%rsp), %r13
cmpq %r13, %r12
je 0x726d
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 0x91b9
movq %r12, %rdi
movq %r13, %rsi
callq 0x929c
addq $0x68, %r14
cmpq %rbp, %r14
jne 0x7222
movq 0x10(%rbx), %r14
movq 0x18(%rbx), %rbp
cmpq %rbp, %r14
je 0x72a7
xorl %eax, %eax
movzwl 0x10(%r14), %ecx
andl $0x1f, %ecx
cmpw $0x12, %cx
sete %cl
orb %cl, %al
addq $0x68, %r14
cmpq %rbp, %r14
jne 0x7285
testb $0x1, %al
jne 0x7345
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 0xff4f(%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 0x7aea
addq $0x10, %rbx
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x7d18
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x732e
callq 0x671a
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0x7345
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x5230
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x735b
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 0x7384
jmp 0x7384
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x7d42
jmp 0x7387
jmp 0x7384
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x739d
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x5230
movq %rbx, %rdi
callq 0x53e0
nop