#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 */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
long long my_atoll(const char *str) {
  if (str == NULL) {
    printf("error: the argument of my_atoi is NULL!\n");
    exit(0);
  }
  long long res = 0;
  char sign = '+';
  const char *pStr = str;
  while (*pStr == ' ')
    pStr++;
  if (*pStr == '+' || *pStr == '-')
    sign = *pStr++;
  while (*pStr >= '0' && *pStr <= '9') {
    res = res * 10 + *pStr - '0';
    pStr++;
  }
  return sign == '-' ? -res : res;
}


x86 assembly (clang, -O0):
<my_atoll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    114a <my_atoll+0x2a>
lea    0xec2(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <exit@plt>
movq   $0x0,-0x10(%rbp)
movb   $0x2b,-0x11(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    117f <my_atoll+0x5f>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    115e <my_atoll+0x3e>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
je     119f <my_atoll+0x7f>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11b3 <my_atoll+0x93>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%al
mov    %al,-0x11(%rbp)
jmp    11b8 <my_atoll+0x98>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x21(%rbp)
jl     11dd <my_atoll+0xbd>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
setle  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11ed <my_atoll+0xcd>
jmp    1216 <my_atoll+0xf6>
imul   $0xa,-0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbq (%rcx),%rcx
add    %rcx,%rax
sub    $0x30,%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11b8 <my_atoll+0x98>
movsbl -0x11(%rbp),%eax
cmp    $0x2d,%eax
jne    1232 <my_atoll+0x112>
xor    %eax,%eax
sub    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    123a <my_atoll+0x11a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_atoll>:
push   %rax
test   %rdi,%rdi
je     11a2 <my_atoll+0x82>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rdi
movzbl -0x1(%rdi),%ecx
cmp    $0x20,%ecx
je     1130 <my_atoll+0x10>
cmp    $0x2b,%cl
je     1147 <my_atoll+0x27>
cmp    $0x2d,%cl
jne    114b <my_atoll+0x2b>
mov    (%rdi),%al
jmp    1156 <my_atoll+0x36>
add    $0xffffffffffffffff,%rdi
mov    %ecx,%eax
mov    $0x2b,%ecx
lea    -0x30(%rax),%edx
cmp    $0x9,%dl
ja     1191 <my_atoll+0x71>
add    $0x1,%rdi
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%rdx,%rdx,4),%rdx
movzbl %al,%eax
lea    (%rax,%rdx,2),%rdx
add    $0xffffffffffffffd0,%rdx
movzbl (%rdi),%eax
lea    -0x30(%rax),%esi
add    $0x1,%rdi
cmp    $0xa,%sil
jb     1170 <my_atoll+0x50>
jmp    1193 <my_atoll+0x73>
xor    %edx,%edx
mov    %rdx,%rax
neg    %rax
cmp    $0x2d,%ecx
cmovne %rdx,%rax
pop    %rcx
ret
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [41 x i8] c"error: the argument of my_atoi is NULL!\0A\00"
define i64 @my_atoll(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 0)
unreachable
11: ; preds = %1
store i64 0, i64* %3
store i8 43, i8* %4
%12 = load i8*, i8** %2
store i8* %12, i8** %5
br label %13
13: ; preds = %18, %11
%14 = load i8*, i8** %5
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 32
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %5
br label %13
21: ; preds = %13
%22 = load i8*, i8** %5
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 43
br i1 %25, label %31, label %26
26: ; preds = %21
%27 = load i8*, i8** %5
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 45
br i1 %30, label %31, label %35
31: ; preds = %26, %21
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %5
%34 = load i8, i8* %32
store i8 %34, i8* %4
br label %35
35: ; preds = %31, %26
br label %36
36: ; preds = %48, %35
%37 = load i8*, i8** %5
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp sge i32 %39, 48
br i1 %40, label %41, label %46
41: ; preds = %36
%42 = load i8*, i8** %5
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp sle i32 %44, 57
br label %46
46: ; preds = %41, %36
%47 = phi i1 [ false, %36 ], [ %45, %41 ]
br i1 %47, label %48, label %58
48: ; preds = %46
%49 = load i64, i64* %3
%50 = mul nsw i64 %49, 10
%51 = load i8*, i8** %5
%52 = load i8, i8* %51
%53 = sext i8 %52 to i64
%54 = add nsw i64 %50, %53
%55 = sub nsw i64 %54, 48
store i64 %55, i64* %3
%56 = load i8*, i8** %5
%57 = getelementptr inbounds i8, i8* %56, i32 1
store i8* %57, i8** %5
br label %36
58: ; preds = %46
%59 = load i8, i8* %4
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 45
br i1 %61, label %62, label %65
62: ; preds = %58
%63 = load i64, i64* %3
%64 = sub nsw i64 0, %63
br label %67
65: ; preds = %58
%66 = load i64, i64* %3
br label %67
67: ; preds = %65, %62
%68 = phi i64 [ %64, %62 ], [ %66, %65 ]
ret i64 %68
}

LLVM IR (-O2):
@str = [40 x i8] c"error: the argument of my_atoi is NULL!\00"
define i64 @my_atoll(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @exit(i32 0)
unreachable
6: ; preds = %1, %9
%7 = phi i8* [ %10, %9 ], [ %0, %1 ]
%8 = load i8, i8* %7
switch i8 %8, label %15 [
i8 32, label %9
i8 43, label %11
i8 45, label %11
]
9: ; preds = %6
%10 = getelementptr inbounds i8, i8* %7, i64 1
br label %6
11: ; preds = %6, %6
%12 = getelementptr inbounds i8, i8* %7, i64 1
%13 = zext i8 %8 to i32
%14 = load i8, i8* %12
br label %15
15: ; preds = %6, %11
%16 = phi i8 [ %14, %11 ], [ %8, %6 ]
%17 = phi i32 [ %13, %11 ], [ 43, %6 ]
%18 = phi i8* [ %12, %11 ], [ %7, %6 ]
%19 = add i8 %16, -48
%20 = icmp ult i8 %19, 10
br i1 %20, label %21, label %33
21: ; preds = %15, %21
%22 = phi i8 [ %30, %21 ], [ %16, %15 ]
%23 = phi i8* [ %29, %21 ], [ %18, %15 ]
%24 = phi i64 [ %28, %21 ], [ 0, %15 ]
%25 = mul nsw i64 %24, 10
%26 = zext i8 %22 to i64
%27 = add i64 %25, -48
%28 = add i64 %27, %26
%29 = getelementptr inbounds i8, i8* %23, i64 1
%30 = load i8, i8* %29
%31 = add i8 %30, -48
%32 = icmp ult i8 %31, 10
br i1 %32, label %21, label %33
33: ; preds = %21, %15
%34 = phi i64 [ 0, %15 ], [ %28, %21 ]
%35 = icmp eq i32 %17, 45
%36 = sub nsw i64 0, %34
%37 = select i1 %35, i64 %36, i64 %34
ret i64 %37
}