#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 */
scalar_t__ isdigit(unsigned char);
int ccnl_ccnb_data2uint(unsigned char *cp, int len) {
  int i, val;
  for (i = 0, val = 0; i < len; i++)
    if (isdigit(cp[i]))
      val = 10 * val + cp[i] - '0';
    else
      return -1;
  return val;
}


x86 assembly (clang, -O0):
<ccnl_ccnb_data2uint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1190 <ccnl_ccnb_data2uint+0x80>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1171 <ccnl_ccnb_data2uint+0x61>
imul   $0xa,-0x1c(%rbp),%eax
mov    -0x10(%rbp),%rcx
movslq -0x18(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
add    %ecx,%eax
sub    $0x30,%eax
mov    %eax,-0x1c(%rbp)
jmp    117d <ccnl_ccnb_data2uint+0x6d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1196 <ccnl_ccnb_data2uint+0x86>
jmp    1182 <ccnl_ccnb_data2uint+0x72>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112d <ccnl_ccnb_data2uint+0x1d>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ccnl_ccnb_data2uint>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    115b <ccnl_ccnb_data2uint+0x4b>
mov    %rdi,%r14
mov    %esi,%r15d
xor    %ebx,%ebx
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
movzbl (%r14,%rbx,1),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1160 <ccnl_ccnb_data2uint+0x50>
lea    (%r12,%r12,4),%eax
movzbl (%r14,%rbx,1),%ecx
lea    (%rcx,%rax,2),%r12d
add    $0xffffffd0,%r12d
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1130 <ccnl_ccnb_data2uint+0x20>
jmp    1166 <ccnl_ccnb_data2uint+0x56>
xor    %r12d,%r12d
jmp    1166 <ccnl_ccnb_data2uint+0x56>
mov    $0xffffffff,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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