// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathmsc.cpp
// Function: open_log_file(char*)
FILE *open_log_file(char *mode)
{
u32 color;
int i;
char *s;

   if(log_file) return 0;  // log already open
   if(mode == 0) return 0;

   s = strchr(log_name, FLUSH_CHAR);
   if(s) {
      *s = 0;
      log_flush_mode = 1;
   }
   else log_flush_mode = 0;

   log_file = topen(log_name, mode);
   if(log_file == 0) return 0;
   if(debug_file) fprintf(debug_file, "! log file %s opened\n", log_name);

   if(log_header) log_written = 0;
   log_loaded = 0;
   show_log_state();
   log_file_time = (log_interval+1);

   if     (strstr(log_name, ".xml")) log_fmt = XML;
   else if(strstr(log_name, ".XML")) log_fmt = XML;
   else if(strstr(log_name, ".gpx")) log_fmt = GPX;
   else if(strstr(log_name, ".GPX")) log_fmt = GPX;
   else if(strstr(log_name, ".kml")) log_fmt = KML;
   else if(strstr(log_name, ".KML")) log_fmt = KML;
   else if(strstr(log_name, ".obs")) log_fmt = RINEX;
   else if(strstr(log_name, ".OBS")) log_fmt = RINEX;
   else log_fmt = HEATHER;

   if(log_fmt != HEATHER) {
      last_log_hours = hours;
      if(log_fmt == GPX) {
         fprintf(log_file, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n\n");
         fprintf(log_file, "<gpx version=\"1.0\"  creator=\"Lady Heather V%s - %s\" >\n", VERSION, date_string);
         log_rcvr_type();
         start_log_track();
      }
      else if(log_fmt == KML) {
         fprintf(log_file, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
         fprintf(log_file, "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n");
         fprintf(log_file, "\n"); 
         fprintf(log_file, "  <Document>\n");
         fprintf(log_file, "  "); log_rcvr_type();
         fprintf(log_file, "    <visibility>1</visibility>\n"); 
         fprintf(log_file, "    <open>1</open>\n"); 
         fprintf(log_file, "\n"); 

         for(i=0; i<16; i++) {
            color = get_bgr_palette(i);
            color = (color & 0x00FF00) | ((color & 0xFF) << 16) | ((color & 0xFF0000) >> 16); 
            color |= 0x64000000;

            fprintf(log_file, "    <Style id=\"color%d\">\n", i);
            fprintf(log_file, "      <LineStyle>\n");
            fprintf(log_file, "        <color>%08X</color>\n", color);  // opacity(0..100) BB GG RR
            fprintf(log_file, "        <width>1</width>\n");
            fprintf(log_file, "      </LineStyle>\n");
            fprintf(log_file, "    </Style>\n");
            fprintf(log_file, "\n");
         }
         start_log_track();
      }
      else if(log_fmt == RINEX) {
      }
      else if(log_fmt == XML) {
         fprintf(log_file, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n\n");
         fprintf(log_file, "<gpx version=\"1.1\"  creator=\"Lady Heather V%s - %s\" >\n", VERSION, date_string);
         log_rcvr_type();
         start_log_track();
      }
   }
   if(log_flush_mode && log_file) fflush(log_file);

   return log_file;
}

// Assembly:
xorl %eax, %eax
testq %rdi, %rdi
je 0xc3a01
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x17aae4(%rip), %r12    # 0x23e360
cmpq $0x0, (%r12)
jne 0xc39f3
movq %rdi, %rbx
leaq 0x1795cf(%rip), %rdi    # 0x23ce60
movl $0x2a, %esi
callq 0x9100
testq %rax, %rax
je 0xc38aa
movb $0x0, (%rax)
movl $0x1, %eax
jmp 0xc38ac
xorl %eax, %eax
leaq 0x17ab6d(%rip), %r13    # 0x23e420
movl %eax, (%r13)
leaq 0x1795a2(%rip), %rdi    # 0x23ce60
movq %rbx, %rsi
callq 0x9a47
movq %rax, (%r12)
testq %rax, %rax
je 0xc39f1
leaq 0x17aab6(%rip), %rax    # 0x23e390
movq (%rax), %rdi
testq %rdi, %rdi
je 0xc38f7
leaq 0x69c39(%rip), %rsi     # 0x12d522
leaq 0x179570(%rip), %rdx    # 0x23ce60
xorl %eax, %eax
callq 0x9560
leaq 0x17aafa(%rip), %rax    # 0x23e3f8
cmpb $0x0, (%rax)
je 0xc390d
leaq 0x17aae0(%rip), %rax    # 0x23e3ea
movb $0x0, (%rax)
leaq 0x17aae6(%rip), %rax    # 0x23e3fa
movb $0x0, (%rax)
callq 0xc1ff4
leaq 0x157a85(%rip), %rax    # 0x21b3a8
movq (%rax), %rax
incq %rax
leaq 0x17aad0(%rip), %rcx    # 0x23e400
movq %rax, (%rcx)
leaq 0x179526(%rip), %rdi    # 0x23ce60
leaq 0x5a759(%rip), %rsi     # 0x11e09a
callq 0x9090
testq %rax, %rax
jne 0xc3967
leaq 0x17950e(%rip), %rdi    # 0x23ce60
leaq 0x69bdf(%rip), %rsi     # 0x12d538
callq 0x9090
testq %rax, %rax
je 0xc3a02
leaq 0x17aada(%rip), %rax    # 0x23e448
movl $0xa, (%rax)
leaq 0x249b55(%rip), %rax    # 0x30d4d0
movl (%rax), %eax
leaq 0x249d80(%rip), %rcx    # 0x30d704
movl %eax, (%rcx)
movq (%r12), %rcx
leaq 0x69bca(%rip), %rdi     # 0x12d55b
movl $0x29, %esi
movl $0x1, %edx
callq 0x9750
movq (%r12), %rdi
leaq 0x69d10(%rip), %rsi     # 0x12d6bb
leaq 0x4a19b(%rip), %rdx     # 0x10db4d
leaq 0x15fb97(%rip), %rcx    # 0x223550
xorl %eax, %eax
callq 0x9560
callq 0xc2d0a
callq 0xc292f
cmpl $0x0, (%r13)
setne %cl
movq (%r12), %rax
testq %rax, %rax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0xc39f3
movq %rax, %rdi
callq 0x9420
movq (%r12), %rax
jmp 0xc39f3
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x179457(%rip), %rdi    # 0x23ce60
leaq 0x69b2d(%rip), %rsi     # 0x12d53d
callq 0x9090
testq %rax, %rax
jne 0xc3a32
leaq 0x17943f(%rip), %rdi    # 0x23ce60
leaq 0x69b1a(%rip), %rsi     # 0x12d542
callq 0x9090
testq %rax, %rax
je 0xc3a7b
leaq 0x17aa0f(%rip), %rax    # 0x23e448
movl $0x14, (%rax)
leaq 0x249a8a(%rip), %rax    # 0x30d4d0
movl (%rax), %eax
leaq 0x249cb5(%rip), %rcx    # 0x30d704
movl %eax, (%rcx)
movq (%r12), %rcx
leaq 0x69aff(%rip), %rdi     # 0x12d55b
movl $0x29, %esi
movl $0x1, %edx
callq 0x9750
movq (%r12), %rdi
leaq 0x69b0f(%rip), %rsi     # 0x12d585
jmp 0xc39ab
leaq 0x1793de(%rip), %rdi    # 0x23ce60
leaq 0x69abe(%rip), %rsi     # 0x12d547
callq 0x9090
testq %rax, %rax
jne 0xc3aaf
leaq 0x1793c6(%rip), %rdi    # 0x23ce60
leaq 0x69aab(%rip), %rsi     # 0x12d54c
callq 0x9090
testq %rax, %rax
je 0xc3c6e
leaq 0x17a992(%rip), %rax    # 0x23e448
movl $0x1e, (%rax)
leaq 0x249a0d(%rip), %rax    # 0x30d4d0
movl (%rax), %eax
leaq 0x249c38(%rip), %rcx    # 0x30d704
movl %eax, (%rcx)
movq (%r12), %rcx
leaq 0x69ae3(%rip), %rdi     # 0x12d5bc
movl $0x28, %esi
movl $0x1, %edx
callq 0x9750
movq (%r12), %rcx
leaq 0x69af2(%rip), %rdi     # 0x12d5e5
movl $0x2d, %esi
movl $0x1, %edx
callq 0x9750
movq (%r12), %rsi
movl $0xa, %edi
callq 0x9480
movq (%r12), %rcx
leaq 0x69af8(%rip), %rdi     # 0x12d613
movl $0xd, %esi
movl $0x1, %edx
callq 0x9750
movq (%r12), %rcx
leaq 0x5f01e(%rip), %rdi     # 0x122b53
movl $0x2, %esi
movl $0x1, %edx
callq 0x9750
callq 0xc2d0a
movq (%r12), %rcx
leaq 0x690c9(%rip), %rdi     # 0x12cc1d
movl $0x1f, %esi
movl $0x1, %edx
callq 0x9750
movq (%r12), %rcx
leaq 0x69ab3(%rip), %rdi     # 0x12d621
movl $0x13, %esi
movl $0x1, %edx
callq 0x9750
movq (%r12), %rsi
movl $0xa, %edi
callq 0x9480
movl $0xff, %ebx
xorl %r14d, %r14d
movl %r14d, %edi
callq 0xf38e
movl %eax, %ecx
andl $0xff00, %ecx           # imm = 0xFF00
movl %eax, %edx
andl %ebx, %edx
shll $0x10, %edx
orl %ecx, %edx
shrl $0x10, %eax
andl %ebx, %eax
leal (%rax,%rdx), %r15d
addl $0x64000000, %r15d      # imm = 0x64000000
movq (%r12), %rdi
leaq 0x69a6e(%rip), %rsi     # 0x12d635
movl %r14d, %edx
xorl %eax, %eax
callq 0x9560
movq (%r12), %rcx
movl $0x12, %esi
movl $0x1, %edx
leaq 0x69a69(%rip), %rdi     # 0x12d64f
callq 0x9750
movq (%r12), %rdi
leaq 0x69a6c(%rip), %rsi     # 0x12d662
movl %r15d, %edx
xorl %eax, %eax
callq 0x9560
movq (%r12), %rcx
movl $0x19, %esi
movl $0x1, %edx
leaq 0x69a6a(%rip), %rdi     # 0x12d67f
callq 0x9750
movq (%r12), %rcx
movl $0x13, %esi
movl $0x1, %edx
leaq 0x69a6a(%rip), %rdi     # 0x12d699
callq 0x9750
movq (%r12), %rcx
movl $0xd, %esi
movl $0x1, %edx
leaq 0x69a64(%rip), %rdi     # 0x12d6ad
callq 0x9750
movq (%r12), %rsi
movl $0xa, %edi
callq 0x9480
incl %r14d
cmpl $0x10, %r14d
jne 0xc3b93
jmp 0xc39c5
leaq 0x1791eb(%rip), %rdi    # 0x23ce60
leaq 0x698d5(%rip), %rsi     # 0x12d551
callq 0x9090
testq %rax, %rax
jne 0xc3c9e
leaq 0x1791d3(%rip), %rdi    # 0x23ce60
leaq 0x698c2(%rip), %rsi     # 0x12d556
callq 0x9090
testq %rax, %rax
je 0xc3cc2
leaq 0x17a7a3(%rip), %rax    # 0x23e448
movl $0x12e, (%rax)          # imm = 0x12E
leaq 0x24981e(%rip), %rax    # 0x30d4d0
movl (%rax), %eax
leaq 0x249a49(%rip), %rcx    # 0x30d704
movl %eax, (%rcx)
jmp 0xc39ca
leaq 0x17a77f(%rip), %rax    # 0x23e448
movl $0x0, (%rax)
jmp 0xc39ca