#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 */
typedef int uint64_t;
struct timeval {
  char *tv_sec;
  int /*<<< orphan*/ tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *,
                           int /*<<< orphan*/, char *, int, int, char const *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int json_parse_uint64(const char **s, size_t *n, uint64_t *v) {
  if (**s < '0' || **s > '9') {
    do {
      struct timeval _tv;
      gettimeofday(&_tv, NULL);
      fprintf(stderr,
              "%lu.%06lu %s:%d: "
              "Warning"
              ": "
              "Expected digit at start of string parsing\n"
              "Current position: %.*s\n"
              "\n",
              _tv.tv_sec, _tv.tv_usec,
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/pombredanne/spiz/refs/heads/master/"
              "src/server/json.c",
              146, (int)*n, *s);
    } while (0);
    return (-1);
  }
  *v = 0;
  while (*n) {
    if (**s < '0' || **s > '9') {
      return (0);
    }
    *v *= 10;
    *v += **s - '0';
    (*n)--;
    (*s)++;
  }
  return (-1);
}


x86 assembly (clang, -O0):
<json_parse_uint64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     115a <json_parse_uint64+0x3a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jle    11bb <json_parse_uint64+0x9b>
jmp    115f <json_parse_uint64+0x3f>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %eax,%r10d
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
lea    0xe6c(%rip),%rsi
lea    0xec2(%rip),%r8
mov    $0x92,%r9d
mov    %r10d,(%rsp)
mov    %rax,0x8(%rsp)
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124b <json_parse_uint64+0x12b>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     1244 <json_parse_uint64+0x124>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     11f9 <json_parse_uint64+0xd9>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jle    1205 <json_parse_uint64+0xe5>
movl   $0x0,-0x4(%rbp)
jmp    124b <json_parse_uint64+0x12b>
mov    -0x20(%rbp),%rax
imul   $0xa,(%rax),%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%ecx
sub    $0x30,%ecx
mov    -0x20(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    11c5 <json_parse_uint64+0xa5>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<json_parse_uint64>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
mov    (%rdi),%rcx
mov    (%rcx),%al
add    $0xc6,%al
cmp    $0xf5,%al
ja     1180 <json_parse_uint64+0x60>
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
mov    (%rsp),%rdx
mov    0x8(%rsp),%ecx
mov    (%r15),%eax
lea    0xea1(%rip),%rsi
lea    0xef7(%rip),%r8
mov    $0x92,%r9d
push   (%r14)
push   %rax
call   1040 <fprintf@plt>
add    $0x10,%rsp
mov    $0xffffffff,%eax
jmp    11d2 <json_parse_uint64+0xb2>
movl   $0x0,(%rdx)
mov    (%r15),%rsi
mov    $0xffffffff,%eax
test   %rsi,%rsi
je     11d2 <json_parse_uint64+0xb2>
add    $0x1,%rcx
add    $0xffffffffffffffff,%rsi
xor    %edi,%edi
nopl   (%rax)
movzbl -0x1(%rcx),%ebx
add    $0xc6,%bl
cmp    $0xf6,%bl
jb     11d0 <json_parse_uint64+0xb0>
add    %edi,%edi
lea    (%rdi,%rdi,4),%edi
mov    %edi,(%rdx)
movsbl -0x1(%rcx),%ebx
add    %ebx,%edi
add    $0xffffffd0,%edi
mov    %edi,(%rdx)
mov    %rsi,(%r15)
mov    %rcx,(%r14)
add    $0x1,%rcx
add    $0xffffffffffffffff,%rsi
jb     11a0 <json_parse_uint64+0x80>
jmp    11d2 <json_parse_uint64+0xb2>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i8*, i32 }
@stderr = global i32 0
@.str = [93 x i8] c"%lu.%06lu %s:%d: Warning: Expected digit at start of string parsing\0ACurrent position: %.*s\0A\0A\00"
@.str.1 = [143 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/pombredanne/spiz/refs/heads/master/src/server/json.c\00"
define i32 @json_parse_uint64(i8** %0, i64* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64*
%7 = alloca i32*
%8 = alloca %struct.timeval
store i8** %0, i8*** %5
store i64* %1, i64** %6
store i32* %2, i32** %7
%9 = load i8**, i8*** %5
%10 = load i8*, i8** %9
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp slt i32 %12, 48
br i1 %13, label %20, label %14
14: ; preds = %3
%15 = load i8**, i8*** %5
%16 = load i8*, i8** %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp sgt i32 %18, 57
br i1 %19, label %20, label %35
20: ; preds = %14, %3
br label %21
21: ; preds = %20
%22 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
%23 = load i32, i32* @stderr
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%25 = load i8*, i8** %24
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%27 = load i32, i32* %26
%28 = load i64*, i64** %6
%29 = load i64, i64* %28
%30 = trunc i64 %29 to i32
%31 = load i8**, i8*** %5
%32 = load i8*, i8** %31
%33 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str, i64 0, i64 0), i8* %25, i32 %27, i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.1, i64 0, i64 0), i32 146, i32 %30, i8* %32)
br label %34
34: ; preds = %21
store i32 -1, i32* %4
br label %73
35: ; preds = %14
%36 = load i32*, i32** %7
store i32 0, i32* %36
br label %37
37: ; preds = %54, %35
%38 = load i64*, i64** %6
%39 = load i64, i64* %38
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %72
41: ; preds = %37
%42 = load i8**, i8*** %5
%43 = load i8*, i8** %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp slt i32 %45, 48
br i1 %46, label %53, label %47
47: ; preds = %41
%48 = load i8**, i8*** %5
%49 = load i8*, i8** %48
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp sgt i32 %51, 57
br i1 %52, label %53, label %54
53: ; preds = %47, %41
store i32 0, i32* %4
br label %73
54: ; preds = %47
%55 = load i32*, i32** %7
%56 = load i32, i32* %55
%57 = mul nsw i32 %56, 10
store i32 %57, i32* %55
%58 = load i8**, i8*** %5
%59 = load i8*, i8** %58
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = sub nsw i32 %61, 48
%63 = load i32*, i32** %7
%64 = load i32, i32* %63
%65 = add nsw i32 %64, %62
store i32 %65, i32* %63
%66 = load i64*, i64** %6
%67 = load i64, i64* %66
%68 = add i64 %67, -1
store i64 %68, i64* %66
%69 = load i8**, i8*** %5
%70 = load i8*, i8** %69
%71 = getelementptr inbounds i8, i8* %70, i32 1
store i8* %71, i8** %69
br label %37
72: ; preds = %37
store i32 -1, i32* %4
br label %73
73: ; preds = %72, %53, %34
%74 = load i32, i32* %4
ret i32 %74
}

