#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 atoll(const char *str) {
  long long num = 0;
  int neg = 0;
  while (isspace(*str))
    str++;
  if (*str == '-') {
    neg = 1;
    str++;
  }
  while (isdigit(*str)) {
    num = 10 * num + (*str - '0');
    str++;
  }
  if (neg)
    num = -num;
  return num;
}


x86 assembly (clang, -O0):
<atoll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     1162 <atoll+0x42>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    113b <atoll+0x1b>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1185 <atoll+0x65>
movl   $0x1,-0x14(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    118a <atoll+0x6a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11ca <atoll+0xaa>
imul   $0xa,-0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
movsbl (%rcx),%ecx
sub    $0x30,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    118a <atoll+0x6a>
cmpl   $0x0,-0x14(%rbp)
je     11de <atoll+0xbe>
xor    %eax,%eax
sub    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atoll>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
nopw   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
call   1040 <isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1130 <atoll+0x10>
mov    -0x1(%rbx),%r14b
xor    %ebp,%ebp
cmp    $0x2d,%r14b
sete   %bpl
movsbl -0x1(%rbx,%rbp,1),%edi
call   1030 <isdigit@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     1194 <atoll+0x74>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%r15,%r15,4),%rax
movsbq -0x1(%rbx,%rbp,1),%rcx
lea    (%rcx,%rax,2),%r15
add    $0xffffffffffffffd0,%r15
movsbl (%rbx,%rbp,1),%edi
call   1030 <isdigit@plt>
add    $0x1,%rbp
test   %rax,%rax
jne    1170 <atoll+0x50>
mov    %r15,%rax
neg    %rax
cmp    $0x2d,%r14b
cmovne %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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