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

/* Variables and functions */
scalar_t__ errno;
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strtoll(char *, char **, int);
int parse_decimal(char *text, uint64_t *integer) {
  register int k;
  if (text == NULL) {
    printf("%s"
           "\n",
           "unable to parse integer value");
    return ((0));
  };
  for (k = 0; text[k] != 0 && text[k] >= '0' && text[k] <= '9'; k++)
    ;
  if (text[k] != 0) {
    printf("%s"
           "\n",
           "unable to parse integer value");
    return ((0));
  };
  char *endptr;
  errno = 0;
  *integer = (uint64_t)strtoll(text, &endptr, 10);
  if (errno != 0 || endptr == text) {
    printf("%s"
           "\n",
           "unable to parse integer value");
    return ((0));
  };
  return ((!(0)));
}


x86 assembly (clang, -O0):
<parse_decimal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115a <parse_decimal+0x3a>
lea    0xebe(%rip),%rdi
lea    0xebb(%rip),%rsi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1270 <parse_decimal+0x150>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
je     11aa <parse_decimal+0x8a>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x29(%rbp)
jl     11aa <parse_decimal+0x8a>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x39,%eax
setle  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11ba <parse_decimal+0x9a>
jmp    11cd <parse_decimal+0xad>
jmp    11bf <parse_decimal+0x9f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1161 <parse_decimal+0x41>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1201 <parse_decimal+0xe1>
lea    0xe17(%rip),%rdi
lea    0xe14(%rip),%rsi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1270 <parse_decimal+0x150>
mov    0x2dd8(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtoll@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    0x2dae(%rip),%rax
cmpq   $0x0,(%rax)
jne    124a <parse_decimal+0x12a>
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1269 <parse_decimal+0x149>
lea    0xdaf(%rip),%rdi
lea    0xdac(%rip),%rsi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1270 <parse_decimal+0x150>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_decimal>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
je     1153 <parse_decimal+0x33>
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rdi,%rax
nopw   0x0(%rax,%rax,1)
movzbl (%rax),%ecx
lea    -0x30(%rcx),%edx
add    $0x1,%rax
cmp    $0xa,%dl
jb     1140 <parse_decimal+0x20>
test   %cl,%cl
je     1172 <parse_decimal+0x52>
lea    0xea6(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e67(%rip),%r15
movq   $0x0,(%r15)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtoll@plt>
mov    %rax,(%r14)
cmpq   $0x0,(%r15)
jne    1153 <parse_decimal+0x33>
mov    $0x1,%eax
cmp    %rbx,0x8(%rsp)
jne    1168 <parse_decimal+0x48>
jmp    1153 <parse_decimal+0x33>

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [30 x i8] c"unable to parse integer value\00"
@errno = global i64 0
define i32 @parse_decimal(i8* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i64* %1, i64** %5
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %66
12: ; preds = %2
store i32 0, i32* %6
br label %13
13: ; preds = %40, %12
%14 = load i8*, i8** %4
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %37
21: ; preds = %13
%22 = load i8*, i8** %4
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp sge i32 %27, 48
br i1 %28, label %29, label %37
29: ; preds = %21
%30 = load i8*, i8** %4
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp sle i32 %35, 57
br label %37
37: ; preds = %29, %21, %13
%38 = phi i1 [ false, %21 ], [ false, %13 ], [ %36, %29 ]
br i1 %38, label %39, label %43
39: ; preds = %37
br label %40
40: ; preds = %39
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
br label %13
43: ; preds = %37
%44 = load i8*, i8** %4
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %43
%52 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %66
53: ; preds = %43
store i64 0, i64* @errno
%54 = load i8*, i8** %4
%55 = call i64 @strtoll(i8* %54, i8** %7, i32 10)
%56 = load i64*, i64** %5
store i64 %55, i64* %56
%57 = load i64, i64* @errno
%58 = icmp ne i64 %57, 0
br i1 %58, label %63, label %59
59: ; preds = %53
%60 = load i8*, i8** %7
%61 = load i8*, i8** %4
%62 = icmp eq i8* %60, %61
br i1 %62, label %63, label %65
63: ; preds = %59, %53
%64 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %66
65: ; preds = %59
store i32 1, i32* %3
br label %66
66: ; preds = %65, %63, %51, %10
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [30 x i8] c"unable to parse integer value\00"
@errno = global i64 0
define i32 @parse_decimal(i8* %0, i64* nocapture writeonly %1) {
%3 = alloca i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %30
7: ; preds = %2, %7
%8 = phi i64 [ %13, %7 ], [ 0, %2 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = add i8 %10, -48
%12 = icmp ult i8 %11, 10
%13 = add nuw i64 %8, 1
br i1 %12, label %7, label %14
14: ; preds = %7
%15 = icmp eq i8 %10, 0
br i1 %15, label %18, label %16
16: ; preds = %14
%17 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %30
18: ; preds = %14
%19 = bitcast i8** %3 to i8*
store i64 0, i64* @errno
%20 = call i64 @strtoll(i8* %0, i8** %3, i32 10)
store i64 %20, i64* %1
%21 = load i64, i64* @errno
%22 = icmp ne i64 %21, 0
%23 = load i8*, i8** %3
%24 = icmp eq i8* %23, %0
%25 = select i1 %22, i1 true, i1 %24
br i1 %25, label %26, label %28
26: ; preds = %18
%27 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %18, %26
%29 = phi i32 [ 0, %26 ], [ 1, %18 ]
br label %30
30: ; preds = %28, %16, %5
%31 = phi i32 [ 0, %5 ], [ 0, %16 ], [ %29, %28 ]
ret i32 %31
}