LLVM IR (-O2):
%struct.timeval = type { i8*, i32 }
@stderr = global i32 0
@.str = [93 x i8] c"%lu.%06lu %s:%d: Warning: Expected digit at start of string parsing\0ACurrent position: %.*s\0A\0A\00"
@.str.1 = [143 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/pombredanne/spiz/refs/heads/master/src/server/json.c\00"
define i32 @json_parse_uint64(i8** nocapture %0, i64* nocapture %1, i32* nocapture %2) {
%4 = alloca %struct.timeval
%5 = load i8*, i8** %0
%6 = load i8, i8* %5
%7 = add i8 %6, -58
%8 = icmp ult i8 %7, -10
br i1 %8, label %9, label %21
9: ; preds = %3
%10 = bitcast %struct.timeval* %4 to i8*
%11 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%12 = load i32, i32* @stderr
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%14 = load i8*, i8** %13
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%16 = load i32, i32* %15
%17 = load i64, i64* %1
%18 = trunc i64 %17 to i32
%19 = load i8*, i8** %0
%20 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str, i64 0, i64 0), i8* %14, i32 %16, i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.1, i64 0, i64 0), i32 146, i32 %18, i8* %19)
br label %40
21: ; preds = %3
store i32 0, i32* %2
%22 = load i64, i64* %1
%23 = icmp eq i64 %22, 0
br i1 %23, label %40, label %24
24: ; preds = %21, %31
%25 = phi i32 [ %36, %31 ], [ 0, %21 ]
%26 = phi i8* [ %38, %31 ], [ %5, %21 ]
%27 = phi i64 [ %37, %31 ], [ %22, %21 ]
%28 = load i8, i8* %26
%29 = add i8 %28, -58
%30 = icmp ult i8 %29, -10
br i1 %30, label %40, label %31
31: ; preds = %24
%32 = mul nsw i32 %25, 10
store i32 %32, i32* %2
%33 = load i8, i8* %26
%34 = sext i8 %33 to i32
%35 = add i32 %32, -48
%36 = add i32 %35, %34
store i32 %36, i32* %2
%37 = add i64 %27, -1
store i64 %37, i64* %1
%38 = getelementptr inbounds i8, i8* %26, i64 1
store i8* %38, i8** %0
%39 = icmp eq i64 %37, 0
br i1 %39, label %40, label %24
40: ; preds = %24, %31, %21, %9
%41 = phi i32 [ -1, %9 ], [ -1, %21 ], [ 0, %24 ], [ -1, %31 ]
ret i32 %41
}