// File: /workspace/github_cpp_makefile_star2_O2/DoubleString[P]RtConverter/src/Rtklib/rtkcmn.cpp
// Function: bamboo::searchpcv(int, char const*, bamboo::gtime_t, bamboo::pcvs_t const*)
extern pcv_t *searchpcv(int sat, const char *type, gtime_t time,
                        const pcvs_t *pcvs)
{
    pcv_t *pcv;
    char buff[MAXANT],*types[2],*p;
    int i,j,n=0;
    
    trace(3,"searchpcv: sat=%2d type=%s\n",sat,type);
    
    if (sat) { /* search satellite antenna */
        for (i=0;i<pcvs->n;i++) {
            pcv=pcvs->pcv+i;
            if (pcv->sat!=sat) continue;
            if (pcv->ts.time!=0&&timediff(pcv->ts,time)>0.0) continue;
            if (pcv->te.time!=0&&timediff(pcv->te,time)<0.0) continue;
            return pcv;
        }
    }
    else {
        strcpy(buff,type);
        for (p=strtok(buff," ");p&&n<2;p=strtok(NULL," ")) types[n++]=p;
        if (n<=0) return NULL;
        
        /* search receiver antenna with radome at first */
        for (i=0;i<pcvs->n;i++) {
            pcv=pcvs->pcv+i;
            for (j=0;j<n;j++) if (!strstr(pcv->type,types[j])) break;
            if (j>=n) return pcv;
        }
        /* search receiver antenna without radome */
        for (i=0;i<pcvs->n;i++) {
            pcv=pcvs->pcv+i;
            if (strstr(pcv->type,types[0])!=pcv->type) continue;
            
            trace(2,"pcv without radome is used type=%s\n",type);
            return pcv;
        }
    }
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movsd %xmm0, -0x38(%rbp)
movq %rdx, -0x48(%rbp)
testl %edi, %edi
movq %rcx, -0x30(%rbp)
je 0x49358
movl %edi, %r12d
movl (%rcx), %eax
xorl %edx, %edx
testl %eax, %eax
cmovlel %edx, %eax
imulq $0x2b8, %rax, %r14      # imm = 0x2B8
xorl %r13d, %r13d
xorl %ebx, %ebx
cmpq %r13, %r14
je 0x49469
movq 0x8(%rcx), %r15
cmpl %r12d, (%r15,%r13)
jne 0x49349
movq 0x88(%r15,%r13), %rdi
testq %rdi, %rdi
je 0x49308
movsd 0x90(%r15,%r13), %xmm0
movsd %xmm0, -0x40(%rbp)
movq -0x48(%rbp), %rsi
callq 0x8340
movq -0x30(%rbp), %rcx
addsd -0x40(%rbp), %xmm0
ucomisd -0x38(%rbp), %xmm0
ja 0x49349
movq 0x98(%r15,%r13), %rdi
testq %rdi, %rdi
je 0x49402
movsd 0xa0(%r15,%r13), %xmm0
movsd %xmm0, -0x40(%rbp)
movq -0x48(%rbp), %rsi
callq 0x8340
movq -0x30(%rbp), %rcx
addsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x4940e
incq %rbx
addq $0x2b8, %r13            # imm = 0x2B8
jmp 0x492c0
leaq -0xa0(%rbp), %r15
movq %r15, %rdi
callq 0x85c0
leaq 0x22177(%rip), %r14     # 0x6b4e5
movq %r15, %rdi
movq %r14, %rsi
callq 0x89a0
xorl %r12d, %r12d
testq %rax, %rax
je 0x4939b
cmpq $0x1, %r12
ja 0x4939b
movq %rax, -0x60(%rbp,%r12,8)
incq %r12
xorl %edi, %edi
movq %r14, %rsi
callq 0x89a0
jmp 0x4937c
xorl %r15d, %r15d
testq %r12, %r12
je 0x4946c
movq -0x30(%rbp), %rax
movl (%rax), %ebx
testl %ebx, %ebx
cmovlel %r15d, %ebx
xorl %r14d, %r14d
cmpq %rbx, %r14
je 0x49413
movq 0x8(%rax), %rax
imulq $0x2b8, %r14, %rcx      # imm = 0x2B8
leaq (%rax,%rcx), %rdx
movq %rdx, -0x38(%rbp)
leaq (%rax,%rcx), %r15
addq $0x4, %r15
xorl %r13d, %r13d
cmpq %r13, %r12
je 0x493fc
movq -0x60(%rbp,%r13,8), %rsi
movq %r15, %rdi
callq 0x8170
incq %r13
testq %rax, %rax
jne 0x493d9
incq %r14
movq -0x30(%rbp), %rax
jmp 0x493b6
movq -0x38(%rbp), %r15
jmp 0x4946c
imulq $0x2b8, %rbx, %rax      # imm = 0x2B8
addq %rax, %r15
jmp 0x4946c
addq %r13, %r15
jmp 0x4946c
movq -0x60(%rbp), %r15
imulq $0x2b8, %rbx, %rbx      # imm = 0x2B8
movq $-0x2b8, %rcx           # imm = 0xFD48
leaq 0x2b8(%rcx), %r14
cmpq %r14, %rbx
je 0x49469
movq -0x30(%rbp), %rax
movq 0x8(%rax), %r13
leaq (%rcx,%r13), %r12
addq $0x2bc, %r12            # imm = 0x2BC
movq %r15, %rdi
callq 0x8290
movq %r12, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x8300
movq %r14, %rcx
testl %eax, %eax
jne 0x49425
addq %r14, %r13
movq %r13, %r15
jmp 0x4946c
xorl %r15d, %r15d
movq %r15, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq