#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 /*<<< orphan*/ isdigit(char const);
int parse_dec(const char *s, int digits) {
  int n = 0;
  while (digits-- > 0) {
    if (!isdigit(*s))
      return -1;
    n = n * 10 + *s++ - '0';
  }
  return n;
}


x86 assembly (clang, -O0):
<parse_dec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
jle    117e <parse_dec+0x6e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    115b <parse_dec+0x4b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1184 <parse_dec+0x74>
imul   $0xa,-0x18(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
movsbl (%rcx),%ecx
add    %ecx,%eax
sub    $0x30,%eax
mov    %eax,-0x18(%rbp)
jmp    1126 <parse_dec+0x16>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_dec>:
push   %rbp
push   %r14
push   %rbx
test   %esi,%esi
jle    1159 <parse_dec+0x49>
mov    %esi,%ebp
mov    %rdi,%rbx
add    $0x1,%ebp
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     115e <parse_dec+0x4e>
lea    (%r14,%r14,4),%eax
movsbl (%rbx),%ecx
add    $0x1,%rbx
lea    (%rcx,%rax,2),%r14d
add    $0xffffffd0,%r14d
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
jg     1130 <parse_dec+0x20>
jmp    1164 <parse_dec+0x54>
xor    %r14d,%r14d
jmp    1164 <parse_dec+0x54>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @parse_dec(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %17, %2
%8 = load i32, i32* %5
%9 = add nsw i32 %8, -1
store i32 %9, i32* %5
%10 = icmp sgt i32 %8, 0
br i1 %10, label %11, label %26
11: ; preds = %7
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = call i32 @isdigit(i8 signext %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %11
store i32 -1, i32* %3
br label %28
17: ; preds = %11
%18 = load i32, i32* %6
%19 = mul nsw i32 %18, 10
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %4
%22 = load i8, i8* %20
%23 = sext i8 %22 to i32
%24 = add nsw i32 %19, %23
%25 = sub nsw i32 %24, 48
store i32 %25, i32* %6
br label %7
26: ; preds = %7
%27 = load i32, i32* %6
store i32 %27, i32* %3
br label %28
28: ; preds = %26, %16
%29 = load i32, i32* %3
ret i32 %29
}

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