#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 Util_sscandec(const char *s) {
  int result;
  if (*s == '\0')
    return -1;
  result = 0;
  for (;;) {
    if (*s >= '0' && *s <= '9')
      result = 10 * result + *s - '0';
    else if (*s == '\0')
      return result;
    else
      return -1;
    s++;
  }
}


x86 assembly (clang, -O0):
<Util_sscandec>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1124 <Util_sscandec+0x24>
movl   $0xffffffff,-0x4(%rbp)
jmp    119b <Util_sscandec+0x9b>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     1163 <Util_sscandec+0x63>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jg     1163 <Util_sscandec+0x63>
imul   $0xa,-0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
movsbl (%rcx),%ecx
add    %ecx,%eax
sub    $0x30,%eax
mov    %eax,-0x14(%rbp)
jmp    118a <Util_sscandec+0x8a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    117e <Util_sscandec+0x7e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119b <Util_sscandec+0x9b>
movl   $0xffffffff,-0x4(%rbp)
jmp    119b <Util_sscandec+0x9b>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    112b <Util_sscandec+0x2b>
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<Util_sscandec>:
mov    (%rdi),%cl
lea    -0x30(%rcx),%edx
mov    $0xffffffff,%eax
cmp    $0x9,%dl
ja     1140 <Util_sscandec+0x40>
add    $0x1,%rdi
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl %cl,%eax
lea    (%rdx,%rdx,4),%ecx
lea    (%rax,%rcx,2),%edx
add    $0xffffffd0,%edx
movzbl (%rdi),%ecx
lea    -0x30(%rcx),%eax
add    $0x1,%rdi
cmp    $0xa,%al
jb     1120 <Util_sscandec+0x20>
neg    %cl
sbb    %eax,%eax
or     %edx,%eax
ret

LLVM IR (-O0):
define i32 @Util_sscandec(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 -1, i32* %2
br label %40
10: ; preds = %1
store i32 0, i32* %4
br label %11
11: ; preds = %37, %10
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp sge i32 %14, 48
br i1 %15, label %16, label %29
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp sle i32 %19, 57
br i1 %20, label %21, label %29
21: ; preds = %16
%22 = load i32, i32* %4
%23 = mul nsw i32 10, %22
%24 = load i8*, i8** %3
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = add nsw i32 %23, %26
%28 = sub nsw i32 %27, 48
store i32 %28, i32* %4
br label %37
29: ; preds = %16, %11
%30 = load i8*, i8** %3
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = load i32, i32* %4
store i32 %35, i32* %2
br label %40
36: ; preds = %29
store i32 -1, i32* %2
br label %40
37: ; preds = %21
%38 = load i8*, i8** %3
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %3
br label %11
40: ; preds = %36, %34, %9
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
define i32 @Util_sscandec(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = add i8 %2, -48
%4 = icmp ult i8 %3, 10
br i1 %4, label %5, label %20
5: ; preds = %1, %5
%6 = phi i8 [ %14, %5 ], [ %2, %1 ]
%7 = phi i32 [ %12, %5 ], [ 0, %1 ]
%8 = phi i8* [ %13, %5 ], [ %0, %1 ]
%9 = zext i8 %6 to i32
%10 = mul nsw i32 %7, 10
%11 = add i32 %10, -48
%12 = add i32 %11, %9
%13 = getelementptr inbounds i8, i8* %8, i64 1
%14 = load i8, i8* %13
%15 = add i8 %14, -48
%16 = icmp ult i8 %15, 10
br i1 %16, label %5, label %17
17: ; preds = %5
%18 = icmp eq i8 %14, 0
%19 = select i1 %18, i32 %12, i32 -1
br label %20
20: ; preds = %17, %1
%21 = phi i32 [ -1, %1 ], [ %19, %17 ]
ret i32 %21
}