// File: /workspace/github_cpp_makefile_star2_O2/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
andl $0x0, -0x1c(%rbp)
movapd %xmm0, %xmm2
movl 0x18(%r15), %r14d
testb $0x1, %r14b
jne 0x3274a
testb $0x8, %r14b
jne 0x327b9
leaq 0x82a90(%rbx), %rdi
leaq 0x315cf(%rip), %rsi     # 0x63cb7
movsd %xmm2, -0x28(%rbp)
callq 0x8170
movsd -0x28(%rbp), %xmm2
orl $0x8, %r14d
movl %r14d, 0x18(%r15)
testq %rax, %rax
je 0x327b9
addq $0x6, %rax
leaq 0x39a58(%rip), %rsi     # 0x6c16b
leaq -0x1c(%rbp), %r14
movq %rax, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x8600
testl %eax, %eax
sete %al
movl (%r14), %ecx
testl %ecx, %ecx
setle %dl
orb %al, %dl
cmpb $0x1, %dl
jne 0x32798
leaq 0x3157f(%rip), %rsi     # 0x63cbe
xorl %edi, %edi
xorl %eax, %eax
callq 0x4acf2
jmp 0x327b4
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm2
jne 0x32756
jnp 0x327b9
movsd 0x10(%r15), %xmm1
ucomisd %xmm0, %xmm1
jne 0x32764
jnp 0x32790
ucomisd %xmm2, %xmm1
jbe 0x32790
movl 0x34(%r15), %edx
leal 0x1(%rdx), %ecx
leaq 0x31199(%rip), %rsi     # 0x63911
pushq $0x2
popq %rdi
xorl %eax, %eax
movsd %xmm2, -0x28(%rbp)
callq 0x4acf2
movsd -0x28(%rbp), %xmm2
incl 0x34(%r15)
movsd %xmm2, 0x10(%r15)
jmp 0x327b9
movl %ecx, 0x34(%r15)
orb $0x1, 0x18(%r15)
leaq 0x31544(%rip), %rsi     # 0x63cec
pushq $0x2
popq %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x4acf2
movsd -0x28(%rbp), %xmm2
movl 0x34(%r15), %eax
movl %eax, -0x1c(%rbp)
testl %eax, %eax
jne 0x3284d
xorl %eax, %eax
testb $0x3, 0x18(%r15)
jne 0x3284d
movq (%rbx), %rdi
movsd 0x8(%rbx), %xmm0
testq %rdi, %rdi
movsd %xmm2, -0x28(%rbp)
jne 0x32803
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x32801
jp 0x32801
callq 0x47349
movq %rax, %rdi
movq %rax, (%rbx)
movsd %xmm0, 0x8(%rbx)
jmp 0x32803
xorl %edi, %edi
leaq -0x1c(%rbp), %rsi
callq 0x470f1
xorpd %xmm1, %xmm1
movsd -0x28(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jne 0x3281d
jnp 0x3282d
movl -0x1c(%rbp), %edi
callq 0x4708a
movq %rax, (%rbx)
movsd %xmm0, 0x8(%rbx)
movl -0x1c(%rbp), %edx
movl %edx, 0x34(%r15)
orb $0x4, 0x18(%r15)
leaq 0x314e2(%rip), %rsi     # 0x63d22
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0x4acf2
movl -0x1c(%rbp), %eax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq