// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/src/util.c
// Function: string2ll
int string2ll(const char *s, size_t slen, long long *value) {
    const char *p = s;
    size_t plen = 0;
    int negative = 0;
    unsigned long long v;

    if (plen == slen)
        return 0;

    /* Special case: first and only digit is 0. */
    if (slen == 1 && p[0] == '0') {
        if (value != NULL) *value = 0;
        return 1;
    }

    if (p[0] == '-') {
        negative = 1;
        p++; plen++;

        /* Abort on only a negative sign. */
        if (plen == slen)
            return 0;
    }

    /* First digit should be 1-9, otherwise the string should just be 0. */
    if (p[0] >= '1' && p[0] <= '9') {
        v = p[0]-'0';
        p++; plen++;
    } else if (p[0] == '0' && slen == 1) {
        *value = 0;
        return 1;
    } else {
        return 0;
    }

    while (plen < slen && p[0] >= '0' && p[0] <= '9') {
        if (v > (ULLONG_MAX / 10)) /* Overflow. */
            return 0;
        v *= 10;

        if (v > (ULLONG_MAX - (p[0]-'0'))) /* Overflow. */
            return 0;
        v += p[0]-'0';

        p++; plen++;
    }

    /* Return if not all bytes were used. */
    if (plen < slen)
        return 0;

    if (negative) {
        if (v > ((unsigned long long)(-(LLONG_MIN+1))+1)) /* Overflow. */
            return 0;
        if (value != NULL) *value = -v;
    } else {
        if (v > LLONG_MAX) /* Overflow. */
            return 0;
        if (value != NULL) *value = v;
    }
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x18(%rbp), %rax
jne 0x479ad
movl $0x0, -0x4(%rbp)
jmp 0x47bd7
cmpq $0x1, -0x18(%rbp)
jne 0x479de
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x30, %eax
jne 0x479de
cmpq $0x0, -0x20(%rbp)
je 0x479d2
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x47bd7
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x47a21
movl $0x1, -0x34(%rbp)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x18(%rbp), %rax
jne 0x47a1f
movl $0x0, -0x4(%rbp)
jmp 0x47bd7
jmp 0x47a21
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x31, %eax
jl 0x47a63
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x39, %eax
jg 0x47a63
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
subl $0x30, %eax
cltq
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x47a99
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x30, %eax
jne 0x47a8d
cmpq $0x1, -0x18(%rbp)
jne 0x47a8d
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x47bd7
movl $0x0, -0x4(%rbp)
jmp 0x47bd7
jmp 0x47a9b
movq -0x30(%rbp), %rcx
xorl %eax, %eax
cmpq -0x18(%rbp), %rcx
movb %al, -0x41(%rbp)
jae 0x47acb
movq -0x28(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x30, %ecx
movb %al, -0x41(%rbp)
jl 0x47acb
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x39, %eax
setle %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0x47ad7
jmp 0x47b59
movabsq $0x1999999999999999, %rax # imm = 0x1999999999999999
cmpq %rax, -0x40(%rbp)
jbe 0x47af3
movl $0x0, -0x4(%rbp)
jmp 0x47bd7
imulq $0xa, -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x28(%rbp), %rcx
movsbl (%rcx), %ecx
subl $0x30, %ecx
movslq %ecx, %rdx
movq $-0x1, %rcx
subq %rdx, %rcx
cmpq %rcx, %rax
jbe 0x47b28
movl $0x0, -0x4(%rbp)
jmp 0x47bd7
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
subl $0x30, %eax
cltq
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x47a9b
movq -0x30(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x47b6c
movl $0x0, -0x4(%rbp)
jmp 0x47bd7
cmpl $0x0, -0x34(%rbp)
je 0x47ba3
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
cmpq %rax, -0x40(%rbp)
jbe 0x47b8b
movl $0x0, -0x4(%rbp)
jmp 0x47bd7
cmpq $0x0, -0x20(%rbp)
je 0x47ba1
xorl %eax, %eax
movl %eax, %ecx
subq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
jmp 0x47bd0
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
cmpq %rax, -0x40(%rbp)
jbe 0x47bbc
movl $0x0, -0x4(%rbp)
jmp 0x47bd7
cmpq $0x0, -0x20(%rbp)
je 0x47bce
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
jmp 0x47bd0
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax)