// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathmsc.cpp
// Function: write_rinex_obs_header(_IO_FILE*, int)
int write_rinex_obs_header(FILE *file, int no_obs_output)
{
int i;
int no_obs;
int prn;
int p;
char gnss;
int frac;
int col_count;
int out_count;
static int last_hr = (-1);
static int last_min = (-1);
static int last_sec = (-1);
static double last_frac;
static int last_year = 0, last_month = 0,last_day = (-1);
static int last_hours = 0, last_minutes = 0 ,last_seconds = 0;

   // write observation data header for tracked sats
//NEW_RCVR

   if(file == 0) return 0;
   if(rinex_header_written == 0) return 0;

   i = 0;
   for(prn=1; prn<MAX_PRN; prn++) {  // count number of tracked sats
      if(good_raw(prn) == 0) continue;
      ++i;
   }
// if(i == 0) return 0;

   get_obs_time(jd_obs, obs_tow);

   if(g_frac >= 1.0) {
      goto jd_fault;
   }
   frac = (int) (g_frac * 1.0E7);

   if(last_hr != g_hours) ;
   else if(last_min != g_minutes) ;
   else if(last_sec != g_seconds) ;
   else if(last_frac != g_frac) ;
   else if(rinex_fix) {
      sprintf(out, "#! skipped duplicate RINEX observation timestamp!");
      write_rinex_line(file, out, "COMMENT");

      jd_fault:
      gregorian(1, last_jd_obs);
      if(debug_file) fprintf(debug_file, "#! skipped duplicate RINEX observation:  last: %02d:%02d:%02d g_frac:%f\n", g_hours,g_minutes,g_seconds, g_frac);
      gregorian(1, jd_obs);
      if(debug_file) fprintf(debug_file, "                                         this: %02d:%02d:%02d g_frac:%f\n", g_hours,g_minutes,g_seconds, g_frac);
      return 0;
   }

   last_hr = g_hours;     // another duplicate data block prevention check
   last_min = g_minutes;
   last_sec = g_seconds;
   last_frac = g_frac;


#define GOOD_LLI ' '  // '4'
#define BAD_LLI  '1'  // '5'
#define P_MODE   '4'  // tracking P code

   if(have_l1_phase || have_l2_phase || have_l5_phase || have_l6_phase || have_l7_phase || have_l8_phase || 
      have_l1_doppler || have_l2_doppler || have_l5_doppler || have_l6_doppler || have_l7_doppler || have_l8_doppler ||
      have_l1_range || have_l2_range || have_l5_range || have_l6_range || have_l7_range || have_l8_range) {  // dual freq observations
      rinex_obs_written = 1;  // OPUS does not like comments within observation records
   }

   if(rinex_fmt >= 3.0) { // observation header
      fprintf(file, "> %04d %02d %02d %02d %02d%11.7f%3d%3d\n", g_year,g_month,g_day, g_hours,g_minutes,(double)g_seconds+g_frac, 0, i);
      if(no_obs_output) return 2;
      no_obs = 0;
   }
   else {
      if(no_obs_output) i = 0;
      fprintf(file,  " %02d %02d %02d %02d %02d%11.7f%3d%3d", g_year%100,g_month,g_day, g_hours,g_minutes,(double)g_seconds+g_frac, 0, i);
      if(no_obs_output) {
         fprintf(file, "\n");
         return 2;
      }

      no_obs = 1;
      col_count = 0;
      out_count = 0;
      for(prn=1; prn<MAX_PRN; prn++) {  // output list of sats in the observation
         gnss = good_raw(prn);
         if(gnss == 0) continue;
         no_obs = 0;

         p = rinex_prn(prn);  // convert receiver PRN number to RINEX prn value

         fprintf(file, "%c%02d", gnss, p);
         ++col_count;
         ++out_count;
         if(out_count == i) break;
         if((i > 12) && (col_count == 12)) {  // we need a continuation line
            fprintf(file, "\n                                ");
            col_count = 0;
         }
      }
      if(col_count || no_obs) fprintf(file, "\n");
   }

   return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
xorl %r15d, %r15d
testq %rdi, %rdi
je 0xde989
leaq 0x15fef9(%rip), %rax    # 0x23e3ec
cmpl $0x0, (%rax)
je 0xde989
movl %esi, %r12d
movq %rdi, %rbx
movl $0x1, %r15d
xorl %r14d, %r14d
movl %r15d, %edi
callq 0xdc2fb
cmpl $0x1, %eax
sbbl $-0x1, %r14d
incl %r15d
cmpl $0x3e7, %r15d           # imm = 0x3E7
jne 0xde50b
leaq 0x22f043(%rip), %r15    # 0x30d570
movsd (%r15), %xmm0
leaq 0x22f03f(%rip), %rax    # 0x30d578
movsd (%rax), %xmm1
callq 0xde371
leaq 0x22f16f(%rip), %r13    # 0x30d6b8
movsd (%r13), %xmm0
ucomisd 0x2ab19(%rip), %xmm0    # 0x109070
jae 0xde606
leaq 0x22f144(%rip), %rax    # 0x30d6a8
movl (%rax), %r9d
leaq 0x22f13e(%rip), %rax    # 0x30d6ac
movl (%rax), %r10d
cmpl %r9d, 0x8c2a0(%rip)     # 0x16a818
jne 0xde6aa
leaq 0x22f12b(%rip), %rax    # 0x30d6b0
movl (%rax), %eax
cmpl %r10d, 0x8c28e(%rip)    # 0x16a81c
jne 0xde6b3
cmpl %eax, 0x8c286(%rip)     # 0x16a820
jne 0xde6b3
movsd 0x29c448(%rip), %xmm1   # 0x37a9f0
ucomisd %xmm0, %xmm1
jne 0xde6b3
jp 0xde6b3
leaq 0x15ffc9(%rip), %rcx    # 0x23e588
cmpl $0x0, (%rcx)
je 0xde6b3
movups 0x5547c(%rip), %xmm0    # 0x133a4b
leaq 0x25dc4a(%rip), %rsi    # 0x33c220
movaps %xmm0, 0x20(%rsi)
movups 0x5545a(%rip), %xmm0    # 0x133a3b
movaps %xmm0, 0x10(%rsi)
movupd 0x5543e(%rip), %xmm0    # 0x133a2b
movapd %xmm0, (%rsi)
movw $0x21, 0x30(%rsi)
leaq 0x4f1b2(%rip), %rdx     # 0x12d7b0
movq %rbx, %rdi
callq 0xc3f69
movsd 0x29c3ea(%rip), %xmm0   # 0x37a9f8
movl $0x1, %edi
callq 0xd12da
leaq 0x15fd71(%rip), %rbx    # 0x23e390
movq (%rbx), %rdi
testq %rdi, %rdi
je 0xde657
leaq 0x22f07a(%rip), %rax    # 0x30d6a8
movl (%rax), %edx
leaq 0x22f075(%rip), %rax    # 0x30d6ac
movl (%rax), %ecx
leaq 0x22f070(%rip), %rax    # 0x30d6b0
movl (%rax), %r8d
movsd (%r13), %xmm0
leaq 0x5540d(%rip), %rsi     # 0x133a5d
movb $0x1, %al
callq 0x9560
movsd (%r15), %xmm0
movl $0x1, %edi
callq 0xd12da
movq (%rbx), %rdi
xorl %r15d, %r15d
testq %rdi, %rdi
je 0xde989
leaq 0x22f02c(%rip), %rax    # 0x30d6a8
movl (%rax), %edx
leaq 0x22f027(%rip), %rax    # 0x30d6ac
movl (%rax), %ecx
leaq 0x22f022(%rip), %rax    # 0x30d6b0
movl (%rax), %r8d
movsd (%r13), %xmm0
leaq 0x55408(%rip), %rsi     # 0x133aa6
movb $0x1, %al
callq 0x9560
jmp 0xde989
leaq 0x22efff(%rip), %rax    # 0x30d6b0
movl (%rax), %eax
movl %r9d, 0x8c15e(%rip)     # 0x16a818
movl %r10d, 0x8c15b(%rip)    # 0x16a81c
movl %eax, 0x8c159(%rip)     # 0x16a820
movsd %xmm0, 0x29c321(%rip)   # 0x37a9f0
leaq 0x22ec7e(%rip), %rcx    # 0x30d354
cmpl $0x0, (%rcx)
jne 0xde7c3
leaq 0x22ec7e(%rip), %rcx    # 0x30d364
cmpl $0x0, (%rcx)
jne 0xde7c3
leaq 0x22ec7e(%rip), %rcx    # 0x30d374
cmpl $0x0, (%rcx)
jne 0xde7c3
leaq 0x22ec7e(%rip), %rcx    # 0x30d384
cmpl $0x0, (%rcx)
jne 0xde7c3
leaq 0x22ec7e(%rip), %rcx    # 0x30d394
cmpl $0x0, (%rcx)
jne 0xde7c3
leaq 0x22ec7e(%rip), %rcx    # 0x30d3a4
cmpl $0x0, (%rcx)
jne 0xde7c3
leaq 0x22ec1a(%rip), %rcx    # 0x30d350
cmpl $0x0, (%rcx)
jne 0xde7c3
leaq 0x22ec1a(%rip), %rcx    # 0x30d360
cmpl $0x0, (%rcx)
jne 0xde7c3
leaq 0x22ec1e(%rip), %rcx    # 0x30d370
cmpl $0x0, (%rcx)
jne 0xde7c3
leaq 0x22ec22(%rip), %rcx    # 0x30d380
cmpl $0x0, (%rcx)
jne 0xde7c3
leaq 0x22ec26(%rip), %rcx    # 0x30d390
cmpl $0x0, (%rcx)
jne 0xde7c3
leaq 0x22ec2a(%rip), %rcx    # 0x30d3a0
cmpl $0x0, (%rcx)
jne 0xde7c3
leaq 0x22ebd6(%rip), %rcx    # 0x30d358
cmpl $0x0, (%rcx)
jne 0xde7c3
leaq 0x22ebda(%rip), %rcx    # 0x30d368
cmpl $0x0, (%rcx)
jne 0xde7c3
leaq 0x22ebde(%rip), %rcx    # 0x30d378
cmpl $0x0, (%rcx)
jne 0xde7c3
leaq 0x22ebe2(%rip), %rcx    # 0x30d388
cmpl $0x0, (%rcx)
jne 0xde7c3
leaq 0x22ebe6(%rip), %rcx    # 0x30d398
cmpl $0x0, (%rcx)
jne 0xde7c3
leaq 0x22ebea(%rip), %rcx    # 0x30d3a8
cmpl $0x0, (%rcx)
je 0xde7d0
leaq 0x15fc26(%rip), %rcx    # 0x23e3f0
movl $0x1, (%rcx)
leaq 0x15fda9(%rip), %rcx    # 0x23e580
movsd (%rcx), %xmm1
ucomisd 0x2d225(%rip), %xmm1    # 0x10ba08
jae 0xde873
testl %r12d, %r12d
movl $0x0, %r15d
cmovel %r14d, %r15d
leaq 0x22eea7(%rip), %rcx    # 0x30d6a4
movslq (%rcx), %rdx
imulq $0x51eb851f, %rdx, %rcx # imm = 0x51EB851F
movq %rcx, %rsi
shrq $0x3f, %rsi
sarq $0x25, %rcx
addl %esi, %ecx
imull $0x64, %ecx, %ecx
subl %ecx, %edx
leaq 0x22ee7c(%rip), %rcx    # 0x30d69c
movl (%rcx), %ecx
leaq 0x22ee77(%rip), %rsi    # 0x30d6a0
movl (%rsi), %r8d
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
addsd %xmm1, %xmm0
subq $0x8, %rsp
leaq 0x552d5(%rip), %rsi     # 0x133b17
movq %rbx, %rdi
movb $0x1, %al
pushq %r15
pushq $0x0
pushq %r10
callq 0x9560
addq $0x20, %rsp
testl %r12d, %r12d
je 0xde8cd
movl $0xa, %edi
movq %rbx, %rsi
callq 0x9480
movl $0x2, %r15d
jmp 0xde989
leaq 0x22ee2a(%rip), %rcx    # 0x30d6a4
movl (%rcx), %edx
leaq 0x22ee19(%rip), %rcx    # 0x30d69c
movl (%rcx), %ecx
leaq 0x22ee14(%rip), %rsi    # 0x30d6a0
movl (%rsi), %r8d
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
addsd %xmm1, %xmm0
subq $0x8, %rsp
leaq 0x5524a(%rip), %rsi     # 0x133aef
movq %rbx, %rdi
movb $0x1, %al
pushq %r14
pushq $0x0
pushq %r10
callq 0x9560
addq $0x20, %rsp
movl $0x2, %r15d
testl %r12d, %r12d
jne 0xde989
jmp 0xde983
movq %r15, -0x40(%rbp)
movl $0x0, -0x2c(%rbp)
movq %rbx, -0x38(%rbp)
movl $0x1, %r15d
xorl %ebx, %ebx
movl $0x1, %r12d
movl %r12d, %edi
callq 0xdc2fb
testl %eax, %eax
je 0xde960
movl %eax, %r13d
movl %r12d, %edi
callq 0xdc01f
xorl %r15d, %r15d
movq -0x38(%rbp), %rdi
leaq 0x5522e(%rip), %rsi     # 0x133b3d
movl %r13d, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0x9560
incl %ebx
movl -0x2c(%rbp), %eax
incl %eax
movl %eax, -0x2c(%rbp)
cmpl -0x40(%rbp), %eax
je 0xde970
cmpl $0xd, %r14d
setae %al
cmpl $0xc, %ebx
sete %cl
andb %al, %cl
xorl %r15d, %r15d
cmpb $0x1, %cl
jne 0xde960
movl $0x21, %esi
movl $0x1, %edx
leaq 0x551f2(%rip), %rdi     # 0x133b44
movq -0x38(%rbp), %rcx
callq 0x9750
xorl %r15d, %r15d
xorl %ebx, %ebx
incl %r12d
cmpl $0x3e7, %r12d           # imm = 0x3E7
jne 0xde8ea
orl %ebx, %r15d
movq -0x38(%rbp), %rsi
je 0xde983
movl $0xa, %edi
callq 0x9480
movl $0x1, %r15d
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq