// File: /workspace/github_cpp_makefile_star2_O1/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 0xde0d3
leaq 0x1607af(%rip), %rax    # 0x23e3ec
cmpl $0x0, (%rax)
je 0xde0d3
movl %esi, %r12d
movq %rdi, %rbx
movl $0x1, %r15d
xorl %r14d, %r14d
movl %r15d, %edi
callq 0xdbc92
cmpl $0x1, %eax
sbbl $-0x1, %r14d
incl %r15d
cmpl $0x3e7, %r15d           # imm = 0x3E7
jne 0xddc55
leaq 0x22f8f9(%rip), %r15    # 0x30d570
movsd (%r15), %xmm0
leaq 0x22f8f5(%rip), %rax    # 0x30d578
movsd (%rax), %xmm1
callq 0xddabb
leaq 0x22fa25(%rip), %r13    # 0x30d6b8
movsd (%r13), %xmm0
ucomisd 0x2b3cf(%rip), %xmm0    # 0x109070
jae 0xddd4e
leaq 0x22f9fa(%rip), %rax    # 0x30d6a8
movl (%rax), %r9d
cmpl %r9d, 0x8cb60(%rip)     # 0x16a818
jne 0xdddf2
movl 0x8cb58(%rip), %eax     # 0x16a81c
leaq 0x22f9e1(%rip), %rcx    # 0x30d6ac
cmpl (%rcx), %eax
jne 0xdddf2
movl 0x8cb47(%rip), %eax     # 0x16a820
leaq 0x22f9d0(%rip), %rcx    # 0x30d6b0
cmpl (%rcx), %eax
jne 0xdddf2
movsd 0x29cd00(%rip), %xmm1   # 0x37a9f0
ucomisd %xmm0, %xmm1
jne 0xdddf2
jp 0xdddf2
leaq 0x160881(%rip), %rax    # 0x23e588
cmpl $0x0, (%rax)
je 0xdddf2
movups 0x55c44(%rip), %xmm0    # 0x13395b
leaq 0x25e502(%rip), %rsi    # 0x33c220
movaps %xmm0, 0x20(%rsi)
movups 0x55c22(%rip), %xmm0    # 0x13394b
movaps %xmm0, 0x10(%rsi)
movupd 0x55c06(%rip), %xmm0    # 0x13393b
movapd %xmm0, (%rsi)
movw $0x21, 0x30(%rsi)
leaq 0x4f97a(%rip), %rdx     # 0x12d6c0
movq %rbx, %rdi
callq 0xc3936
movsd 0x29cca2(%rip), %xmm0   # 0x37a9f8
movl $0x1, %edi
callq 0xd0c46
leaq 0x160629(%rip), %rbx    # 0x23e390
movq (%rbx), %rdi
testq %rdi, %rdi
je 0xddd9f
leaq 0x22f932(%rip), %rax    # 0x30d6a8
movl (%rax), %edx
leaq 0x22f92d(%rip), %rax    # 0x30d6ac
movl (%rax), %ecx
leaq 0x22f928(%rip), %rax    # 0x30d6b0
movl (%rax), %r8d
movsd (%r13), %xmm0
leaq 0x55bd5(%rip), %rsi     # 0x13396d
movb $0x1, %al
callq 0x9560
movsd (%r15), %xmm0
movl $0x1, %edi
callq 0xd0c46
movq (%rbx), %rdi
xorl %r15d, %r15d
testq %rdi, %rdi
je 0xde0d3
leaq 0x22f8e4(%rip), %rax    # 0x30d6a8
movl (%rax), %edx
leaq 0x22f8df(%rip), %rax    # 0x30d6ac
movl (%rax), %ecx
leaq 0x22f8da(%rip), %rax    # 0x30d6b0
movl (%rax), %r8d
movsd (%r13), %xmm0
leaq 0x55bd0(%rip), %rsi     # 0x1339b6
movb $0x1, %al
callq 0x9560
jmp 0xde0d3
movl %r9d, 0x8ca1f(%rip)     # 0x16a818
leaq 0x22f8ac(%rip), %rax    # 0x30d6ac
movl (%rax), %r10d
movl %r10d, 0x8ca12(%rip)    # 0x16a81c
leaq 0x22f89f(%rip), %rax    # 0x30d6b0
movl (%rax), %eax
movl %eax, 0x8ca07(%rip)     # 0x16a820
movsd %xmm0, 0x29cbcf(%rip)   # 0x37a9f0
leaq 0x22f52c(%rip), %rcx    # 0x30d354
cmpl $0x0, (%rcx)
jne 0xddf15
leaq 0x22f52c(%rip), %rcx    # 0x30d364
cmpl $0x0, (%rcx)
jne 0xddf15
leaq 0x22f52c(%rip), %rcx    # 0x30d374
cmpl $0x0, (%rcx)
jne 0xddf15
leaq 0x22f52c(%rip), %rcx    # 0x30d384
cmpl $0x0, (%rcx)
jne 0xddf15
leaq 0x22f52c(%rip), %rcx    # 0x30d394
cmpl $0x0, (%rcx)
jne 0xddf15
leaq 0x22f52c(%rip), %rcx    # 0x30d3a4
cmpl $0x0, (%rcx)
jne 0xddf15
leaq 0x22f4c8(%rip), %rcx    # 0x30d350
cmpl $0x0, (%rcx)
jne 0xddf15
leaq 0x22f4c8(%rip), %rcx    # 0x30d360
cmpl $0x0, (%rcx)
jne 0xddf15
leaq 0x22f4cc(%rip), %rcx    # 0x30d370
cmpl $0x0, (%rcx)
jne 0xddf15
leaq 0x22f4d0(%rip), %rcx    # 0x30d380
cmpl $0x0, (%rcx)
jne 0xddf15
leaq 0x22f4d4(%rip), %rcx    # 0x30d390
cmpl $0x0, (%rcx)
jne 0xddf15
leaq 0x22f4d8(%rip), %rcx    # 0x30d3a0
cmpl $0x0, (%rcx)
jne 0xddf15
leaq 0x22f484(%rip), %rcx    # 0x30d358
cmpl $0x0, (%rcx)
jne 0xddf15
leaq 0x22f488(%rip), %rcx    # 0x30d368
cmpl $0x0, (%rcx)
jne 0xddf15
leaq 0x22f48c(%rip), %rcx    # 0x30d378
cmpl $0x0, (%rcx)
jne 0xddf15
leaq 0x22f490(%rip), %rcx    # 0x30d388
cmpl $0x0, (%rcx)
jne 0xddf15
leaq 0x22f494(%rip), %rcx    # 0x30d398
cmpl $0x0, (%rcx)
jne 0xddf15
leaq 0x22f498(%rip), %rcx    # 0x30d3a8
cmpl $0x0, (%rcx)
je 0xddf22
leaq 0x1604d4(%rip), %rcx    # 0x23e3f0
movl $0x1, (%rcx)
leaq 0x160657(%rip), %rcx    # 0x23e580
movsd (%rcx), %xmm1
ucomisd 0x2dad3(%rip), %xmm1    # 0x10ba08
jae 0xddfc1
xorl %ecx, %ecx
testl %r12d, %r12d
cmovnel %ecx, %r14d
leaq 0x22f759(%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 0x22f72e(%rip), %rcx    # 0x30d69c
movl (%rcx), %ecx
leaq 0x22f729(%rip), %rsi    # 0x30d6a0
movl (%rsi), %r8d
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
addsd %xmm1, %xmm0
subq $0x8, %rsp
leaq 0x55a97(%rip), %rsi     # 0x133a27
movq %rbx, %rdi
movb $0x1, %al
pushq %r14
pushq $0x0
pushq %r10
callq 0x9560
addq $0x20, %rsp
testl %r12d, %r12d
je 0xde01b
movl $0xa, %edi
movq %rbx, %rsi
callq 0x9480
movl $0x2, %r15d
jmp 0xde0d3
leaq 0x22f6dc(%rip), %rcx    # 0x30d6a4
movl (%rcx), %edx
leaq 0x22f6cb(%rip), %rcx    # 0x30d69c
movl (%rcx), %ecx
leaq 0x22f6c6(%rip), %rsi    # 0x30d6a0
movl (%rsi), %r8d
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
addsd %xmm1, %xmm0
subq $0x8, %rsp
leaq 0x55a0c(%rip), %rsi     # 0x1339ff
movq %rbx, %rdi
movb $0x1, %al
pushq %r14
pushq $0x0
pushq %r10
callq 0x9560
addq $0x20, %rsp
movl $0x2, %r15d
testl %r12d, %r12d
jne 0xde0d3
jmp 0xde0cd
movl $0x0, -0x2c(%rbp)
movq %rbx, -0x38(%rbp)
movl $0x1, %r15d
xorl %ebx, %ebx
movl $0x1, %r12d
movl %r12d, %edi
callq 0xdbc92
testl %eax, %eax
je 0xde0aa
movl %eax, %r13d
movl %r12d, %edi
callq 0xdb96e
xorl %r15d, %r15d
movq -0x38(%rbp), %rdi
leaq 0x559f4(%rip), %rsi     # 0x133a4d
movl %r13d, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0x9560
incl %ebx
movl -0x2c(%rbp), %eax
incl %eax
movl %eax, -0x2c(%rbp)
cmpl %r14d, %eax
je 0xde0ba
cmpl $0xd, %r14d
setae %al
cmpl $0xc, %ebx
sete %cl
andb %al, %cl
xorl %r15d, %r15d
cmpb $0x1, %cl
jne 0xde0aa
movl $0x21, %esi
movl $0x1, %edx
leaq 0x559b8(%rip), %rdi     # 0x133a54
movq -0x38(%rbp), %rcx
callq 0x9750
xorl %r15d, %r15d
xorl %ebx, %ebx
incl %r12d
cmpl $0x3e7, %r12d           # imm = 0x3E7
jne 0xde034
orl %ebx, %r15d
movq -0x38(%rbp), %rsi
je 0xde0cd
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