#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ errAbort(char *, char *);
unsigned long sqlUnsignedLong(char *s) {
  unsigned long res = 0;
  char *p = s;
  char c;
  while (((c = *(p++)) >= '0') && (c <= '9')) {
    res *= 10;
    res += c - '0';
  }
  --p;
  if ((c != '\0') || (p == s))
    errAbort("invalid unsigned long: \"%s\"", s);
  return res;
}


x86 assembly (clang, -O0):
<sqlUnsignedLong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    %al,-0x19(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x1a(%rbp)
jl     115e <sqlUnsignedLong+0x4e>
movsbl -0x19(%rbp),%eax
cmp    $0x39,%eax
setle  %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
test   $0x1,%al
jne    116e <sqlUnsignedLong+0x5e>
jmp    118d <sqlUnsignedLong+0x7d>
imul   $0xa,-0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
movsbl -0x19(%rbp),%eax
sub    $0x30,%eax
cltq
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    112c <sqlUnsignedLong+0x1c>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x0,%eax
jne    11b4 <sqlUnsignedLong+0xa4>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    11c4 <sqlUnsignedLong+0xb4>
mov    -0x8(%rbp),%rsi
lea    0xe41(%rip),%rdi
call   1030 <errAbort@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlUnsignedLong>:
push   %rbx
mov    %rdi,%rsi
mov    (%rdi),%al
lea    -0x30(%rax),%ecx
cmp    $0x9,%cl
ja     115a <sqlUnsignedLong+0x4a>
xor    %ecx,%ecx
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    (%rbx,%rbx,4),%rdx
movzbl %al,%eax
add    $0xffffffd0,%eax
lea    (%rax,%rdx,2),%rbx
movzbl 0x1(%rsi,%rcx,1),%eax
lea    -0x30(%rax),%edx
add    $0x1,%rcx
cmp    $0xa,%dl
jb     1130 <sqlUnsignedLong+0x20>
test   %rcx,%rcx
je     115c <sqlUnsignedLong+0x4c>
test   %al,%al
je     1168 <sqlUnsignedLong+0x58>
jmp    115c <sqlUnsignedLong+0x4c>
xor    %ebx,%ebx
lea    0xe9d(%rip),%rdi
call   1030 <errAbort@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [28 x i8] c"invalid unsigned long: \22%s\22\00"
define i64 @sqlUnsignedLong(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8
store i8* %0, i8** %2
store i64 0, i64* %3
%6 = load i8*, i8** %2
store i8* %6, i8** %4
br label %7
7: ; preds = %19, %1
%8 = load i8*, i8** %4
%9 = getelementptr inbounds i8, i8* %8, i32 1
store i8* %9, i8** %4
%10 = load i8, i8* %8
store i8 %10, i8* %5
%11 = sext i8 %10 to i32
%12 = icmp sge i32 %11, 48
br i1 %12, label %13, label %17
13: ; preds = %7
%14 = load i8, i8* %5
%15 = sext i8 %14 to i32
%16 = icmp sle i32 %15, 57
br label %17
17: ; preds = %13, %7
%18 = phi i1 [ false, %7 ], [ %16, %13 ]
br i1 %18, label %19, label %28
19: ; preds = %17
%20 = load i64, i64* %3
%21 = mul i64 %20, 10
store i64 %21, i64* %3
%22 = load i8, i8* %5
%23 = sext i8 %22 to i32
%24 = sub nsw i32 %23, 48
%25 = sext i32 %24 to i64
%26 = load i64, i64* %3
%27 = add i64 %26, %25
store i64 %27, i64* %3
br label %7
28: ; preds = %17
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i32 -1
store i8* %30, i8** %4
%31 = load i8, i8* %5
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %28
%35 = load i8*, i8** %4
%36 = load i8*, i8** %2
%37 = icmp eq i8* %35, %36
br i1 %37, label %38, label %41
38: ; preds = %34, %28
%39 = load i8*, i8** %2
%40 = call i32 @errAbort(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %38, %34
%42 = load i64, i64* %3
ret i64 %42
}

LLVM IR (-O2):
@.str = [28 x i8] c"invalid unsigned long: \22%s\22\00"
define i64 @sqlUnsignedLong(i8* %0) {
%2 = load i8, i8* %0
%3 = add i8 %2, -48
%4 = icmp ult i8 %3, 10
br i1 %4, label %5, label %22
5: ; preds = %1, %5
%6 = phi i8 [ %15, %5 ], [ %2, %1 ]
%7 = phi i64 [ %14, %5 ], [ 0, %1 ]
%8 = phi i8* [ %10, %5 ], [ %0, %1 ]
%9 = zext i8 %6 to i64
%10 = getelementptr inbounds i8, i8* %8, i64 1
%11 = mul i64 %7, 10
%12 = add nuw nsw i64 %9, 4294967248
%13 = and i64 %12, 4294967295
%14 = add i64 %13, %11
%15 = load i8, i8* %10
%16 = add i8 %15, -48
%17 = icmp ult i8 %16, 10
br i1 %17, label %5, label %18
18: ; preds = %5
%19 = icmp ne i8 %15, 0
%20 = icmp eq i8* %10, %0
%21 = or i1 %20, %19
br i1 %21, label %22, label %25
22: ; preds = %1, %18
%23 = phi i64 [ %14, %18 ], [ 0, %1 ]
%24 = tail call i32 @errAbort(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %25
25: ; preds = %18, %22
%26 = phi i64 [ %14, %18 ], [ %23, %22 ]
ret i64 %26
}