#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';
  }
  if (c != '\0')
    errAbort("invalid unsigned integer: \"%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>
movsbl -0x19(%rbp),%eax
cmp    $0x0,%eax
je     11aa <sqlUnsignedLong+0x9a>
mov    -0x8(%rbp),%rsi
lea    0xe5b(%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     1162 <sqlUnsignedLong+0x52>
lea    0x1(%rsi),%rcx
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%rbx,%rbx,4),%rdx
movzbl %al,%eax
add    $0xffffffd0,%eax
lea    (%rax,%rdx,2),%rbx
movzbl (%rcx),%eax
lea    -0x30(%rax),%edx
add    $0x1,%rcx
cmp    $0xa,%dl
jb     1130 <sqlUnsignedLong+0x20>
test   %al,%al
je     115d <sqlUnsignedLong+0x4d>
lea    0xea8(%rip),%rdi
call   1030 <errAbort@plt>
mov    %rbx,%rax
pop    %rbx
ret
xor    %ebx,%ebx
test   %al,%al
jne    1151 <sqlUnsignedLong+0x41>
jmp    115d <sqlUnsignedLong+0x4d>

LLVM IR (-O0):
@.str = [31 x i8] c"invalid unsigned integer: \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* %5
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i8*, i8** %2
%34 = call i32 @errAbort(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %32, %28
%36 = load i64, i64* %3
ret i64 %36
}

LLVM IR (-O2):
@.str = [31 x i8] c"invalid unsigned integer: \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 %18
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, %1
%19 = phi i64 [ 0, %1 ], [ %14, %5 ]
%20 = phi i8 [ %2, %1 ], [ %15, %5 ]
%21 = icmp eq i8 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %18
%23 = tail call i32 @errAbort(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %24
24: ; preds = %22, %18
ret i64 %19
}