// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heather.cpp
// Function: main
int main(int argc, char *argv[])
{
   #ifdef USE_X11
      if(argv[0]) strcpy(exe_name, argv[0]);
      printf("argv[0] (%s)\n", argv[0]);
   #endif

   config_program(argc, argv);  // process command line arguments

   if(1) ;
   else if(((rcvr_type == NO_RCVR) || (rcvr_type == TIDE_RCVR)) && (com[RCVR_PORT].process_com == 0)) {
      com[RCVR_PORT].process_com = 1;
      com[RCVR_PORT].user_disabled_com = 0;
   }

   #ifdef WIN_VFX
     get_screen_size(0);
     if(display_width == 1280) {
        vfx_full:
        if(vfx_fullscreen) {
           SAL_set_preference(SAL_MAXIMIZE_TO_FULLSCREEN, YES);
           initial_window_mode = VFX_TRY_FULLSCREEN;
        }
     }
     else if(display_width == 1024) goto vfx_full;
     else if(display_width == 800)  goto vfx_full;
     else if(display_width == 640)  goto vfx_full;
   #endif

   if(jpl_clock) {
      if(dst_ofs)            time_color = DST_TIME_COLOR;
      else if(time_zone_set) time_color = DST_TIME_COLOR;  // !!! std_time_color is rather dim for the big clock
      else                   time_color = WHITE;
   }

   if(luxor) {
      config_luxor_plots();
   }

   find_endian();     // determine machine byte ordering
   alloc_memory();    // allocate memory for plot and adev queues, etc
   adjust_view();     // tweak screen for user selected view interval, etc


   init_hardware();   // initialize the com port, screen, and any other hardware
   hw_setup = 1;
   update_pwm();

   if(temp_script) {  // heather.cfg created a temporary keyboard script file, process it
      fclose(temp_script);
      temp_script = 0;
      open_script(TEMP_SCRIPT);
   }

   if(take_a_dump) {
      dump_stream(1);
   }

   #ifdef PLM
      init_pl_timer();// setup to monitor power line freq
   #endif
   config_tz_info();  // try to get time zone info from the system
   config_options();  // configure system for command line options

   // user set a log param on the command line, start writing the log file
   if(user_set_log) {
      log_file_time = log_interval + 1;
      open_log_file(log_mode);
      rinex_header_written = 0;
   }

   if(need_debug_log) {
      need_debug_log = 0;
      if(debug_file) fclose(debug_file);
      debug_file = 0;
      debug_name[0] = 0;

      sprintf(out, "debug.log");
      open_debug_file(out);
   }

   if(need_rinex_file) {
      need_rinex_file = 0;
      if(rinex_file) fclose(rinex_file);
      rinex_file = 0;
      rinex_name[0] = 0;

      set_rinex_name();  // into string "out"
      if(out[0]) open_rinex_file(out);
   }

   if(need_raw_file) {  // open raw receiver log file specified on the command line
      need_raw_file = 0;
      if(raw_file) fclose(raw_file);
      raw_file = 0;
      sprintf(raw_name, "%s.raw", "heather");
      raw_file = open_raw_file(raw_name, "wb");
      if(raw_file) log_stream |= LOG_RAW_STREAM;
   }

   if(need_prn_file) {  // open raw receiver log file specified on the command line
      need_prn_file = 0;
      if(prn_file) fclose(prn_file);
      prn_file = 0;
      sprintf(prn_name, "%s.prn", "heather");
      prn_file = open_prn_file(prn_name, "wb");
   }

   if(need_ticc_file) {  // open ticc log file specified on the command line
      need_ticc_file = 0;
      if(ticc_file) fclose(ticc_file);
      ticc_file = 0;
      sprintf(ticc_name, "%s.raw", "ticc");
      ticc_file = topen(ticc_name, "wb");
// aaattt      if(raw_file) log_stream |= LOG_RAW_STREAM;
   }

   if(detect_rcvr_type) {
      auto_detect(0);
      if(rcvr_type == TICC_RCVR) {  // xyzzy  disable watch/azel/signals
         reset_com_timer(RCVR_PORT);
         init_screen(5395);
         reset_com_timer(RCVR_PORT);
not_safe = 3;
      }
   }

   if(ticc_type == PICPET_TICC) {  // scale PICPET wrap interval to 10 MHz clock equivalent
      if(rcvr_type == TICC_RCVR) {
         pet_clock = (double) com[RCVR_PORT].baud_rate / 19200.0;
         if(timestamp_wrap == 0.0) timestamp_wrap = 100.0 / pet_clock;
      }
      else if(ticc_port_open()) {
         pet_clock = (double) com[TICC_PORT].baud_rate / 19200.0;
         if(timestamp_wrap == 0.0) timestamp_wrap = 100.0 / pet_clock;
      }
   }

   if(NO_SATS || (rcvr_type == TIDE_RCVR)) {  // try to get default user position from file
      read_default_lla();
   }

   if(enviro_mode()) {
      config_enviro_plots(1);
   }

   if(user_set_title_bar) { // set title bar text
      set_title_bar(0);
   }
   else if(unit_file_name == 0) {
   }
   else if(unit_file_name[0]) {
      strcpy(szAppName, unit_file_name);
      strupr(szAppName);
szAppName[0] = 0;
      user_set_title_bar = 2;
      set_title_bar(2);
   }

   if(TICC_USED) no_adev_flag = 0;
   else if(0 && no_adev_flag) {
      free_mtie();
      free_adev_queues();

      adev_q_size = 0;
      // disable adevs... if you re-enable them you will need to use
      // the /j command to reset the adev period to a non-zero value!!!!!
      adev_q_size = 1L;
      adev_period = 0.0;
      pps_adev_period = adev_period;
      osc_adev_period = adev_period;
      chc_adev_period = adev_period;
      chd_adev_period = adev_period;
      save_adev_period();
   }

   plot_axes();         // draw graph axes
   if(luxor) reset_luxor_wdt(1);
   show_version_header();
   show_log_state();    // show logging state
   show_com_state();    // show com port state and flush buffer
   get_log_file();      // read in any initial log file
   read_rpn_file(rpn_name, 1);  // read in any calculator user defined functions

   if(monitor_mode) {
      set_monitor_mode(0); // port monitor
   }
   else if(enable_terminal) {
      do_term(term_port);  // debug terminal
      if(rcvr_type == NO_RCVR) goto exit_pgm;
      if(rcvr_type == TERM_RCVR) goto exit_pgm;
   }

   reset_com_timer(RCVR_PORT);

   if(need_view_auto) {     // force a VT auto view command
      add_kbd('v');
      add_kbd('t');
      add_kbd(0x0D);
   }

   if(calc_rcvr) {
      start_calc_zoom(1);
   }

   do_gps();            // run the receiver until something says stop

   exit_pgm:
   clean_up();          // leave the receiver in a nice stand-alone state
   shut_down(0);        // clean up remaining details and exit
   return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rsi, %rbx
movl %edi, %r14d
movq (%rsi), %rsi
testq %rsi, %rsi
jne 0x1f021
xorl %esi, %esi
jmp 0x1f030
leaq 0x30adb8(%rip), %rdi    # 0x329de0
callq 0x9330
movq (%rbx), %rsi
leaq 0xd65a8(%rip), %rdi     # 0xf55df
xorl %eax, %eax
callq 0x9030
movl %r14d, %edi
movq %rbx, %rsi
callq 0x1ece7
cmpl $0x0, 0x1e379c(%rip)    # 0x2027ec
je 0x1f078
cmpl $0x0, 0x2d8847(%rip)    # 0x2f78a0
sete %al
cmpb $0x0, 0x2d8831(%rip)    # 0x2f7894
sete %cl
andb %al, %cl
movzbl %cl, %eax
leal 0xb(,%rax,4), %eax
movl %eax, 0x1ee55c(%rip)    # 0x20d5d4
cmpb $0x0, 0x209ebf(%rip)    # 0x228f3e
je 0x1f086
callq 0x45f25
testl $0x400904, 0x1e3840(%rip) # imm = 0x400904
setne 0x1e373d(%rip)          # 0x2027d4
callq 0x10483
callq 0x1bc03
callq 0xbbdb
movl $0x1, 0x1e5f84(%rip)    # 0x205034
callq 0xc067d
movq 0x2092f4(%rip), %rdi    # 0x2283b0
testq %rdi, %rdi
je 0x1f0da
callq 0x9360
andq $0x0, 0x2092e2(%rip)    # 0x2283b0
leaq 0xd5ced(%rip), %rdi     # 0xf4dc2
callq 0x1bfce
cmpl $0x0, 0x209e6f(%rip)    # 0x228f50
jne 0x1f343
callq 0x1ee69
callq 0xd5b6
cmpb $0x0, 0x209304(%rip)    # 0x2283fc
je 0x1f11e
movq 0x1e62a7(%rip), %rax    # 0x2053a8
incq %rax
movq %rax, 0x2092f5(%rip)    # 0x228400
movq 0x209246(%rip), %rdi    # 0x228358
callq 0xb2773
andl $0x0, 0x2092ce(%rip)    # 0x2283ec
cmpb $0x0, 0x2092c3(%rip)    # 0x2283e8
je 0x1f174
movb $0x0, 0x2092ba(%rip)    # 0x2283e8
movq 0x20925b(%rip), %rdi    # 0x228390
testq %rdi, %rdi
je 0x1f13f
callq 0x9360
andq $0x0, 0x209249(%rip)    # 0x228390
movb $0x0, 0x208912(%rip)    # 0x227a60
movabsq $0x6f6c2e6775626564, %rax # imm = 0x6F6C2E6775626564
movq %rax, 0x3070c1(%rip)    # 0x326220
movw $0x67, 0x3070c0(%rip)   # 0x326228
leaq 0x3070b1(%rip), %rdi    # 0x326220
callq 0xa2ae
cmpb $0x0, 0x20926e(%rip)    # 0x2283e9
je 0x1f1be
movb $0x0, 0x209265(%rip)    # 0x2283e9
movq 0x2091dd(%rip), %rdi    # 0x228368
testq %rdi, %rdi
je 0x1f195
callq 0x9360
andq $0x0, 0x2091cb(%rip)    # 0x228368
movb $0x0, 0x207dbc(%rip)    # 0x226f60
callq 0xa330
cmpb $0x0, 0x307070(%rip)    # 0x326220
je 0x1f1be
leaq 0x307067(%rip), %rdi    # 0x326220
callq 0xa447
cmpb $0x0, 0x20921f(%rip)    # 0x2283e4
je 0x1f228
movb $0x0, 0x209216(%rip)    # 0x2283e4
movq 0x20919b(%rip), %rdi    # 0x228370
testq %rdi, %rdi
je 0x1f1df
callq 0x9360
andq $0x0, 0x209189(%rip)    # 0x228370
leaq 0x207e72(%rip), %rbx    # 0x227060
leaq 0xd63f8(%rip), %rsi     # 0xf55ed
leaq 0xd48ae(%rip), %rdx     # 0xf3aaa
movq %rbx, %rdi
xorl %eax, %eax
callq 0x9060
leaq 0xd4db1(%rip), %rsi     # 0xf3fbe
movq %rbx, %rdi
callq 0xa50c
movq %rax, 0x209154(%rip)    # 0x228370
testq %rax, %rax
je 0x1f228
orb $0x8, 0x2091e8(%rip)    # 0x228410
cmpb $0x0, 0x2091b6(%rip)    # 0x2283e5
je 0x1f286
movb $0x0, 0x2091ad(%rip)    # 0x2283e5
movq 0x209139(%rip), %rdi    # 0x228378
testq %rdi, %rdi
je 0x1f249
callq 0x9360
andq $0x0, 0x209127(%rip)    # 0x228378
leaq 0x207f08(%rip), %rbx    # 0x227160
leaq 0xd6395(%rip), %rsi     # 0xf55f4
leaq 0xd4844(%rip), %rdx     # 0xf3aaa
movq %rbx, %rdi
xorl %eax, %eax
callq 0x9060
leaq 0xd4d47(%rip), %rsi     # 0xf3fbe
movq %rbx, %rdi
callq 0xa5c9
movq %rax, 0x2090f2(%rip)    # 0x228378
cmpb $0x0, 0x20915a(%rip)    # 0x2283e7
je 0x1f2e4
movb $0x0, 0x209151(%rip)    # 0x2283e7
movq 0x2090eb(%rip), %rdi    # 0x228388
testq %rdi, %rdi
je 0x1f2a7
callq 0x9360
andq $0x0, 0x2090d9(%rip)    # 0x228388
leaq 0x207faa(%rip), %rbx    # 0x227260
leaq 0xd6330(%rip), %rsi     # 0xf55ed
leaq 0xd6337(%rip), %rdx     # 0xf55fb
movq %rbx, %rdi
xorl %eax, %eax
callq 0x9060
leaq 0xd4ce9(%rip), %rsi     # 0xf3fbe
movq %rbx, %rdi
callq 0x9a22
movq %rax, 0x2090a4(%rip)    # 0x228388
cmpl $0x0, 0x1e5cdd(%rip)    # 0x204fc8
je 0x1f323
xorl %edi, %edi
callq 0x5a086
cmpq $0x10000, 0x1e35d1(%rip) # imm = 0x10000
jne 0x1f323
pushq $0xa
popq %rbx
movl %ebx, %edi
callq 0x1d93f
movl $0x1513, %edi           # imm = 0x1513
callq 0xbc0b
movl %ebx, %edi
callq 0x1d93f
movb $0x3, 0x2d8b4a(%rip)    # 0x2f7e6d
cmpl $0x50, 0x1e35de(%rip)   # 0x202908
jne 0x1f394
cmpq $0x10000, 0x1e3599(%rip) # imm = 0x10000
jne 0x1f34b
cvtsi2sdl 0x2ee96f(%rip), %xmm0 # 0x30dcb0
jmp 0x1f35c
pushq $0x1
popq %rdi
callq 0x1e6df
callq 0x66b41
testl %eax, %eax
je 0x1f394
cvtsi2sdl 0x2f5074(%rip), %xmm0 # 0x3143d0
divsd 0xd3e1c(%rip), %xmm0    # 0xf3180
movsd %xmm0, 0x2d7684(%rip)   # 0x2f69f0
movsd 0x2d7684(%rip), %xmm1   # 0x2f69f8
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
jne 0x1f394
jp 0x1f394
movsd 0xd3cd8(%rip), %xmm1    # 0xf3060
divsd %xmm0, %xmm1
movsd %xmm1, 0x2d7664(%rip)   # 0x2f69f8
movq 0x1e3535(%rip), %rax    # 0x2028d0
movabsq $0x105b8b0400, %rcx     # imm = 0x105B8B0400
testq %rcx, %rax
jne 0x1f3c4
cmpl $0x0, 0x1e5c1f(%rip)    # 0x204fd0
je 0x1f4fd
cmpl $0x0, 0x2d8006(%rip)    # 0x2f73c4
jne 0x1f4fd
callq 0x1eecd
callq 0x57eca
testl %eax, %eax
je 0x1f3da
pushq $0x1
popq %rdi
callq 0x362c5
cmpl $0x0, 0x309357(%rip)    # 0x328738
jne 0x1f41c
movq 0x13b89e(%rip), %rsi    # 0x15ac88
testq %rsi, %rsi
je 0x1f421
cmpb $0x0, (%rsi)
je 0x1f421
leaq 0x128815(%rip), %rbx    # 0x147c10
movq %rbx, %rdi
callq 0x9330
movq %rbx, %rdi
callq 0x988f
movb $0x0, 0x1287fe(%rip)    # 0x147c10
movl $0x2, 0x30931c(%rip)    # 0x328738
callq 0xda3d
cmpq $0x10000, 0x1e34a4(%rip) # imm = 0x10000
je 0x1f437
callq 0x66b41
testl %eax, %eax
je 0x1f43e
andl $0x0, 0x2078f6(%rip)    # 0x226d34
callq 0x1776e
cmpb $0x0, 0x209af4(%rip)    # 0x228f3e
je 0x1f454
pushq $0x1
popq %rdi
callq 0x72eff
callq 0x68b5b
callq 0xb1018
callq 0x1d981
callq 0x1db42
leaq 0x2081f1(%rip), %rdi    # 0x227660
pushq $0x1
popq %rsi
callq 0x21774
cmpl $0x0, 0x208fba(%rip)    # 0x228438
jne 0x1f4ad
cmpl $0x0, 0x209aa9(%rip)    # 0x228f30
je 0x1f4b2
movl 0x2d8e45(%rip), %edi    # 0x2f82d4
callq 0x1e22b
movq 0x1e3435(%rip), %rax    # 0x2028d0
cmpq $0x400, %rax            # imm = 0x400
je 0x1f4f1
cmpq $0x4000000, %rax        # imm = 0x4000000
je 0x1f4f1
jmp 0x1f4b2
callq 0x1e1e2
pushq $0xa
popq %rdi
callq 0x1d93f
cmpl $0x0, 0x1e5eff(%rip)    # 0x2053c0
je 0x1f4db
pushq $0x76
popq %rdi
callq 0xd140
pushq $0x74
popq %rdi
callq 0xd140
pushq $0xd
popq %rdi
callq 0xd140
cmpl $0x0, 0x1e33fe(%rip)    # 0x2028e0
je 0x1f4ec
pushq $0x1
popq %rdi
callq 0x1f6f0
callq 0x1ea58
callq 0x1dbaa
xorl %edi, %edi
callq 0xd8d5
cmpq $0x400000, %rax         # imm = 0x400000
sete %cl
cmpl $0x0, 0x2d84a7(%rip)    # 0x2f79b4
sete %dl
cmpq $0x800000, %rax         # imm = 0x800000
je 0x1f3c4
andb %dl, %cl
je 0x1f3c9
jmp 0x1f3c4