// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x138(%rbp)
leaq -0x20(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0xd400
movq -0x130(%rbp), %rdi
movl $0x300, -0x24(%rbp)     # imm = 0x300
leaq -0x24(%rbp), %rsi
callq 0xd420
jmp 0xb973
movl $0x7f0000, -0x38(%rbp)  # imm = 0x7F0000
leaq -0x20(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0xd420
jmp 0xb989
movq -0x138(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x7cb0
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
callq 0x7ce0
movq %rax, -0x50(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x7d10
testb $0x1, %al
jne 0xb9c5
jmp 0xba34
leaq -0x48(%rbp), %rdi
callq 0x7d50
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
leaq -0x20(%rbp), %rsi
xorl %edx, %edx
callq 0xcdd0
jmp 0xb9e3
leaq -0x20(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0xd490
movq -0x140(%rbp), %rdi
movq %rax, -0x60(%rbp)
callq 0xd4c0
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0xd450
jmp 0xba16
jmp 0xba18
leaq -0x48(%rbp), %rdi
callq 0x7d70
jmp 0xb9b2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0xbc12
movq -0x138(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
callq 0x7cb0
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rdi
callq 0x7ce0
movq %rax, -0x80(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x7d10
testb $0x1, %al
jne 0xba70
jmp 0xbae6
leaq -0x78(%rbp), %rdi
callq 0x7d50
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rdi
leaq -0x20(%rbp), %rsi
movl $0x1, %edx
callq 0xcdd0
jmp 0xba97
leaq -0x20(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0xd490
movq -0x148(%rbp), %rdi
movq %rax, -0x90(%rbp)
callq 0xd4c0
movq %rax, -0x98(%rbp)
movq -0x90(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0xd450
jmp 0xbad6
jmp 0xbad8
leaq -0x78(%rbp), %rdi
callq 0x7d70
jmp 0xba5d
movq -0x138(%rbp), %rax
movb $0x0, -0x99(%rbp)
addq $0x10, %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rdi
callq 0x7cb0
movq %rax, -0xb0(%rbp)
movq -0xa8(%rbp), %rdi
callq 0x7ce0
movq %rax, -0xb8(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x7d10
testb $0x1, %al
jne 0xbb3e
jmp 0xbb7a
leaq -0xb0(%rbp), %rdi
callq 0x7d50
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rdi
callq 0xb160
testb $0x1, %al
jne 0xbb63
jmp 0xbb6a
movb $0x1, -0x99(%rbp)
jmp 0xbb6c
leaq -0xb0(%rbp), %rdi
callq 0x7d70
jmp 0xbb25
testb $0x1, -0x99(%rbp)
jne 0xbbfc
leaq -0x128(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0xd2e0
movq -0x150(%rbp), %rdi
callq 0xb120
jmp 0xbba4
leaq -0x128(%rbp), %rdi
leaq -0x20(%rbp), %rsi
movl $0x1, %edx
callq 0xcdd0
jmp 0xbbbb
movq -0x138(%rbp), %rdi
addq $0x10, %rdi
leaq -0x128(%rbp), %rsi
callq 0xd340
jmp 0xbbd4
leaq -0x128(%rbp), %rdi
callq 0x94a0
jmp 0xbbfc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x94a0
jmp 0xbc12
leaq -0x20(%rbp), %rdi
callq 0xd4f0
movb $0x1, %al
andb $0x1, %al
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
leaq -0x20(%rbp), %rdi
callq 0xd4f0
movq -0x30(%rbp), %rdi
callq 0x6540
nopw %cs:(%rax,%rax)