// File: /workspace/github_c_makefile_star2_O2/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 %r15
pushq %r14
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 0x1a885
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)
leaq 0x10764(%rip), %rax     # 0x2aff0
movq %rax, 0x8(%rsp)
xorl %ebx, %ebx
testq %rdi, %rdi
je 0x1a9d3
movq %rsi, %r14
movq %rdi, %rsi
leaq 0x10747(%rip), %rdi     # 0x2aff0
movl $0x400, %edx            # imm = 0x400
callq 0x5080
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, 0x10(%rsp)
leaq 0x110(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x8(%rsp), %rdi
callq 0x1a678
testl %eax, %eax
js 0x1a9d3
xorl %ebx, %ebx
leaq 0x28(%rsp), %r12
leaq 0x8(%rsp), %r15
movzbl (%r14), %eax
cmpl $0x20, %eax
je 0x1a9c9
cmpl $0x25, %eax
je 0x1a917
cmpl $0x2c, %eax
je 0x1a9c9
jmp 0x1a9d1
movl 0x10(%rsp), %ecx
cmpq $0x28, %rcx
ja 0x1a932
movq %rcx, %rax
addq 0x20(%rsp), %rax
addl $0x8, %ecx
movl %ecx, 0x10(%rsp)
jmp 0x1a940
movq 0x18(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x18(%rsp)
movq (%rax), %rax
movq %r12, %rsi
testq %rax, %rax
je 0x1a94e
movq %rax, %rsi
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x1a9d3
incq %r14
movzbl (%rax), %ecx
cmpl $0x2d, %ecx
je 0x1a969
testl %ecx, %ecx
jne 0x1a985
jmp 0x1a9d3
cmpb $0x2c, 0x1(%rax)
jne 0x1a985
addq $0x2, %rax
movq %rax, 0x8(%rsp)
incl %ebx
cmpb $0x64, (%r14)
jne 0x1a9c9
orl $-0x1, (%rsi)
jmp 0x1a9c9
movzbl (%r14), %eax
cmpl $0x62, %eax
je 0x1a9b1
cmpl $0x78, %eax
je 0x1a9a7
cmpl $0x73, %eax
je 0x1a9bb
cmpl $0x64, %eax
jne 0x1a9d3
movq %r15, %rdi
callq 0x1a6ac
jmp 0x1a9c3
movq %r15, %rdi
callq 0x1a71a
jmp 0x1a9c3
movq %r15, %rdi
callq 0x1a722
jmp 0x1a9c3
movq %r15, %rdi
callq 0x1a755
testl %eax, %eax
js 0x1a9d3
incl %ebx
incq %r14
jmp 0x1a8f7
testl %eax, %eax
movl %ebx, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq