#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__ ft_isdigit(char const);
scalar_t__ ft_isspace(char const);
int ft_atoi(const char *str) {
  int ans;
  int sign;
  while (ft_isspace(*str))
    ++str;
  sign = *str == '-' ? -1 : 1;
  if (*str == '+' || *str == '-')
    ++str;
  ans = 0;
  while (ft_isdigit(*str))
    ans = 10 * ans + sign * (*str++ - '0');
  return (ans);
}


x86 assembly (clang, -O0):
<ft_atoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <ft_isspace@plt>
cmp    $0x0,%rax
je     1153 <ft_atoi+0x33>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    112c <ft_atoi+0xc>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edx
mov    $0x1,%eax
mov    $0xffffffff,%ecx
cmp    $0x2d,%edx
cmove  %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
je     118d <ft_atoi+0x6d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1199 <ft_atoi+0x79>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <ft_isdigit@plt>
cmp    $0x0,%rax
je     11df <ft_atoi+0xbf>
imul   $0xa,-0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
mov    -0x8(%rbp),%rdx
mov    %rdx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x8(%rbp)
movsbl (%rdx),%edx
sub    $0x30,%edx
imul   %edx,%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
jmp    11a0 <ft_atoi+0x80>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_atoi>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
nopl   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
call   1040 <ft_isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1130 <ft_atoi+0x10>
mov    -0x1(%rbx),%r15b
lea    -0x2b(%r15),%eax
xor    %r12d,%r12d
test   $0xfd,%al
sete   %r12b
movsbl -0x1(%rbx,%r12,1),%edi
call   1030 <ft_isdigit@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     11a2 <ft_atoi+0x82>
cs nopw 0x0(%rax,%rax,1)
nop
movsbl -0x1(%rbx,%r12,1),%eax
mov    $0x30,%ecx
sub    %eax,%ecx
add    $0xffffffd0,%eax
cmp    $0x2d,%r15b
lea    (%r14,%r14,4),%edx
cmove  %ecx,%eax
lea    (%rax,%rdx,2),%r14d
movsbl (%rbx,%r12,1),%edi
call   1030 <ft_isdigit@plt>
add    $0x1,%r12
test   %rax,%rax
jne    1170 <ft_atoi+0x50>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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