// File: /workspace/github_c_makefile_star2_O1/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 0x1bef4
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 0x100f5(%rip), %rax     # 0x2bff0
movq %rax, (%rsp)
xorl %ebx, %ebx
testq %rdi, %rdi
je 0x1c0a6
movq %rsi, %r14
movq %rdi, %rsi
leaq 0x100d9(%rip), %rdi     # 0x2bff0
movl $0x400, %edx            # imm = 0x400
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 (%rsp), %rdi
testq %rdi, %rdi
je 0x1c0a6
movl $0x3a, %esi
callq 0x5190
movq %rax, (%rsp)
testq %rax, %rax
je 0x1c0a6
incq %rax
movq %rsp, %r15
movq %rax, (%r15)
xorl %ebx, %ebx
leaq 0x28(%rsp), %rbp
leaq 0xc(%rsp), %r12
movzbl (%r14), %eax
cmpl $0x24, %eax
jle 0x1bfb6
cmpl $0x2c, %eax
je 0x1c09c
cmpl $0x25, %eax
jne 0x1c0a6
movl 0x10(%rsp), %ecx
cmpq $0x28, %rcx
ja 0x1bfc4
movq %rcx, %rax
addq 0x20(%rsp), %rax
addl $0x8, %ecx
movl %ecx, 0x10(%rsp)
jmp 0x1bfd2
cmpl $0x20, %eax
je 0x1c09c
jmp 0x1c0a4
movq 0x18(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x18(%rsp)
movq (%rax), %rax
movq %rbp, %r13
testq %rax, %rax
je 0x1bfe0
movq %rax, %r13
movq (%rsp), %rax
testq %rax, %rax
je 0x1c0a6
cmpb $0x0, (%rax)
je 0x1c0a6
incq %r14
cmpb $0x2d, (%rax)
jne 0x1c022
cmpb $0x2c, 0x1(%rax)
jne 0x1c022
addq $0x2, %rax
movq %rax, (%rsp)
incl %ebx
cmpb $0x64, (%r14)
jne 0x1c09c
movl $0xffffffff, (%r13)     # imm = 0xFFFFFFFF
jmp 0x1c09c
movzbl (%r14), %eax
cmpl $0x72, %eax
jg 0x1c044
cmpl $0x62, %eax
je 0x1c069
cmpl $0x64, %eax
jne 0x1c0a6
movq %r15, %rdi
movq %r13, %rsi
movl $0xa, %edx
xorl %ecx, %ecx
jmp 0x1c05e
cmpl $0x73, %eax
je 0x1c08e
cmpl $0x78, %eax
jne 0x1c0a6
movq %r15, %rdi
movq %r13, %rsi
movl $0x10, %edx
movl $0x1, %ecx
callq 0x1bcfd
testl %eax, %eax
jns 0x1c09a
jmp 0x1c0a6
movq %r15, %rdi
movq %r12, %rsi
movl $0xa, %edx
xorl %ecx, %ecx
callq 0x1bcfd
testl %eax, %eax
js 0x1c0a6
movl 0xc(%rsp), %eax
cmpl $0x1, %eax
ja 0x1c0a6
movb %al, (%r13)
jmp 0x1c09a
movq %r15, %rdi
callq 0x1bdca
movq %rax, (%r13)
incl %ebx
incq %r14
jmp 0x1bf80
testl %eax, %eax
movl %ebx, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop