#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);
int ft_atoi_printf(char *str) {
  int result;
  int sign;
  int i;
  i = 0;
  result = 0;
  sign = 1;
  while (ft_isdigit(str[i])) {
    result = (result * 10) + (str[i] - '0');
    ++i;
  }
  return (result * sign);
}


x86 assembly (clang, -O0):
<ft_atoi_printf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <ft_isdigit@plt>
cmp    $0x0,%rax
je     1172 <ft_atoi_printf+0x62>
imul   $0xa,-0xc(%rbp),%eax
mov    -0x8(%rbp),%rcx
movslq -0x14(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1131 <ft_atoi_printf+0x21>
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_atoi_printf>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <ft_isdigit@plt>
test   %rax,%rax
je     1153 <ft_atoi_printf+0x43>
add    $0x1,%rbx
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
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    1130 <ft_atoi_printf+0x20>
jmp    1156 <ft_atoi_printf+0x46>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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