// File: /workspace/github_cpp_makefile_star2_O1/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 0xc36a3
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x17b0c1(%rip), %r12    # 0x23e360
cmpq $0x0, (%r12)
jne 0xc3695
movq %rdi, %rbx
leaq 0x179bac(%rip), %rdi    # 0x23ce60
movl $0x2a, %esi
callq 0x9100
testq %rax, %rax
je 0xc32cd
movb $0x0, (%rax)
movl $0x1, %eax
jmp 0xc32cf
xorl %eax, %eax
leaq 0x17b14a(%rip), %r14    # 0x23e420
movl %eax, (%r14)
leaq 0x179b80(%rip), %rdi    # 0x23ce60
movq %rbx, %rsi
callq 0x9a4d
movq %rax, (%r12)
testq %rax, %rax
je 0xc3619
leaq 0x17b094(%rip), %rax    # 0x23e390
movq (%rax), %rdi
testq %rdi, %rdi
je 0xc3319
leaq 0x6a127(%rip), %rsi     # 0x12d432
leaq 0x179b4e(%rip), %rdx    # 0x23ce60
xorl %eax, %eax
callq 0x9560
leaq 0x17b0d8(%rip), %rax    # 0x23e3f8
cmpb $0x0, (%rax)
je 0xc332f
leaq 0x17b0be(%rip), %rax    # 0x23e3ea
movb $0x0, (%rax)
leaq 0x17b0c4(%rip), %rax    # 0x23e3fa
movb $0x0, (%rax)
callq 0xc1a24
leaq 0x158063(%rip), %rax    # 0x21b3a8
movq (%rax), %rax
incq %rax
leaq 0x17b0ae(%rip), %rcx    # 0x23e400
movq %rax, (%rcx)
leaq 0x179b04(%rip), %rdi    # 0x23ce60
leaq 0x5acac(%rip), %rsi     # 0x11e00f
callq 0x9090
movl $0xa, %ebx
testq %rax, %rax
jne 0xc3438
leaq 0x179ae3(%rip), %rdi    # 0x23ce60
leaq 0x6a0c4(%rip), %rsi     # 0x12d448
callq 0x9090
testq %rax, %rax
jne 0xc3438
leaq 0x179ac7(%rip), %rdi    # 0x23ce60
leaq 0x6a0ad(%rip), %rsi     # 0x12d44d
callq 0x9090
movl $0x14, %ebx
testq %rax, %rax
jne 0xc3438
leaq 0x179aa6(%rip), %rdi    # 0x23ce60
leaq 0x6a091(%rip), %rsi     # 0x12d452
callq 0x9090
testq %rax, %rax
jne 0xc3438
leaq 0x179a8e(%rip), %rdi    # 0x23ce60
leaq 0x6a07e(%rip), %rsi     # 0x12d457
callq 0x9090
movl $0x1e, %ebx
testq %rax, %rax
jne 0xc3438
leaq 0x179a71(%rip), %rdi    # 0x23ce60
leaq 0x6a066(%rip), %rsi     # 0x12d45c
callq 0x9090
testq %rax, %rax
jne 0xc3438
leaq 0x179a59(%rip), %rdi    # 0x23ce60
leaq 0x6a053(%rip), %rsi     # 0x12d461
callq 0x9090
movl $0x12e, %ebx            # imm = 0x12E
testq %rax, %rax
jne 0xc3438
leaq 0x179a3c(%rip), %rdi    # 0x23ce60
leaq 0x6a03b(%rip), %rsi     # 0x12d466
callq 0x9090
xorl %ecx, %ecx
testq %rax, %rax
cmovel %ecx, %ebx
leaq 0x17b009(%rip), %rax    # 0x23e448
movl %ebx, (%rax)
testl %ebx, %ebx
je 0xc3674
leaq 0x24a080(%rip), %rax    # 0x30d4d0
movl (%rax), %eax
leaq 0x24a2ab(%rip), %rcx    # 0x30d704
movl %eax, (%rcx)
cmpl $0xa, %ebx
je 0xc3626
cmpl $0x14, %ebx
je 0xc361d
cmpl $0x1e, %ebx
jne 0xc3674
movq (%r12), %rcx
leaq 0x6a04b(%rip), %rdi     # 0x12d4cc
movl $0x28, %esi
movl $0x1, %edx
callq 0x9750
movq (%r12), %rcx
leaq 0x6a05a(%rip), %rdi     # 0x12d4f5
movl $0x2d, %esi
movl $0x1, %edx
callq 0x9750
movq (%r12), %rsi
movl $0xa, %edi
callq 0x9480
movq (%r12), %rcx
leaq 0x6a060(%rip), %rdi     # 0x12d523
movl $0xd, %esi
movl $0x1, %edx
callq 0x9750
movq (%r12), %rcx
leaq 0x5f596(%rip), %rdi     # 0x122a73
movl $0x2, %esi
movl $0x1, %edx
callq 0x9750
callq 0xc272c
movq (%r12), %rcx
leaq 0x69631(%rip), %rdi     # 0x12cb2d
movl $0x1f, %esi
movl $0x1, %edx
callq 0x9750
movq (%r12), %rcx
leaq 0x6a01b(%rip), %rdi     # 0x12d531
movl $0x13, %esi
movl $0x1, %edx
callq 0x9750
movq (%r12), %rsi
movl $0xa, %edi
callq 0x9480
movl $0xff, %r13d
leaq 0x6a07d(%rip), %rbx     # 0x12d5bd
xorl %r14d, %r14d
movl %r14d, %edi
callq 0xf410
movl %eax, %ecx
andl $0xff00, %ecx           # imm = 0xFF00
movl %eax, %edx
andl %r13d, %edx
shll $0x10, %edx
orl %ecx, %edx
shrl $0x10, %eax
andl %r13d, %eax
leal (%rax,%rdx), %r15d
addl $0x64000000, %r15d      # imm = 0x64000000
movq (%r12), %rdi
leaq 0x69fcc(%rip), %rsi     # 0x12d545
movl %r14d, %edx
xorl %eax, %eax
callq 0x9560
movq (%r12), %rcx
movl $0x12, %esi
movl $0x1, %edx
leaq 0x69fc7(%rip), %rdi     # 0x12d55f
callq 0x9750
movq (%r12), %rdi
leaq 0x69fca(%rip), %rsi     # 0x12d572
movl %r15d, %edx
xorl %eax, %eax
callq 0x9560
movq (%r12), %rcx
movl $0x19, %esi
movl $0x1, %edx
leaq 0x69fc8(%rip), %rdi     # 0x12d58f
callq 0x9750
movq (%r12), %rcx
movl $0x13, %esi
movl $0x1, %edx
leaq 0x69fc8(%rip), %rdi     # 0x12d5a9
callq 0x9750
movq (%r12), %rcx
movl $0xd, %esi
movl $0x1, %edx
movq %rbx, %rdi
callq 0x9750
movq (%r12), %rsi
movl $0xa, %edi
callq 0x9480
incl %r14d
cmpl $0x10, %r14d
jne 0xc3543
jmp 0xc3668
xorl %eax, %eax
jmp 0xc3695
leaq 0x69e71(%rip), %rbx     # 0x12d495
jmp 0xc362d
leaq 0x69f9e(%rip), %rbx     # 0x12d5cb
movq (%r12), %rcx
leaq 0x69e33(%rip), %rdi     # 0x12d46b
movl $0x29, %esi
movl $0x1, %edx
callq 0x9750
movq (%r12), %rdi
leaq 0x4a467(%rip), %rdx     # 0x10dab9
leaq 0x15fef7(%rip), %rcx    # 0x223550
movq %rbx, %rsi
xorl %eax, %eax
callq 0x9560
callq 0xc272c
callq 0xc2351
leaq 0x17adac(%rip), %r14    # 0x23e420
cmpl $0x0, (%r14)
setne %al
movq (%r12), %rdi
testq %rdi, %rdi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xc3691
callq 0x9420
movq (%r12), %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq