#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__ isdigit(char const);
scalar_t__ isspace(char const);
long long int my_atoll(const char *nptr) {
  long long int returnval = 0LL;
  int max_digits = 30;
  while (isspace(*nptr)) {
    nptr++;
  }
  while (--max_digits && isdigit(*nptr)) {
    returnval = (returnval * 10) + (*nptr++ - '0');
  }
  return returnval;
}


x86 assembly (clang, -O0):
<my_atoll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x1e,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     1162 <my_atoll+0x42>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    113b <my_atoll+0x1b>
jmp    1167 <my_atoll+0x47>
mov    -0x14(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x15(%rbp)
je     1194 <my_atoll+0x74>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    11a4 <my_atoll+0x84>
jmp    11cd <my_atoll+0xad>
imul   $0xa,-0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
movsbl (%rcx),%ecx
sub    $0x30,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    1167 <my_atoll+0x47>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_atoll>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
nopl   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
call   1040 <isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1130 <my_atoll+0x10>
mov    $0xffffffffffffffff,%r15
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
movsbl (%rbx,%r15,1),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     117a <my_atoll+0x5a>
lea    (%r14,%r14,4),%rax
movsbq (%rbx,%r15,1),%rcx
lea    (%rcx,%rax,2),%r14
add    $0xffffffffffffffd0,%r14
add    $0x1,%r15
cmp    $0x1c,%r15d
jne    1150 <my_atoll+0x30>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @my_atoll(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
store i8* %0, i8** %2
store i64 0, i64* %3
store i32 30, i32* %4
br label %5
5: ; preds = %10, %1
%6 = load i8*, i8** %2
%7 = load i8, i8* %6
%8 = call i64 @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
br label %14
14: ; preds = %25, %13
%15 = load i32, i32* %4
%16 = add nsw i32 %15, -1
store i32 %16, i32* %4
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i8*, i8** %2
%20 = load i8, i8* %19
%21 = call i64 @isdigit(i8 signext %20)
%22 = icmp ne i64 %21, 0
br label %23
23: ; preds = %18, %14
%24 = phi i1 [ false, %14 ], [ %22, %18 ]
br i1 %24, label %25, label %35
25: ; preds = %23
%26 = load i64, i64* %3
%27 = mul nsw i64 %26, 10
%28 = load i8*, i8** %2
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %2
%30 = load i8, i8* %28
%31 = sext i8 %30 to i32
%32 = sub nsw i32 %31, 48
%33 = sext i32 %32 to i64
%34 = add nsw i64 %27, %33
store i64 %34, i64* %3
br label %14
35: ; preds = %23
%36 = load i64, i64* %3
ret i64 %36
}

LLVM IR (-O2):
define i64 @my_atoll(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 @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, %15
%9 = phi i32 [ %22, %15 ], [ 29, %2 ]
%10 = phi i64 [ %21, %15 ], [ 0, %2 ]
%11 = phi i8* [ %17, %15 ], [ %3, %2 ]
%12 = load i8, i8* %11
%13 = tail call i64 @isdigit(i8 signext %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %24, label %15
15: ; preds = %8
%16 = mul nsw i64 %10, 10
%17 = getelementptr inbounds i8, i8* %11, i64 1
%18 = load i8, i8* %11
%19 = sext i8 %18 to i64
%20 = add i64 %16, -48
%21 = add i64 %20, %19
%22 = add nsw i32 %9, -1
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %8
24: ; preds = %15, %8
%25 = phi i64 [ %21, %15 ], [ %10, %8 ]
ret i64 %25
}