// File: /workspace/github_c_makefile_star2_O2/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x90, %rsp
movq %rsi, %rbx
movq %rdi, %r14
testq %rsi, %rsi
je 0x39562
andl $0x0, (%rbx)
xorl %r12d, %r12d
cmpb $0x2d, (%r14)
sete %r12b
pushq $0x1
popq %r13
movsbq (%r14,%r12), %r15
testq %r15, %r15
je 0x39653
callq 0x26560
movq (%rax), %rax
testb $0x8, 0x1(%rax,%r15,2)
je 0x39594
incq %r12
jmp 0x39571
leaq (%r14,%r12), %r15
leaq 0x88dac(%rip), %rsi     # 0xc234b
movq %r15, %rdi
callq 0x262f0
testl %eax, %eax
je 0x39653
leaq 0x8b177(%rip), %rsi     # 0xc472d
movq %r15, %rdi
callq 0x262f0
testl %eax, %eax
je 0x3962d
leaq 0x7cac1(%rip), %rsi     # 0xb608a
movq %r15, %rdi
callq 0x262f0
testl %eax, %eax
je 0x39635
leaq 0x86848(%rip), %rsi     # 0xbfe24
movq %r15, %rdi
callq 0x262f0
testl %eax, %eax
je 0x3963d
leaq 0x7f9f6(%rip), %rsi     # 0xb8fe5
movq %r15, %rdi
callq 0x262f0
testl %eax, %eax
je 0x39645
leaq 0x81fca(%rip), %rsi     # 0xbb5cc
movq %r15, %rdi
callq 0x262f0
testl %eax, %eax
je 0x3964d
leaq 0x7ca67(%rip), %rsi     # 0xb607c
movq %r15, %rdi
callq 0x262f0
testl %eax, %eax
jne 0x396a8
movl $0x40000000, %r13d      # imm = 0x40000000
jmp 0x39653
movl $0x3e8, %r13d           # imm = 0x3E8
jmp 0x39653
movl $0x400, %r13d           # imm = 0x400
jmp 0x39653
movl $0xf4240, %r13d         # imm = 0xF4240
jmp 0x39653
movl $0x100000, %r13d        # imm = 0x100000
jmp 0x39653
movl $0x3b9aca00, %r13d      # imm = 0x3B9ACA00
movl %r12d, %r15d
cmpq $0x80, %r15
jae 0x396a8
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
andl $0x0, (%rax)
leaq 0x8(%rsp), %rsi
pushq $0xa
popq %rdx
movq %r12, %rdi
callq 0x26af0
testq %rax, %rax
jne 0x3969e
cmpl $0x16, (%r14)
je 0x396a8
movq 0x8(%rsp), %rcx
cmpb $0x0, (%rcx)
je 0x396c6
testq %rbx, %rbx
je 0x396b3
movl $0x1, (%rbx)
xorl %eax, %eax
addq $0x90, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
imulq %r13, %rax
jmp 0x396b5