#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__ _isnumber(char);
int str2int(char *str) {
  int result = 0;
  for (int i = 0; _isnumber(str[i]); i++) {
    result = result * 10;
    result += str[i] - '0';
  }
  return result;
}


x86 assembly (clang, -O0):
<str2int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <_isnumber@plt>
cmp    $0x0,%rax
je     116f <str2int+0x5f>
imul   $0xa,-0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
sub    $0x30,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112a <str2int+0x1a>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2int>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <_isnumber@plt>
test   %rax,%rax
je     1153 <str2int+0x43>
add    $0x1,%rbx
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
lea    (%r14,%r14,4),%eax
movsbl -0x1(%rbx),%ecx
lea    (%rcx,%rax,2),%r14d
add    $0xffffffd0,%r14d
movsbl (%rbx),%edi
call   1030 <_isnumber@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1130 <str2int+0x20>
jmp    1156 <str2int+0x46>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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