#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 num;
  int sign;
  num = 0;
  sign = 1;
  while (ft_isspace(*str))
    str++;
  if (*str == '-') {
    sign = -1;
    str++;
  } else if (*str == '+')
    str++;
  while (ft_isdigit(*str)) {
    num = num * 10 + (*str - '0');
    str++;
  }
  return (num * sign);
}


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   1040 <ft_isspace@plt>
cmp    $0x0,%rax
je     1161 <ft_atoi+0x41>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    113a <ft_atoi+0x1a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1189 <ft_atoi+0x69>
movl   $0xffffffff,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11aa <ft_atoi+0x8a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    11a5 <ft_atoi+0x85>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11aa <ft_atoi+0x8a>
jmp    11af <ft_atoi+0x8f>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <ft_isdigit@plt>
cmp    $0x0,%rax
je     11e9 <ft_atoi+0xc9>
imul   $0xa,-0xc(%rbp),%eax
mov    -0x8(%rbp),%rcx
movsbl (%rcx),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11af <ft_atoi+0x8f>
mov    -0xc(%rbp),%eax
imul   -0x10(%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   1040 <ft_isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1130 <ft_atoi+0x10>
mov    -0x1(%rbx),%al
cmp    $0x2b,%al
je     1157 <ft_atoi+0x37>
cmp    $0x2d,%al
jne    1153 <ft_atoi+0x33>
mov    $0xffffffff,%ebp
jmp    115c <ft_atoi+0x3c>
add    $0xffffffffffffffff,%rbx
mov    $0x1,%ebp
movsbl (%rbx),%edi
call   1030 <ft_isdigit@plt>
test   %rax,%rax
je     1193 <ft_atoi+0x73>
add    $0x1,%rbx
xor    %r14d,%r14d
lea    (%r14,%r14,4),%eax
movsbl -0x1(%rbx),%ecx
lea    (%rcx,%rax,2),%r14d
add    $0xffffffd0,%r14d
movsbl (%rbx),%edi
call   1030 <ft_isdigit@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1170 <ft_atoi+0x50>
jmp    1196 <ft_atoi+0x76>
xor    %r14d,%r14d
imul   %ebp,%r14d
mov    %r14d,%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 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 45
br i1 %17, label %18, label %21
18: ; preds = %13
store i32 -1, i32* %4
%19 = load i8*, i8** %2
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %2
br label %30
21: ; preds = %13
%22 = load i8*, i8** %2
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 43
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i8*, i8** %2
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %2
br label %29
29: ; preds = %26, %21
br label %30
30: ; preds = %29, %18
br label %31
31: ; preds = %36, %30
%32 = load i8*, i8** %2
%33 = load i8, i8* %32
%34 = call i64 @ft_isdigit(i8 signext %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %46
36: ; preds = %31
%37 = load i32, i32* %3
%38 = mul nsw i32 %37, 10
%39 = load i8*, i8** %2
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = sub nsw i32 %41, 48
%43 = add nsw i32 %38, %42
store i32 %43, i32* %3
%44 = load i8*, i8** %2
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %2
br label %31
46: ; preds = %31
%47 = load i32, i32* %3
%48 = load i32, i32* %4
%49 = mul nsw i32 %47, %48
ret i32 %49
}

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