// File: /workspace/github_cpp_makefile_star2_O1/DoubleString[P]RtConverter/src/Rtklib/rt17.cpp
// Function: bamboo::GetWeek(bamboo::raw_t*, double)
static int GetWeek(raw_t *Raw, double Tow)
{
    rt17_t *rt17 = (rt17_t*) Raw->rcv_data;
    int Week = 0;

    if (rt17->Flags & M_WEEK_OPTION)
    {
        if ((Tow && rt17->Tow) && (Tow < rt17->Tow))
        {
            tracet(2, "RT17: GPS WEEK rolled over from %d to %d.\n", rt17->Week, rt17->Week + 1);
            rt17->Week++;
        }

        if (Tow != 0.0)
            rt17->Tow = Tow;
    }
    else if (!(rt17->Flags & M_WEEK_SCAN))
    {
        char *opt = strstr(Raw->opt, "-WEEK=");

        rt17->Flags |= M_WEEK_SCAN;

        if (opt)
        {
            if (!sscanf(opt+6, "%d", &Week) || (Week <= 0))
                tracet(0, "RT17: Invalid -WEEK=n receiver option value.\n");
            else
            {
                rt17->Week = Week;
                rt17->Flags |= M_WEEK_OPTION;
                tracet(2, "RT17: Initial GPS WEEK explicitly set to %d by user.\n", Week, Week);
            }
        }
    }

    Week = rt17->Week;

    if (!Week && !(rt17->Flags & (M_WEEK_OPTION|M_WEEK_EPH)))
    {
        if ((Raw->time.time == 0) && (Raw->time.sec == 0.0))
            Raw->time = timeget();
        
        time2gpst(Raw->time, &Week);

        if (Tow != 0.0)
            Raw->time = gpst2time(Week, Tow);

        rt17->Week = Week;
        rt17->Flags |= M_WEEK_TIME; 
        tracet(2, "RT17: Initial GPS WEEK number unknown; WEEK number %d assumed for now.\n", Week);       
    }
 
    return Week;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq 0x82ba0(%rdi), %r15
movl $0x0, -0x1c(%rbp)
movl 0x18(%r15), %r14d
testb $0x1, %r14b
jne 0x38ed2
testb $0x8, %r14b
jne 0x38f45
leaq 0x82a90(%rbx), %rdi
leaq 0x34e47(%rip), %rsi     # 0x6dcb7
movsd %xmm0, -0x28(%rbp)
callq 0x8160
movsd -0x28(%rbp), %xmm0
orl $0x8, %r14d
movl %r14d, 0x18(%r15)
testq %rax, %rax
je 0x38f45
addq $0x6, %rax
leaq 0x3d30b(%rip), %rsi     # 0x761a6
leaq -0x1c(%rbp), %r14
movq %rax, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x8610
testl %eax, %eax
sete %al
movl (%r14), %ecx
testl %ecx, %ecx
setle %dl
orb %al, %dl
cmpb $0x1, %dl
jne 0x38f22
leaq 0x34df7(%rip), %rsi     # 0x6dcbe
xorl %edi, %edi
xorl %eax, %eax
callq 0x53ec4
jmp 0x38f40
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm0
jne 0x38ede
jnp 0x38f45
movsd 0x10(%r15), %xmm1
ucomisd %xmm2, %xmm1
jne 0x38eec
jnp 0x38f1a
ucomisd %xmm0, %xmm1
jbe 0x38f1a
movl 0x34(%r15), %edx
leal 0x1(%rdx), %ecx
leaq 0x34a11(%rip), %rsi     # 0x6d911
movl $0x2, %edi
xorl %eax, %eax
movsd %xmm0, -0x28(%rbp)
callq 0x53ec4
movsd -0x28(%rbp), %xmm0
incl 0x34(%r15)
movsd %xmm0, 0x10(%r15)
jmp 0x38f45
movl %ecx, 0x34(%r15)
orb $0x1, 0x18(%r15)
leaq 0x34dba(%rip), %rsi     # 0x6dcec
movl $0x2, %edi
movl %ecx, %edx
xorl %eax, %eax
callq 0x53ec4
movsd -0x28(%rbp), %xmm0
movl 0x34(%r15), %eax
movl %eax, -0x1c(%rbp)
testl %eax, %eax
jne 0x38fd5
testb $0x3, 0x18(%r15)
jne 0x38fd5
movsd %xmm0, -0x28(%rbp)
cmpq $0x0, (%rbx)
jne 0x38f84
movsd 0x8(%rbx), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x38f84
jp 0x38f84
callq 0x4febe
movq %rax, (%rbx)
movsd %xmm0, 0x8(%rbx)
movq (%rbx), %rdi
movsd 0x8(%rbx), %xmm0
leaq -0x1c(%rbp), %rsi
callq 0x4fc2d
xorpd %xmm1, %xmm1
movsd -0x28(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jne 0x38fa6
jnp 0x38fb6
movl -0x1c(%rbp), %edi
callq 0x4fbc6
movq %rax, (%rbx)
movsd %xmm0, 0x8(%rbx)
movl -0x1c(%rbp), %edx
movl %edx, 0x34(%r15)
orb $0x4, 0x18(%r15)
leaq 0x34d59(%rip), %rsi     # 0x6dd22
movl $0x2, %edi
xorl %eax, %eax
callq 0x53ec4
movl -0x1c(%rbp), %eax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop