// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
testb %al, %al
je 0x288a1
movaps %xmm0, -0xe0(%rbp)
movaps %xmm1, -0xd0(%rbp)
movaps %xmm2, -0xc0(%rbp)
movaps %xmm3, -0xb0(%rbp)
movaps %xmm4, -0xa0(%rbp)
movaps %xmm5, -0x90(%rbp)
movaps %xmm6, -0x80(%rbp)
movaps %xmm7, -0x70(%rbp)
movq %r9, -0xe8(%rbp)
movq %r8, -0xf0(%rbp)
movq %rcx, -0xf8(%rbp)
movq %rdx, -0x100(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
leaq 0x108e5(%rip), %rax     # 0x391c0
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x288f2
movl $0x0, -0x4(%rbp)
jmp 0x28b19
movq -0x10(%rbp), %rsi
leaq 0x108c3(%rip), %rdi     # 0x391c0
movl $0x400, %edx            # imm = 0x400
callq 0x5080
leaq -0x40(%rbp), %rax
leaq -0x110(%rbp), %rcx
movq %rcx, 0x10(%rax)
leaq 0x10(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl $0x30, 0x4(%rax)
movl $0x10, (%rax)
leaq -0x60(%rbp), %rdi
callq 0x284e0
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jge 0x28942
jmp 0x28b13
jmp 0x28944
movq -0x48(%rbp), %rax
cmpb $0x0, (%rax)
je 0x28b0f
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2c, %eax
je 0x28969
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0x2896e
jmp 0x28afe
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x25, %eax
je 0x2897f
jmp 0x28b13
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rax
movq %rax, -0x120(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x114(%rbp)
cmpl $0x28, %eax
ja 0x289c6
movq -0x120(%rbp), %rcx
movl -0x114(%rbp), %edx
movslq %edx, %rax
addq 0x10(%rcx), %rax
addl $0x8, %edx
movl %edx, (%rcx)
movq %rax, -0x128(%rbp)
jmp 0x289e3
movq -0x120(%rbp), %rcx
movq 0x8(%rcx), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, 0x8(%rcx)
movq %rax, -0x128(%rbp)
movq -0x128(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x28a00
leaq -0x58(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x287b0
cmpl $0x0, %eax
jne 0x28a13
jmp 0x28b0f
movq -0x60(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x28a5c
movq -0x60(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2c, %eax
jne 0x28a5c
movq -0x60(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x60(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x64, %eax
jne 0x28a57
movq -0x50(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
jmp 0x28afe
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
addl $-0x62, %eax
movl %eax, %ecx
movq %rcx, -0x130(%rbp)
subl $0x16, %eax
ja 0x28af3
movq -0x130(%rbp), %rax
leaq 0x7f5e(%rip), %rcx      # 0x309e0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x50(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x28550
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jge 0x28aa3
jmp 0x28b13
jmp 0x28af5
movq -0x50(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x28630
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jge 0x28abd
jmp 0x28b13
jmp 0x28af5
movq -0x50(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x28660
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jge 0x28ad7
jmp 0x28b13
jmp 0x28af5
movq -0x50(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x286d0
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jge 0x28af1
jmp 0x28b13
jmp 0x28af5
jmp 0x28b13
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x28944
leaq -0x40(%rbp), %rax
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nopw %cs:(%rax,%rax)