#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(scalar_t__);
scalar_t__ ft_iswhitespace(char const);
unsigned long long ft_atoull(const char *str) {
  unsigned long long result;
  unsigned long long temp;
  result = 0;
  temp = 0;
  while (ft_iswhitespace(*str))
    str++;
  if (*str == '+')
    str++;
  while (ft_isdigit(*str - 0)) {
    temp = result;
    result = 10 * result + ((*str++ - '0') % 10);
    if (result < temp)
      return (temp);
  }
  return (result);
}


x86 assembly (clang, -O0):
<ft_atoull>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <ft_iswhitespace@plt>
cmp    $0x0,%rax
je     1163 <ft_atoull+0x43>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    113c <ft_atoull+0x1c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    117f <ft_atoull+0x5f>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1184 <ft_atoull+0x64>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
sub    $0x0,%eax
movslq %eax,%rdi
call   1030 <ft_isdigit@plt>
cmp    $0x0,%rax
je     11fc <ft_atoull+0xdc>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
imul   $0xa,-0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
sub    $0x30,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x28(%rbp),%rax
movslq %edx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11f7 <ft_atoull+0xd7>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1204 <ft_atoull+0xe4>
jmp    1184 <ft_atoull+0x64>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_atoull>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
add    $0xffffffffffffffff,%rbx
nopl   0x0(%rax,%rax,1)
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1040 <ft_iswhitespace@plt>
test   %rax,%rax
jne    1130 <ft_atoull+0x10>
xor    %r14d,%r14d
cmpb   $0x2b,(%rbx)
sete   %r14b
add    %rbx,%r14
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rax,%rbx
movsbq (%r14),%rdi
call   1030 <ft_isdigit@plt>
test   %rax,%rax
je     11a4 <ft_atoull+0x84>
lea    (%rbx,%rbx,4),%rax
movsbl (%r14),%ecx
add    $0x1,%r14
add    $0xffffffd0,%ecx
imul   $0x6667,%ecx,%edx
mov    %edx,%esi
shr    $0x1f,%esi
sar    $0x12,%edx
add    %esi,%edx
add    %edx,%edx
lea    (%rdx,%rdx,4),%edx
sub    %edx,%ecx
movswq %cx,%rcx
lea    (%rcx,%rax,2),%rax
cmp    %rbx,%rax
jae    1160 <ft_atoull+0x40>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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