// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/src/util.c
// Function: memtoll
long long memtoll(const char *p, int *err) {
    const char *u;
    char buf[128];
    long mul; /* unit multiplier */
    long long val;
    unsigned int digits;

    if (err) *err = 0;

    /* Search the first non digit character. */
    u = p;
    if (*u == '-') u++;
    while(*u && isdigit(*u)) u++;
    if (*u == '\0' || !strcasecmp(u,"b")) {
        mul = 1;
    } else if (!strcasecmp(u,"k")) {
        mul = 1000;
    } else if (!strcasecmp(u,"kb")) {
        mul = 1024;
    } else if (!strcasecmp(u,"m")) {
        mul = 1000*1000;
    } else if (!strcasecmp(u,"mb")) {
        mul = 1024*1024;
    } else if (!strcasecmp(u,"g")) {
        mul = 1000L*1000*1000;
    } else if (!strcasecmp(u,"gb")) {
        mul = 1024L*1024*1024;
    } else {
        if (err) *err = 1;
        return 0;
    }

    /* Copy the digits into a buffer, we'll use strtoll() to convert
     * the digit (without the unit) into a number. */
    digits = u-p;
    if (digits >= sizeof(buf)) {
        if (err) *err = 1;
        return 0;
    }
    memcpy(buf,p,digits);
    buf[digits] = '\0';

    char *endptr;
    errno = 0;
    val = strtoll(buf,&endptr,10);
    if ((val == 0 && errno == EINVAL) || *endptr != '\0') {
        if (err) *err = 1;
        return 0;
    }
    return val*mul;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, %rbx
movq %rdi, %r14
testq %rsi, %rsi
je 0x3fd16
movl $0x0, (%rbx)
xorl %eax, %eax
cmpb $0x2d, (%r14)
sete %al
leaq (%r14,%rax), %r15
movb (%r14,%rax), %bpl
movl $0x1, %r13d
testb %bpl, %bpl
je 0x3fe15
callq 0x26560
movq (%rax), %rax
movsbq %bpl, %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x3fd5a
movb 0x1(%r15), %bpl
incq %r15
testb %bpl, %bpl
jne 0x3fd3e
jmp 0x3fe15
leaq 0x91b2a(%rip), %rsi     # 0xd188b
movq %r15, %rdi
callq 0x262f0
testl %eax, %eax
je 0x3fe15
leaq 0x93edd(%rip), %rsi     # 0xd3c55
movq %r15, %rdi
callq 0x262f0
testl %eax, %eax
je 0x3fdef
leaq 0x84f4b(%rip), %rsi     # 0xc4cd6
movq %r15, %rdi
callq 0x262f0
testl %eax, %eax
je 0x3fdf7
leaq 0x8f4be(%rip), %rsi     # 0xcf25c
movq %r15, %rdi
callq 0x262f0
testl %eax, %eax
je 0x3fdff
leaq 0x8824c(%rip), %rsi     # 0xc7ffd
movq %r15, %rdi
callq 0x262f0
testl %eax, %eax
je 0x3fe07
leaq 0x8a9d8(%rip), %rsi     # 0xca79c
movq %r15, %rdi
callq 0x262f0
testl %eax, %eax
je 0x3fe0f
leaq 0x84ef1(%rip), %rsi     # 0xc4cc8
movq %r15, %rdi
callq 0x262f0
testl %eax, %eax
jne 0x3fe6f
movl $0x40000000, %r13d      # imm = 0x40000000
jmp 0x3fe15
movl $0x3e8, %r13d           # imm = 0x3E8
jmp 0x3fe15
movl $0x400, %r13d           # imm = 0x400
jmp 0x3fe15
movl $0xf4240, %r13d         # imm = 0xF4240
jmp 0x3fe15
movl $0x100000, %r13d        # imm = 0x100000
jmp 0x3fe15
movl $0x3b9aca00, %r13d      # imm = 0x3B9ACA00
subl %r14d, %r15d
cmpl $0x80, %r15d
jae 0x3fe6f
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x26c50
movb $0x0, 0x10(%rsp,%r15)
callq 0x26880
movq %rax, %r14
movl $0x0, (%rax)
leaq 0x8(%rsp), %rsi
movq %r12, %rdi
movl $0xa, %edx
callq 0x26af0
testq %rax, %rax
jne 0x3fe65
cmpl $0x16, (%r14)
je 0x3fe6f
movq 0x8(%rsp), %rcx
cmpb $0x0, (%rcx)
je 0x3fe8e
testq %rbx, %rbx
je 0x3fe7a
movl $0x1, (%rbx)
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
imulq %r13, %rax
jmp 0x3fe7c