// File: /workspace/github_c_makefile_star2_O2/JimKent[P]linearSat/lib/linefile.c
// Function: lineFileCheckAllIntsNoAbort
int lineFileCheckAllIntsNoAbort(char *s, void *val, 
    boolean isSigned, int byteCount, char *typeString, boolean noNeg, 
    char *errMsg, int errMsgSize)
/* Convert string to (signed) integer of the size specified.  
 * Unlike atol assumes all of string is number, no trailing trash allowed.
 * Returns 0 if conversion possible, and value is returned in 'val'
 * Otherwise 1 for empty string or trailing chars, and 2 for numeric overflow,
 * and 3 for (-) sign in unsigned number.
 * Error messages if any are written into the provided buffer.
 * Pass NULL val if you only want validation.
 * Use noNeg if negative values are not allowed despite the type being signed,
 * returns 4. */
{
unsigned long long res = 0, oldRes = 0;
boolean isMinus = FALSE;

if ((byteCount != 1) 
 && (byteCount != 2)
 && (byteCount != 4)
 && (byteCount != 8))
    errAbort("Unexpected error: Invalid byte count for integer size in lineFileCheckAllIntsNoAbort, expected 1 2 4 or 8, got %d.", byteCount);

unsigned long long limit = 0xFFFFFFFFFFFFFFFFULL >> (8*(8-byteCount));

if (isSigned) 
    limit >>= 1;

char *p, *p0 = s;

if (*p0 == '-')
    {
    if (isSigned)
	{
	if (noNeg)
	    {
	    safef(errMsg, errMsgSize, "Negative value not allowed");
	    return 4; 
	    }
	p0++;
	++limit;
	isMinus = TRUE;
	}
    else
	{
	safef(errMsg, errMsgSize, "Unsigned %s may not begin with minus sign (-)", typeString);
	return 3; 
	}
    }
p = p0;
while ((*p >= '0') && (*p <= '9'))
    {
    res *= 10;
    if (res < oldRes)
	{
	safef(errMsg, errMsgSize, "%s%s overflowed", isSigned ? "signed ":"", typeString);
	return 2; 
	}
    oldRes = res;
    res += *p - '0';
    if (res < oldRes)
	{
	safef(errMsg, errMsgSize, "%s%s overflowed", isSigned ? "signed ":"", typeString);
	return 2; 
	}
    if (res > limit)
	{
	safef(errMsg, errMsgSize, "%s%s overflowed, limit=%s%llu", isSigned ? "signed ":"", typeString, isMinus ? "-" : "", limit);
	return 2; 
	}
    oldRes = res;
    p++;
    }
/* test for invalid character, empty, or just a minus */
if (*p != '\0')
    {
    safef(errMsg, errMsgSize, "Trailing characters parsing %s%s", isSigned ? "signed ":"", typeString);
    return 1;
    }
if (p == p0)
    {
    safef(errMsg, errMsgSize, "Empty string parsing %s%s", isSigned ? "signed ":"", typeString);
    return 1;
    }

if (!val)
    return 0;  // only validation required

switch (byteCount)
    {
    case 1:
	if (isSigned)
	    {
	    if (isMinus)
		*(char *)val = -res;
	    else
		*(char *)val = res;
	    }
	else
	    *(unsigned char *)val = res;
	break;
    case 2:
	if (isSigned)
	    {
	    if (isMinus)
		*(short *)val = -res;
	    else
		*(short *)val = res;
	    }
	else
	    *(unsigned short *)val = res;
	break;
    case 4:
	if (isSigned)
	    {
	    if (isMinus)
		*(int *)val = -res;
	    else
		*(int *)val = res;
	    }
	else
	    *(unsigned *)val = res;
	break;
    case 8:
	if (isSigned)
	    {
	    if (isMinus)
		*(long long *)val = -res;
	    else
		*(long long *) val =res;
	    }
	else
	    *(unsigned long long *)val = res;
	break;
    }


return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r9d, %r13d
movq %r8, %rbx
movl %ecx, %r15d
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r12
cmpl $0x8, %ecx
ja 0xc8cb
movl $0x116, %eax            # imm = 0x116
btl %r15d, %eax
jae 0xc8cb
leal (,%r15,8), %ecx
xorl %edx, %edx
testl %ebp, %ebp
sete %dl
shlq $0x3f, %rdx
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
orq %rdx, %rax
negb %cl
shrq %cl, %rax
movl 0x48(%rsp), %esi
movq 0x40(%rsp), %rdi
movb (%r12), %dl
cmpb $0x2d, %dl
jne 0xc8fc
testl %ebp, %ebp
je 0xc8de
testl %r13d, %r13d
je 0xc8f6
leaq 0xb835(%rip), %rdx      # 0x180f2
xorl %eax, %eax
callq 0x939d
pushq $0x4
jmp 0xc9bc
leaq 0xb7ad(%rip), %rdi      # 0x1807f
movl %r15d, %esi
xorl %eax, %eax
callq 0xa61f
jmp 0xc876
leaq 0xb828(%rip), %rdx      # 0x1810d
movq %rbx, %rcx
xorl %eax, %eax
callq 0x939d
pushq $0x3
jmp 0xc9bc
incq %r12
incq %rax
xorl %r8d, %r8d
xorl %ecx, %ecx
movb (%r12,%r8), %r9b
leal -0x30(%r9), %r10d
cmpb $0x9, %r10b
ja 0xc955
imulq $0xa, %rcx, %r9
cmpq %rcx, %r9
jb 0xc92e
movzbl %r10b, %ecx
addq %rcx, %r9
jb 0xc92e
cmpq %rax, %r9
ja 0xc983
incq %r8
movq %r9, %rcx
jmp 0xc901
testl %ebp, %ebp
leaq 0xb39b(%rip), %rax      # 0x17cd2
leaq 0xb80d(%rip), %rcx      # 0x1814b
cmoveq %rax, %rcx
leaq 0xb7f2(%rip), %rdx      # 0x1813b
movq %rbx, %r8
xorl %eax, %eax
callq 0x939d
jmp 0xc9ba
testb %r9b, %r9b
je 0xc9cc
testl %ebp, %ebp
leaq 0xb36f(%rip), %rax      # 0x17cd2
leaq 0xb7e1(%rip), %rcx      # 0x1814b
cmoveq %rax, %rcx
leaq 0xb7fc(%rip), %rdx      # 0x18171
movq %rbx, %r8
xorl %eax, %eax
callq 0x939d
pushq $0x1
jmp 0xc9bc
testl %ebp, %ebp
leaq 0xb346(%rip), %r8       # 0x17cd2
leaq 0xb7b8(%rip), %rcx      # 0x1814b
cmoveq %r8, %rcx
cmpb $0x2d, %dl
leaq 0xdbb2(%rip), %r9       # 0x1a553
cmovneq %r8, %r9
movq %rax, (%rsp)
leaq 0xb7a3(%rip), %rdx      # 0x18153
movq %rbx, %r8
xorl %eax, %eax
callq 0x939d
pushq $0x2
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r8, %r8
je 0xca01
xorl %eax, %eax
testq %r14, %r14
je 0xc9bd
decl %r15d
cmpl $0x7, %r15d
ja 0xc9bd
leaq 0xb2bc(%rip), %rsi      # 0x17ca4
movslq (%rsi,%r15,4), %rdi
addq %rsi, %rdi
jmpq *%rdi
testl %ebp, %ebp
je 0xc9fc
cmpb $0x2d, %dl
jne 0xc9fc
negb %cl
movb %cl, (%r14)
jmp 0xc9bd
testl %ebp, %ebp
leaq 0xb2c8(%rip), %rax      # 0x17cd2
leaq 0xb73a(%rip), %rcx      # 0x1814b
cmoveq %rax, %rcx
leaq 0xb776(%rip), %rdx      # 0x18192
jmp 0xc975
testl %ebp, %ebp
je 0xca2c
cmpb $0x2d, %dl
jne 0xca2c
negl %ecx
movl %ecx, (%r14)
jmp 0xc9bd
testl %ebp, %ebp
je 0xca3c
cmpb $0x2d, %dl
jne 0xca3c
negl %ecx
movw %cx, (%r14)
jmp 0xc9bd
testl %ebp, %ebp
je 0xca51
cmpb $0x2d, %dl
jne 0xca51
negq %rcx
movq %rcx, (%r14)
jmp 0xc9bd