// File: /workspace/github_c_makefile_star2_O3/Carton32[P]quectel-CM/at_tok.c
// Function: at_tok_scanf
int at_tok_scanf(const char *in_line, const char *fmt, ...)
{
    int n = 0;
    int err;
    va_list ap;
    const char *p = fmt;
    void *d;
    void *dump;
    static char s_line[1024];
    char *line = s_line;

    if (!in_line)
        return 0;

    strncpy(s_line, in_line, sizeof(s_line));

    va_start(ap, fmt);

    err = at_tok_start(&line);
    if (err < 0) goto error;

    for (; *p; p++) {
        if (*p == ',' || *p == ' ')
            continue;

        if (*p != '%') {
            goto error;
        }
        p++;

        d = va_arg(ap, void *);
        if (!d)
            d = &dump;

        if (!at_tok_hasmore(&line))
            break;
        
        if (*line == '-' && *(line + 1) == ',') {
            line += 2;
            n++;
            if (*p == 'd')
                *(int *)d = -1;
            continue;
         }

        switch(*p) {
            case 'd':
                err = at_tok_nextint(&line, (int *)d);
                if (err < 0) goto error;
           break;
            case 'x':
                err = at_tok_nexthexint(&line, (int *)d);
                if (err < 0) goto error;
            break;
            case 'b':
                err = at_tok_nextbool(&line, (char *)d);
                if (err < 0) goto error;
            break;
            case 's':
                err = at_tok_nextstr(&line, (char **)d); //if strdup(line), here return free memory to caller
                if (err < 0) goto error;
            break;
            default:
                goto error;
            break;
        }

        n++;
    }

    va_end(ap);

error:
    //free(line);
    return n;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rdx, 0x40(%rsp)
movq %rcx, 0x48(%rsp)
movq %r8, 0x50(%rsp)
movq %r9, 0x58(%rsp)
testb %al, %al
je 0x1bb9c
movaps %xmm0, 0x60(%rsp)
movaps %xmm1, 0x70(%rsp)
movaps %xmm2, 0x80(%rsp)
movaps %xmm3, 0x90(%rsp)
movaps %xmm4, 0xa0(%rsp)
movaps %xmm5, 0xb0(%rsp)
movaps %xmm6, 0xc0(%rsp)
movaps %xmm7, 0xd0(%rsp)
xorl %ebx, %ebx
testq %rdi, %rdi
je 0x1bd3f
movq %rsi, %r14
movq %rdi, %rsi
leaq 0x1043c(%rip), %r15     # 0x2bff0
movl $0x400, %edx            # imm = 0x400
movq %r15, %rdi
callq 0x5080
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, 0x10(%rsp)
leaq 0x120(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
movq %r15, %rdi
movl $0x3a, %esi
callq 0x5190
testq %rax, %rax
je 0x1bd3f
incq %rax
leaq 0x8(%rsp), %r15
movq %rax, (%r15)
xorl %ebx, %ebx
leaq 0x28(%rsp), %rbp
leaq 0x4(%rsp), %r12
movzbl (%r14), %eax
cmpl $0x24, %eax
jle 0x1bc4a
cmpl $0x2c, %eax
je 0x1bd35
cmpl $0x25, %eax
jne 0x1bd3f
movl 0x10(%rsp), %ecx
cmpq $0x28, %rcx
ja 0x1bc58
movq %rcx, %rax
addq 0x20(%rsp), %rax
addl $0x8, %ecx
movl %ecx, 0x10(%rsp)
jmp 0x1bc66
cmpl $0x20, %eax
je 0x1bd35
jmp 0x1bd3d
movq 0x18(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x18(%rsp)
movq (%rax), %rax
movq %rbp, %r13
testq %rax, %rax
je 0x1bc74
movq %rax, %r13
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x1bd3f
incq %r14
movzbl (%rax), %ecx
cmpl $0x2d, %ecx
je 0x1bc96
testl %ecx, %ecx
jne 0x1bcbb
jmp 0x1bd3f
cmpb $0x2c, 0x1(%rax)
jne 0x1bcbb
addq $0x2, %rax
movq %rax, 0x8(%rsp)
incl %ebx
cmpb $0x64, (%r14)
jne 0x1bd35
movl $0xffffffff, (%r13)     # imm = 0xFFFFFFFF
jmp 0x1bd35
movzbl (%r14), %eax
cmpl $0x72, %eax
jg 0x1bcdd
cmpl $0x62, %eax
je 0x1bd02
cmpl $0x64, %eax
jne 0x1bd3f
movq %r15, %rdi
movq %r13, %rsi
movl $0xa, %edx
xorl %ecx, %ecx
jmp 0x1bcf7
cmpl $0x73, %eax
je 0x1bd27
cmpl $0x78, %eax
jne 0x1bd3f
movq %r15, %rdi
movq %r13, %rsi
movl $0x10, %edx
movl $0x1, %ecx
callq 0x1b9ad
testl %eax, %eax
jns 0x1bd33
jmp 0x1bd3f
movq %r15, %rdi
movq %r12, %rsi
movl $0xa, %edx
xorl %ecx, %ecx
callq 0x1b9ad
testl %eax, %eax
js 0x1bd3f
movl 0x4(%rsp), %eax
cmpl $0x2, %eax
jae 0x1bd3f
movb %al, (%r13)
jmp 0x1bd33
movq %r15, %rdi
callq 0x1ba7a
movq %rax, (%r13)
incl %ebx
incq %r14
jmp 0x1bc14
testl %eax, %eax
movl %ebx, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop