#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 */
typedef int /*<<< orphan*/ uintmax_t;

/* Variables and functions */
int LLONG_MAX;
int LLONG_MIN;
scalar_t__ _PDCLIB_strtox_main(char const **, unsigned int, int /*<<< orphan*/,
                               int /*<<< orphan*/, int, char *);
char *_PDCLIB_strtox_prelim(char const *, char *, int *);
long long int strtoll(const char *s, char **endptr, int base) {
  long long int rc;
  char sign = '+';
  const char *p = _PDCLIB_strtox_prelim(s, &sign, &base);
  if (base < 2 || base > 36)
    return 0;
  if (sign == '+') {
    rc = (long long int)_PDCLIB_strtox_main(
        &p, (unsigned)base, (uintmax_t)LLONG_MAX, (uintmax_t)(LLONG_MAX / base),
        (int)(LLONG_MAX % base), &sign);
  } else {
    rc = (long long int)_PDCLIB_strtox_main(
        &p, (unsigned)base, (uintmax_t)LLONG_MIN,
        (uintmax_t)(LLONG_MIN / -base), (int)(-(LLONG_MIN % base)), &sign);
  }
  if (endptr != NULL)
    *endptr = (p != NULL) ? (char *)p : (char *)s;
  return (sign == '+') ? rc : -rc;
}


x86 assembly (clang, -O0):
<strtoll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movb   $0x2b,-0x29(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x29(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1030 <_PDCLIB_strtox_prelim@plt>
mov    %rax,-0x38(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jl     1160 <strtoll+0x40>
cmpl   $0x24,-0x1c(%rbp)
jle    116d <strtoll+0x4d>
movq   $0x0,-0x8(%rbp)
jmp    126e <strtoll+0x14e>
movsbl -0x29(%rbp),%eax
cmp    $0x2b,%eax
jne    11c1 <strtoll+0xa1>
mov    -0x1c(%rbp),%esi
mov    0x2e64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2e58(%rip),%rax
mov    (%rax),%eax
cltd
idivl  -0x1c(%rbp)
mov    %eax,%ecx
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
cltd
idivl  -0x1c(%rbp)
mov    %edx,%r8d
mov    -0x3c(%rbp),%edx
lea    -0x38(%rbp),%rdi
lea    -0x29(%rbp),%r9
call   1040 <_PDCLIB_strtox_main@plt>
mov    %rax,-0x28(%rbp)
jmp    120c <strtoll+0xec>
mov    -0x1c(%rbp),%esi
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2e01(%rip),%rax
mov    (%rax),%eax
xor    %ecx,%ecx
sub    -0x1c(%rbp),%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    0x2dee(%rip),%rax
mov    (%rax),%eax
cltd
idivl  -0x1c(%rbp)
mov    %edx,%eax
mov    -0x40(%rbp),%edx
xor    %r8d,%r8d
sub    %eax,%r8d
lea    -0x38(%rbp),%rdi
lea    -0x29(%rbp),%r9
call   1040 <_PDCLIB_strtox_main@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1242 <strtoll+0x122>
cmpq   $0x0,-0x38(%rbp)
je     122f <strtoll+0x10f>
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    1237 <strtoll+0x117>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movsbl -0x29(%rbp),%eax
cmp    $0x2b,%eax
jne    125c <strtoll+0x13c>
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    1266 <strtoll+0x146>
xor    %eax,%eax
sub    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtoll>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %edx,0xc(%rsp)
movb   $0x2b,0xb(%rsp)
lea    0xb(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1030 <_PDCLIB_strtox_prelim@plt>
mov    %rax,0x10(%rsp)
mov    0xc(%rsp),%esi
lea    -0x25(%rsi),%eax
cmp    $0xffffffdd,%eax
jae    115d <strtoll+0x3d>
xor    %ecx,%ecx
jmp    11dd <strtoll+0xbd>
cmpb   $0x2b,0xb(%rsp)
jne    1185 <strtoll+0x65>
mov    0x2e7d(%rip),%rax
mov    (%rax),%ecx
mov    %ecx,%eax
cltd
idiv   %esi
mov    %edx,%r8d
lea    0x10(%rsp),%rdi
lea    0xb(%rsp),%r9
mov    %ecx,%edx
mov    %eax,%ecx
jmp    11b5 <strtoll+0x95>
mov    0x2e4c(%rip),%rax
mov    (%rax),%ecx
mov    %esi,%edi
neg    %edi
mov    %ecx,%eax
cltd
idiv   %edi
mov    %eax,%r8d
mov    %ecx,%eax
cltd
idiv   %esi
mov    %edx,%eax
neg    %eax
lea    0x10(%rsp),%rdi
lea    0xb(%rsp),%r9
mov    %ecx,%edx
mov    %r8d,%ecx
mov    %eax,%r8d
call   1040 <_PDCLIB_strtox_main@plt>
test   %r14,%r14
je     11ce <strtoll+0xae>
mov    0x10(%rsp),%rcx
test   %rcx,%rcx
cmovne %rcx,%rbx
mov    %rbx,(%r14)
mov    %rax,%rcx
neg    %rcx
cmpb   $0x2b,0xb(%rsp)
cmove  %rax,%rcx
mov    %rcx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@LLONG_MAX = global i32 0
@LLONG_MIN = global i32 0
define i64 @strtoll(i8* %0, i8** %1, i32 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i64
%9 = alloca i8
%10 = alloca i8*
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
store i8 43, i8* %9
%11 = load i8*, i8** %5
%12 = call i8* @_PDCLIB_strtox_prelim(i8* %11, i8* %9, i32* %7)
store i8* %12, i8** %10
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 2
br i1 %14, label %18, label %15
15: ; preds = %3
%16 = load i32, i32* %7
%17 = icmp sgt i32 %16, 36
br i1 %17, label %18, label %19
18: ; preds = %15, %3
store i64 0, i64* %4
br label %69
19: ; preds = %15
%20 = load i8, i8* %9
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 43
br i1 %22, label %23, label %33
23: ; preds = %19
%24 = load i32, i32* %7
%25 = load i32, i32* @LLONG_MAX
%26 = load i32, i32* @LLONG_MAX
%27 = load i32, i32* %7
%28 = sdiv i32 %26, %27
%29 = load i32, i32* @LLONG_MAX
%30 = load i32, i32* %7
%31 = srem i32 %29, %30
%32 = call i64 @_PDCLIB_strtox_main(i8** %10, i32 %24, i32 %25, i32 %28, i32 %31, i8* %9)
store i64 %32, i64* %8
br label %45
33: ; preds = %19
%34 = load i32, i32* %7
%35 = load i32, i32* @LLONG_MIN
%36 = load i32, i32* @LLONG_MIN
%37 = load i32, i32* %7
%38 = sub nsw i32 0, %37
%39 = sdiv i32 %36, %38
%40 = load i32, i32* @LLONG_MIN
%41 = load i32, i32* %7
%42 = srem i32 %40, %41
%43 = sub nsw i32 0, %42
%44 = call i64 @_PDCLIB_strtox_main(i8** %10, i32 %34, i32 %35, i32 %39, i32 %43, i8* %9)
store i64 %44, i64* %8
br label %45
45: ; preds = %33, %23
%46 = load i8**, i8*** %6
%47 = icmp ne i8** %46, null
br i1 %47, label %48, label %58
48: ; preds = %45
%49 = load i8*, i8** %10
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %53
51: ; preds = %48
%52 = load i8*, i8** %10
br label %55
53: ; preds = %48
%54 = load i8*, i8** %5
br label %55
55: ; preds = %53, %51
%56 = phi i8* [ %52, %51 ], [ %54, %53 ]
%57 = load i8**, i8*** %6
store i8* %56, i8** %57
br label %58
58: ; preds = %55, %45
%59 = load i8, i8* %9
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 43
br i1 %61, label %62, label %64
62: ; preds = %58
%63 = load i64, i64* %8
br label %67
64: ; preds = %58
%65 = load i64, i64* %8
%66 = sub nsw i64 0, %65
br label %67
67: ; preds = %64, %62
%68 = phi i64 [ %63, %62 ], [ %66, %64 ]
store i64 %68, i64* %4
br label %69
69: ; preds = %67, %18
%70 = load i64, i64* %4
ret i64 %70
}

LLVM IR (-O2):
@LLONG_MAX = global i32 0
@LLONG_MIN = global i32 0
define i64 @strtoll(i8* %0, i8** writeonly %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8*
store i32 %2, i32* %4
store i8 43, i8* %5
%7 = bitcast i8** %6 to i8*
%8 = call i8* @_PDCLIB_strtox_prelim(i8* %0, i8* %5, i32* %4)
store i8* %8, i8** %6
%9 = load i32, i32* %4
%10 = add i32 %9, -37
%11 = icmp ult i32 %10, -35
br i1 %11, label %39, label %12
12: ; preds = %3
%13 = load i8, i8* %5
%14 = icmp eq i8 %13, 43
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i32, i32* @LLONG_MAX
%17 = sdiv i32 %16, %9
%18 = srem i32 %16, %9
%19 = call i64 @_PDCLIB_strtox_main(i8** %6, i32 %9, i32 %16, i32 %17, i32 %18, i8* %5)
br label %27
20: ; preds = %12
%21 = load i32, i32* @LLONG_MIN
%22 = sub nsw i32 0, %9
%23 = sdiv i32 %21, %22
%24 = srem i32 %21, %9
%25 = sub nsw i32 0, %24
%26 = call i64 @_PDCLIB_strtox_main(i8** %6, i32 %9, i32 %21, i32 %23, i32 %25, i8* %5)
br label %27
27: ; preds = %20, %15
%28 = phi i64 [ %19, %15 ], [ %26, %20 ]
%29 = icmp eq i8** %1, null
br i1 %29, label %34, label %30
30: ; preds = %27
%31 = load i8*, i8** %6
%32 = icmp eq i8* %31, null
%33 = select i1 %32, i8* %0, i8* %31
store i8* %33, i8** %1
br label %34
34: ; preds = %30, %27
%35 = load i8, i8* %5
%36 = icmp eq i8 %35, 43
%37 = sub nsw i64 0, %28
%38 = select i1 %36, i64 %28, i64 %37
br label %39
39: ; preds = %3, %34
%40 = phi i64 [ %38, %34 ], [ 0, %3 ]
ret i64 %40
}