#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(char const);
int atoi(const char *c) {
  int result = 0, sign = 1;
  if (*c == '+')
    c++;
  if (*c == '-') {
    sign = -1;
    c++;
  }
  while (isdigit(*c)) {
    result *= 10;
    result += (int)(*c - '0');
    c++;
  }
  return result * sign;
}


x86 assembly (clang, -O0):
<atoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    1146 <atoi+0x36>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1169 <atoi+0x59>
movl   $0xffffffff,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    116e <atoi+0x5e>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11ac <atoi+0x9c>
imul   $0xa,-0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    116e <atoi+0x5e>
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atoi>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
xor    %ebp,%ebp
cmpb   $0x2b,(%rdi)
sete   %bpl
lea    (%rdi,%rbp,1),%rax
mov    (%rdi,%rbp,1),%r14b
xor    %ebx,%ebx
cmp    $0x2d,%r14b
sete   %bl
movsbl (%rbx,%rax,1),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1171 <atoi+0x61>
add    %rbp,%rbx
lea    (%r15,%rbx,1),%rbp
add    $0x1,%rbp
xor    %ebx,%ebx
nop
lea    (%rbx,%rbx,4),%eax
movsbl -0x1(%rbp),%ecx
lea    (%rcx,%rax,2),%ebx
add    $0xffffffd0,%ebx
movsbl 0x0(%rbp),%edi
call   1030 <isdigit@plt>
add    $0x1,%rbp
test   %rax,%rax
jne    1150 <atoi+0x40>
jmp    1173 <atoi+0x63>
xor    %ebx,%ebx
mov    %ebx,%eax
neg    %eax
cmp    $0x2d,%r14b
cmovne %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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