// File: /workspace/github_cpp_makefile_star2_O3/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
movapd %xmm0, %xmm2
movq %rdi, %rbx
movq 0x82ba0(%rdi), %r15
movl $0x0, -0x1c(%rbp)
movl 0x18(%r15), %r14d
testb $0x1, %r14b
jne 0x38886
testb $0x8, %r14b
jne 0x388f9
leaq 0x82a90(%rbx), %rdi
leaq 0x35493(%rip), %rsi     # 0x6dcb7
movsd %xmm2, -0x28(%rbp)
callq 0x8160
movsd -0x28(%rbp), %xmm2
orl $0x8, %r14d
movl %r14d, 0x18(%r15)
testq %rax, %rax
je 0x388f9
addq $0x6, %rax
leaq 0x3d8dc(%rip), %rsi     # 0x7612b
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 0x388d6
leaq 0x35443(%rip), %rsi     # 0x6dcbe
xorl %edi, %edi
xorl %eax, %eax
callq 0x5342c
jmp 0x388f4
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm2
jne 0x38892
jnp 0x388f9
movsd 0x10(%r15), %xmm1
ucomisd %xmm0, %xmm1
jne 0x388a0
jnp 0x388ce
ucomisd %xmm2, %xmm1
jbe 0x388ce
movl 0x34(%r15), %edx
leal 0x1(%rdx), %ecx
leaq 0x3505d(%rip), %rsi     # 0x6d911
movl $0x2, %edi
xorl %eax, %eax
movsd %xmm2, -0x28(%rbp)
callq 0x5342c
movsd -0x28(%rbp), %xmm2
incl 0x34(%r15)
movsd %xmm2, 0x10(%r15)
jmp 0x388f9
movl %ecx, 0x34(%r15)
orb $0x1, 0x18(%r15)
leaq 0x35406(%rip), %rsi     # 0x6dcec
movl $0x2, %edi
movl %ecx, %edx
xorl %eax, %eax
callq 0x5342c
movsd -0x28(%rbp), %xmm2
movl 0x34(%r15), %eax
movl %eax, -0x1c(%rbp)
testl %eax, %eax
jne 0x3898f
xorl %eax, %eax
testb $0x3, 0x18(%r15)
jne 0x3898f
movq (%rbx), %rdi
movsd 0x8(%rbx), %xmm0
testq %rdi, %rdi
movsd %xmm2, -0x28(%rbp)
jne 0x38943
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x38941
jp 0x38941
callq 0x4f542
movq %rax, %rdi
movq %rax, (%rbx)
movsd %xmm0, 0x8(%rbx)
jmp 0x38943
xorl %edi, %edi
leaq -0x1c(%rbp), %rsi
callq 0x4f2b1
xorpd %xmm1, %xmm1
movsd -0x28(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jne 0x3895d
jnp 0x3896d
movl -0x1c(%rbp), %edi
callq 0x4f24a
movq %rax, (%rbx)
movsd %xmm0, 0x8(%rbx)
movl -0x1c(%rbp), %edx
movl %edx, 0x34(%r15)
orb $0x4, 0x18(%r15)
leaq 0x353a2(%rip), %rsi     # 0x6dd22
movl $0x2, %edi
xorl %eax, %eax
callq 0x5342c
movl -0x1c(%rbp), %eax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop