#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 */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int test_uint64(const char *value, uint64_t *pr) {
  const char *p = value;
  if (!*p) {
    fprintf(stderr, "Invalid empty integer value\n");
    return -1;
  }
  *pr = 0;
  while (*p) {
    if (*pr > ((uint64_t)-1) / 10) {
      fprintf(stderr, "Integer string overflow value=%s\n", value);
      return -1;
    }
    *pr *= 10;
    if (*p < '0' || *p > '9') {
      fprintf(stderr, "Invalid integer string value=%s\n", value);
      return -1;
    }
    *pr += *p - '0';
    p++;
  }
  return 1;
}


x86 assembly (clang, -O0):
<test_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
cmpb   $0x0,(%rax)
jne    1158 <test_uint64+0x48>
mov    0x2ea4(%rip),%rax
mov    (%rax),%edi
lea    0xebb(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121d <test_uint64+0x10d>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     1216 <test_uint64+0x106>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jle    11a3 <test_uint64+0x93>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe8d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121d <test_uint64+0x10d>
mov    -0x18(%rbp),%rax
imul   $0xa,(%rax),%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     11cc <test_uint64+0xbc>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jle    11f3 <test_uint64+0xe3>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe5f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121d <test_uint64+0x10d>
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    1162 <test_uint64+0x52>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_uint64>:
push   %rax
cmpb   $0x0,(%rdi)
je     115b <test_uint64+0x4b>
mov    %rdi,%r8
movl   $0x0,(%rsi)
mov    $0x1,%eax
cmpb   $0x0,(%rdi)
je     1159 <test_uint64+0x49>
lea    0x1(%r8),%r9
xor    %edi,%edi
nop
test   %edi,%edi
jg     1174 <test_uint64+0x64>
add    %edi,%edi
lea    (%rdi,%rdi,4),%edi
mov    %edi,(%rsi)
movzbl -0x1(%r9),%edx
lea    -0x3a(%rdx),%ecx
cmp    $0xf5,%cl
jbe    1186 <test_uint64+0x76>
add    %edx,%edi
add    $0xffffffd0,%edi
mov    %edi,(%rsi)
cmpb   $0x0,(%r9)
lea    0x1(%r9),%r9
jne    1130 <test_uint64+0x20>
pop    %rcx
ret
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
lea    0xe95(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11a0 <test_uint64+0x90>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    0xe99(%rip),%rsi
jmp    1196 <test_uint64+0x86>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0xea9(%rip),%rsi
mov    %r8,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"Invalid empty integer value\0A\00"
@.str.1 = [34 x i8] c"Integer string overflow value=%s\0A\00"
@.str.2 = [33 x i8] c"Invalid integer string value=%s\0A\00"
define i32 @test_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 = icmp ne i8 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %56
14: ; preds = %2
%15 = load i32*, i32** %5
store i32 0, i32* %15
br label %16
16: ; preds = %45, %14
%17 = load i8*, i8** %6
%18 = load i8, i8* %17
%19 = icmp ne i8 %18, 0
br i1 %19, label %20, label %55
20: ; preds = %16
%21 = load i32*, i32** %5
%22 = load i32, i32* %21
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %4
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %26)
store i32 -1, i32* %3
br label %56
28: ; preds = %20
%29 = load i32*, i32** %5
%30 = load i32, i32* %29
%31 = mul nsw i32 %30, 10
store i32 %31, i32* %29
%32 = load i8*, i8** %6
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp slt i32 %34, 48
br i1 %35, label %41, label %36
36: ; preds = %28
%37 = load i8*, i8** %6
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp sgt i32 %39, 57
br i1 %40, label %41, label %45
41: ; preds = %36, %28
%42 = load i32, i32* @stderr
%43 = load i8*, i8** %4
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %43)
store i32 -1, i32* %3
br label %56
45: ; preds = %36
%46 = load i8*, i8** %6
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = sub nsw i32 %48, 48
%50 = load i32*, i32** %5
%51 = load i32, i32* %50
%52 = add nsw i32 %51, %49
store i32 %52, i32* %50
%53 = load i8*, i8** %6
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %6
br label %16
55: ; preds = %16
store i32 1, i32* %3
br label %56
56: ; preds = %55, %41, %24, %11
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"Invalid empty integer value\0A\00"
@.str.1 = [34 x i8] c"Integer string overflow value=%s\0A\00"
@.str.2 = [33 x i8] c"Invalid integer string value=%s\0A\00"
define i32 @test_uint64(i8* %0, i32* nocapture %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %33
8: ; preds = %2
store i32 0, i32* %1
%9 = load i8, i8* %0
%10 = icmp eq i8 %9, 0
br i1 %10, label %33, label %11
11: ; preds = %8, %26
%12 = phi i32 [ %29, %26 ], [ 0, %8 ]
%13 = phi i8* [ %30, %26 ], [ %0, %8 ]
%14 = icmp sgt i32 %12, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %33
18: ; preds = %11
%19 = mul nsw i32 %12, 10
store i32 %19, i32* %1
%20 = load i8, i8* %13
%21 = add i8 %20, -58
%22 = icmp ult i8 %21, -10
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %33
26: ; preds = %18
%27 = zext i8 %20 to i32
%28 = add i32 %19, -48
%29 = add i32 %28, %27
store i32 %29, i32* %1
%30 = getelementptr inbounds i8, i8* %13, i64 1
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 0
br i1 %32, label %33, label %11
33: ; preds = %26, %8, %23, %15, %5
%34 = phi i32 [ -1, %15 ], [ -1, %23 ], [ -1, %5 ], [ 1, %8 ], [ 1, %26 ]
ret i32 %34
}