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


x86 assembly (clang, -O0):
<ft_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),%edi
call   1050 <ft_isspace@plt>
cmp    $0x0,%rax
je     1171 <ft_atoi+0x41>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    114a <ft_atoi+0x1a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <ft_issigned@plt>
cmp    $0x0,%rax
je     11ac <ft_atoi+0x7c>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%edx
mov    $0xffffffff,%eax
mov    $0x1,%ecx
cmp    $0x2b,%edx
cmove  %ecx,%eax
mov    %eax,-0x10(%rbp)
jmp    11b1 <ft_atoi+0x81>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <ft_isdigit@plt>
cmp    $0x0,%rax
je     11ea <ft_atoi+0xba>
imul   $0xa,-0xc(%rbp),%eax
mov    -0x8(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
movsbl (%rcx),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
jmp    11b1 <ft_atoi+0x81>
mov    -0x10(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_atoi>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
nopw   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
call   1050 <ft_isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1140 <ft_atoi+0x10>
lea    -0x1(%rbx),%r14
movsbl -0x1(%rbx),%edi
call   1040 <ft_issigned@plt>
test   %rax,%rax
je     1177 <ft_atoi+0x47>
xor    %eax,%eax
cmpb   $0x2b,(%r14)
sete   %al
lea    (%rax,%rax,1),%ebp
add    $0xffffffff,%ebp
mov    %rbx,%r14
jmp    117c <ft_atoi+0x4c>
mov    $0x1,%ebp
movsbl (%r14),%edi
call   1030 <ft_isdigit@plt>
test   %rax,%rax
je     11b2 <ft_atoi+0x82>
add    $0x1,%r14
xor    %ebx,%ebx
lea    (%rbx,%rbx,4),%eax
movsbl -0x1(%r14),%ecx
lea    (%rcx,%rax,2),%ebx
add    $0xffffffd0,%ebx
movsbl (%r14),%edi
call   1030 <ft_isdigit@plt>
add    $0x1,%r14
test   %rax,%rax
jne    1190 <ft_atoi+0x60>
jmp    11b4 <ft_atoi+0x84>
xor    %ebx,%ebx
imul   %ebp,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ft_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
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 = call i64 @ft_issigned(i8 signext %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %13
%19 = load i8*, i8** %2
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %2
%21 = load i8, i8* %19
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 43
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 1, i32 -1
store i32 %25, i32* %4
br label %26
26: ; preds = %18, %13
br label %27
27: ; preds = %32, %26
%28 = load i8*, i8** %2
%29 = load i8, i8* %28
%30 = call i64 @ft_isdigit(i8 signext %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %41
32: ; preds = %27
%33 = load i32, i32* %3
%34 = mul nsw i32 %33, 10
%35 = load i8*, i8** %2
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %2
%37 = load i8, i8* %35
%38 = sext i8 %37 to i32
%39 = sub nsw i32 %38, 48
%40 = add nsw i32 %34, %39
store i32 %40, i32* %3
br label %27
41: ; preds = %27
%42 = load i32, i32* %4
%43 = load i32, i32* %3
%44 = mul nsw i32 %43, %42
store i32 %44, i32* %3
%45 = load i32, i32* %3
ret i32 %45
}

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 = tail call i64 @ft_issigned(i8 signext %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %8
%13 = load i8, i8* %3
%14 = icmp eq i8 %13, 43
%15 = select i1 %14, i32 1, i32 -1
br label %16
16: ; preds = %12, %8
%17 = phi i8* [ %7, %12 ], [ %3, %8 ]
%18 = phi i32 [ %15, %12 ], [ 1, %8 ]
%19 = load i8, i8* %17
%20 = tail call i64 @ft_isdigit(i8 signext %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %34, label %22
22: ; preds = %16, %22
%23 = phi i32 [ %30, %22 ], [ 0, %16 ]
%24 = phi i8* [ %26, %22 ], [ %17, %16 ]
%25 = mul nsw i32 %23, 10
%26 = getelementptr inbounds i8, i8* %24, i64 1
%27 = load i8, i8* %24
%28 = sext i8 %27 to i32
%29 = add i32 %25, -48
%30 = add i32 %29, %28
%31 = load i8, i8* %26
%32 = tail call i64 @ft_isdigit(i8 signext %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %22
34: ; preds = %22, %16
%35 = phi i32 [ 0, %16 ], [ %30, %22 ]
%36 = mul nsw i32 %35, %18
ret i32 %36
}