#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;

/* Variables and functions */
scalar_t__ isdigit(unsigned char);
int /*<<< orphan*/ test_error(char *, int, char *, char const *);
int /*<<< orphan*/ test_info(char *, int, char *);
int /*<<< orphan*/ test_true(char *, int, char *, int);
int parse_uint64(const char *value, uint64_t *pr) {
  const char *p = value;
  if (!test_true(
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/papyrussolution/OpenPapyrus/refs/heads/"
          "master/Src/OSF/OpenSSL-111/test/evp_test.c",
          1379, "*p", (*p) != 0)) {
    test_info("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/papyrussolution/OpenPapyrus/refs/"
              "heads/master/Src/OSF/OpenSSL-111/test/evp_test.c",
              1380, "Invalid empty integer value");
    return -1;
  }
  for (*pr = 0; *p;) {
    if (*pr > ((uint64_t)-1) / 10) {
      test_error(
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/papyrussolution/OpenPapyrus/refs/heads/"
          "master/Src/OSF/OpenSSL-111/test/evp_test.c",
          1385, "Integer overflow in string %s", value);
      return -1;
    }
    *pr *= 10;
    if (!test_true(
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/papyrussolution/OpenPapyrus/refs/heads/"
            "master/Src/OSF/OpenSSL-111/test/evp_test.c",
            1389, "isdigit((unsigned char)*p)",
            (isdigit((unsigned char)*p)) != 0)) {
      test_error(
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/papyrussolution/OpenPapyrus/refs/heads/"
          "master/Src/OSF/OpenSSL-111/test/evp_test.c",
          1390, "Invalid character in string %s", value);
      return -1;
    }
    *pr += *p - '0';
    p++;
  }
  return 1;
}


