// File: /workspace/github_cpp_makefile_star2_O1/jkingan[P]ladyheather/heather.cpp
// Function: dump_bmp_file(int, int)
int dump_bmp_file(int invert, int top_line)
{
int x, y, c;

   // main header
   dump_byte('B');   dump_byte('M');                          // magic number
   dump_dword((SCREEN_HEIGHT-top_line)*SCREEN_WIDTH/2L+BM_HEADER_SIZE);  // file size
   dump_dword(0L);              // reserved
   dump_dword(BM_HEADER_SIZE);  // offset of bitmap data in the file

   // info header
   dump_dword(40L);             // info header length
   dump_dword(SCREEN_WIDTH);    // screen size
   dump_dword(SCREEN_HEIGHT-top_line);
   dump_word(1);                // number of planes
   dump_word(4);                // bits per pixel
   dump_dword(0L);              // no compression
   dump_dword(SCREEN_WIDTH*(SCREEN_HEIGHT-top_line)/2L);// picture size in bytes
   dump_dword(0L);              // horizontal resolution
   dump_dword(0L);              // vertical resolution
   dump_dword(16L);             // number of used colors
   dump_dword(16L);             // number of important colors

   // palette
   for(c=0; c<16; c++) {
      x = (c << 2);
      if(invert) {
         if     (c == WHITE)  x = (BLACK << 2);
         else if(c == BLACK)  x = (WHITE << 2);
         else if(c == YELLOW) x = (BMP_YELLOW << 2);
      }
      dump_byte(bmp_pal[x++]);
      dump_byte(bmp_pal[x++]);
      dump_byte(bmp_pal[x++]);
      dump_byte(bmp_pal[x]);
   }

   for(y=SCREEN_HEIGHT-1; y>=top_line; y--) {
      update_pwm();
      for(x=0; x<SCREEN_WIDTH; x+=2) {
         c = (get_pixel(x, y) & 0x0F) << 4;
         c |= (get_pixel(x+1, y) & 0x0F);
         dump_byte(c);
      }
   }

   return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebx
movl %edi, %r14d
movq 0x330b38(%rip), %rsi    # 0x340160
movl $0x42, %edi
callq 0x9480
movq 0x330b27(%rip), %rsi    # 0x340160
movl $0x4d, %edi
callq 0x9480
movl 0x2091bb(%rip), %eax    # 0x218804
subl %ebx, %eax
imull 0x2091ae(%rip), %eax    # 0x218800
movl %eax, %edi
shrl $0x1f, %edi
addl %eax, %edi
sarl %edi
addl $0x76, %edi
callq 0xf5b8
xorl %r15d, %r15d
xorl %edi, %edi
callq 0xf5b8
movl $0x76, %edi
callq 0xf5b8
movl $0x28, %edi
callq 0xf5b8
movl 0x209179(%rip), %edi    # 0x218800
callq 0xf5b8
movl 0x209172(%rip), %edi    # 0x218804
subl %ebx, %edi
callq 0xf5b8
movq 0x330ac0(%rip), %rsi    # 0x340160
movl $0x1, %edi
callq 0x9480
movq 0x330aaf(%rip), %rsi    # 0x340160
xorl %edi, %edi
callq 0x9480
movq 0x330aa1(%rip), %rsi    # 0x340160
movl $0x4, %edi
callq 0x9480
movq 0x330a90(%rip), %rsi    # 0x340160
xorl %edi, %edi
callq 0x9480
xorl %edi, %edi
callq 0xf5b8
movl 0x209120(%rip), %eax    # 0x218804
movl %ebx, -0x2c(%rbp)
subl %ebx, %eax
imull 0x209110(%rip), %eax    # 0x218800
movl %eax, %edi
shrl $0x1f, %edi
addl %eax, %edi
sarl %edi
callq 0xf5b8
xorl %edi, %edi
callq 0xf5b8
xorl %edi, %edi
callq 0xf5b8
movl $0x10, %edi
callq 0xf5b8
movl $0x10, %edi
callq 0xf5b8
leaq 0x330939(%rip), %r12    # 0x340060
xorl %r13d, %r13d
movl %r15d, %eax
testl %r14d, %r14d
je 0xf758
cmpl $0xf, %r13d
je 0xf751
cmpl $0xe, %r13d
je 0xf74a
testl %r13d, %r13d
jne 0xf755
movl $0x3c, %eax
jmp 0xf758
movl $0x40, %eax
jmp 0xf758
xorl %eax, %eax
jmp 0xf758
movl %r15d, %eax
movl %eax, %ebx
movsbl (%rbx,%r12), %edi
movq 0x3309fa(%rip), %rsi    # 0x340160
callq 0x9480
movsbl 0x1(%rbx,%r12), %edi
movq 0x3309e8(%rip), %rsi    # 0x340160
callq 0x9480
movsbl 0x2(%rbx,%r12), %edi
movq 0x3309d6(%rip), %rsi    # 0x340160
callq 0x9480
movsbl 0x3(%rbx,%r12), %edi
movq 0x3309c4(%rip), %rsi    # 0x340160
callq 0x9480
incl %r13d
addl $0x4, %r15d
cmpl $0x10, %r13d
jne 0xf72a
movl 0x20904b(%rip), %r14d   # 0x218804
movl -0x2c(%rbp), %ebx
cmpl %ebx, %r14d
jle 0xf816
decl %r14d
callq 0xd1865
cmpl $0x0, 0x209030(%rip)    # 0x218800
jle 0xf7bc
xorl %r15d, %r15d
movl %r15d, %edi
movl %r14d, %esi
callq 0xf193
movl %eax, %r12d
shlb $0x4, %r12b
leal 0x1(%r15), %edi
movl %r14d, %esi
callq 0xf193
andb $0xf, %al
orb %r12b, %al
movq 0x330961(%rip), %rsi    # 0x340160
movsbl %al, %edi
callq 0x9480
addl $0x2, %r15d
cmpl 0x208fee(%rip), %r15d   # 0x218800
jl 0xf7d5
jmp 0xf7bc
movl $0x1, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq