#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 int uint8_t;
typedef int int64_t;

/* Variables and functions */
int64_t strtosint64(const char *s) {
  int sign;
  int64_t i;
  uint8_t b;
  if (*s == '-') {
    s++;
    sign = -1;
  } else
    sign = 1;
  i = 0;
  for (;;) {
    b = (uint8_t)(*s++ - '0');
    if (b >= 10)
      break;
    i = i * 10 + b;
  }
  return i * sign;
}


x86 assembly (clang, -O0):
<strtosint64>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1130 <strtosint64+0x30>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
jmp    1137 <strtosint64+0x37>
movl   $0x1,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jl     1165 <strtosint64+0x65>
jmp    1174 <strtosint64+0x74>
imul   $0xa,-0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    113e <strtosint64+0x3e>
mov    -0x10(%rbp),%eax
imul   -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtosint64>:
mov    (%rdi),%cl
xor    %esi,%esi
cmp    $0x2d,%cl
sete   %sil
mov    (%rdi,%rsi,1),%al
xor    %edx,%edx
cmp    $0x39,%al
jg     1137 <strtosint64+0x37>
add    %rdi,%rsi
add    $0x1,%rsi
xor    %edx,%edx
nopl   (%rax)
movsbl %al,%eax
lea    (%rdx,%rdx,4),%edx
lea    (%rax,%rdx,2),%edx
add    $0xffffffd0,%edx
movzbl (%rsi),%eax
add    $0x1,%rsi
cmp    $0x3a,%al
jl     1120 <strtosint64+0x20>
mov    %edx,%eax
neg    %eax
cmp    $0x2d,%cl
cmovne %edx,%eax
ret

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

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