x86 assembly (clang, -O0):
<parse_uint64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%ecx
lea    0xe8f(%rip),%rdi
mov    $0x563,%esi
lea    0xf2f(%rip),%rdx
call   1030 <test_true@plt>
cmp    $0x0,%eax
jne    11af <parse_uint64+0x6f>
lea    0xe6e(%rip),%rdi
mov    $0x564,%esi
lea    0xf11(%rip),%rdx
call   1050 <test_info@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128f <parse_uint64+0x14f>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     1288 <parse_uint64+0x148>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jle    11fb <parse_uint64+0xbb>
mov    -0x10(%rbp),%rcx
lea    0xe22(%rip),%rdi
mov    $0x569,%esi
lea    0xee1(%rip),%rdx
call   1060 <test_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128f <parse_uint64+0x14f>
mov    -0x18(%rbp),%rax
imul   $0xa,(%rax),%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
movzbl (%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%ecx
lea    0xddd(%rip),%rdi
mov    $0x56d,%esi
lea    0xeba(%rip),%rdx
call   1030 <test_true@plt>
cmp    $0x0,%eax
jne    1265 <parse_uint64+0x125>
mov    -0x10(%rbp),%rcx
lea    0xdb8(%rip),%rdi
mov    $0x56e,%esi
lea    0xeb0(%rip),%rdx
call   1060 <test_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128f <parse_uint64+0x14f>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
sub    $0x30,%ecx
mov    -0x18(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11b9 <parse_uint64+0x79>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_uint64>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %ecx,%ecx
cmpb   $0x0,(%rdi)
setne  %cl
lea    0xea0(%rip),%rdi
lea    0xf45(%rip),%rdx
mov    $0x563,%esi
call   1030 <test_true@plt>
test   %eax,%eax
je     11e9 <parse_uint64+0xa9>
movl   $0x0,(%rbx)
mov    $0x1,%r15d
cmpb   $0x0,(%r14)
je     1239 <parse_uint64+0xf9>
xor    %eax,%eax
lea    0xe6c(%rip),%r12
lea    0xf4e(%rip),%r13
mov    %r14,%rbp
xchg   %ax,%ax
test   %eax,%eax
jg     1203 <parse_uint64+0xc3>
add    %eax,%eax
lea    (%rax,%rax,4),%eax
mov    %eax,(%rbx)
movzbl 0x0(%rbp),%edi
call   1040 <isdigit@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
mov    %r12,%rdi
mov    $0x56d,%esi
mov    %r13,%rdx
call   1030 <test_true@plt>
test   %eax,%eax
je     1218 <parse_uint64+0xd8>
movsbl 0x0(%rbp),%eax
mov    (%rbx),%ecx
add    %ecx,%eax
add    $0xffffffd0,%eax
mov    %eax,(%rbx)
cmpb   $0x0,0x1(%rbp)
lea    0x1(%rbp),%rbp
jne    11a0 <parse_uint64+0x60>
jmp    1239 <parse_uint64+0xf9>
lea    0xe10(%rip),%rdi
lea    0xeb8(%rip),%rdx
mov    $0x564,%esi
call   1050 <test_info@plt>
jmp    1233 <parse_uint64+0xf3>
lea    0xdf6(%rip),%rdi
lea    0xeba(%rip),%rdx
mov    $0x569,%esi
jmp    122b <parse_uint64+0xeb>
lea    0xde1(%rip),%rdi
lea    0xede(%rip),%rdx
mov    $0x56e,%esi
mov    %r14,%rcx
call   1060 <test_error@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [172 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/papyrussolution/OpenPapyrus/refs/heads/master/Src/OSF/OpenSSL-111/test/evp_test.c\00"
@.str.1 = [3 x i8] c"*p\00"
@.str.2 = [28 x i8] c"Invalid empty integer value\00"
@.str.3 = [30 x i8] c"Integer overflow in string %s\00"
@.str.4 = [27 x i8] c"isdigit((unsigned char)*p)\00"
@.str.5 = [31 x i8] c"Invalid character in string %s\00"
define i32 @parse_uint64(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
%7 = load i8*, i8** %4
store i8* %7, i8** %6
%8 = load i8*, i8** %6
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @test_true(i8* getelementptr inbounds ([172 x i8], [172 x i8]* @.str, i64 0, i64 0), i32 1379, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %2
%16 = call i32 @test_info(i8* getelementptr inbounds ([172 x i8], [172 x i8]* @.str, i64 0, i64 0), i32 1380, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %55
17: ; preds = %2
%18 = load i32*, i32** %5
store i32 0, i32* %18
br label %19
19: ; preds = %44, %17
%20 = load i8*, i8** %6
%21 = load i8, i8* %20
%22 = icmp ne i8 %21, 0
br i1 %22, label %23, label %54
23: ; preds = %19
%24 = load i32*, i32** %5
%25 = load i32, i32* %24
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i8*, i8** %4
%29 = call i32 @test_error(i8* getelementptr inbounds ([172 x i8], [172 x i8]* @.str, i64 0, i64 0), i32 1385, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %28)
store i32 -1, i32* %3
br label %55
30: ; preds = %23
%31 = load i32*, i32** %5
%32 = load i32, i32* %31
%33 = mul nsw i32 %32, 10
store i32 %33, i32* %31
%34 = load i8*, i8** %6
%35 = load i8, i8* %34
%36 = call i64 @isdigit(i8 zeroext %35)
%37 = icmp ne i64 %36, 0
%38 = zext i1 %37 to i32
%39 = call i32 @test_true(i8* getelementptr inbounds ([172 x i8], [172 x i8]* @.str, i64 0, i64 0), i32 1389, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %38)
%40 = icmp ne i32 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %30
%42 = load i8*, i8** %4
%43 = call i32 @test_error(i8* getelementptr inbounds ([172 x i8], [172 x i8]* @.str, i64 0, i64 0), i32 1390, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i8* %42)
store i32 -1, i32* %3
br label %55
44: ; preds = %30
%45 = load i8*, i8** %6
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = sub nsw i32 %47, 48
%49 = load i32*, i32** %5
%50 = load i32, i32* %49
%51 = add nsw i32 %50, %48
store i32 %51, i32* %49
%52 = load i8*, i8** %6
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %6
br label %19
54: ; preds = %19
store i32 1, i32* %3
br label %55
55: ; preds = %54, %41, %27, %15
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@.str = [172 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/papyrussolution/OpenPapyrus/refs/heads/master/Src/OSF/OpenSSL-111/test/evp_test.c\00"
@.str.1 = [3 x i8] c"*p\00"
@.str.2 = [28 x i8] c"Invalid empty integer value\00"
@.str.3 = [30 x i8] c"Integer overflow in string %s\00"
@.str.4 = [27 x i8] c"isdigit((unsigned char)*p)\00"
@.str.5 = [31 x i8] c"Invalid character in string %s\00"
define i32 @parse_uint64(i8* %0, i32* nocapture %1) {
%3 = load i8, i8* %0
%4 = icmp ne i8 %3, 0
%5 = zext i1 %4 to i32
%6 = tail call i32 @test_true(i8* getelementptr inbounds ([172 x i8], [172 x i8]* @.str, i64 0, i64 0), i32 1379, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @test_info(i8* getelementptr inbounds ([172 x i8], [172 x i8]* @.str, i64 0, i64 0), i32 1380, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %38
10: ; preds = %2
store i32 0, i32* %1
%11 = load i8, i8* %0
%12 = icmp eq i8 %11, 0
br i1 %12, label %38, label %13
13: ; preds = %10, %29
%14 = phi i32 [ %34, %29 ], [ 0, %10 ]
%15 = phi i8* [ %35, %29 ], [ %0, %10 ]
%16 = icmp sgt i32 %14, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = tail call i32 @test_error(i8* getelementptr inbounds ([172 x i8], [172 x i8]* @.str, i64 0, i64 0), i32 1385, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %38
19: ; preds = %13
%20 = mul nsw i32 %14, 10
store i32 %20, i32* %1
%21 = load i8, i8* %15
%22 = tail call i64 @isdigit(i8 zeroext %21)
%23 = icmp ne i64 %22, 0
%24 = zext i1 %23 to i32
%25 = tail call i32 @test_true(i8* getelementptr inbounds ([172 x i8], [172 x i8]* @.str, i64 0, i64 0), i32 1389, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %24)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %19
%28 = tail call i32 @test_error(i8* getelementptr inbounds ([172 x i8], [172 x i8]* @.str, i64 0, i64 0), i32 1390, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i8* %0)
br label %38
29: ; preds = %19
%30 = load i8, i8* %15
%31 = sext i8 %30 to i32
%32 = add nsw i32 %31, -48
%33 = load i32, i32* %1
%34 = add nsw i32 %32, %33
store i32 %34, i32* %1
%35 = getelementptr inbounds i8, i8* %15, i64 1
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 0
br i1 %37, label %38, label %13
38: ; preds = %29, %10, %27, %17, %8
%39 = phi i32 [ -1, %17 ], [ -1, %27 ], [ -1, %8 ], [ 1, %10 ], [ 1, %29 ]
ret i32 %39
}