#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*/ wchar_t;
typedef scalar_t__ intmax_t;

/* Variables and functions */
int /*<<< orphan*/ ERANGE;
scalar_t__ LLONG_MAX;
scalar_t__ LLONG_MIN;
int /*<<< orphan*/ errno;
scalar_t__ wcstoimax(int /*<<< orphan*/ const *, int /*<<< orphan*/ **, int);
long long wcstoll(const wchar_t *s, wchar_t **p, int base) {
  intmax_t x = wcstoimax(s, p, base);
  if (x > LLONG_MAX) {
    errno = ERANGE;
    return LLONG_MAX;
  } else if (x < LLONG_MIN) {
    errno = ERANGE;
    return LLONG_MIN;
  }
  return x;
}


x86 assembly (clang, -O0):
<wcstoll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <wcstoimax@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2e9e(%rip),%rcx
cmp    (%rcx),%rax
jle    1170 <wcstoll+0x60>
mov    0x2e96(%rip),%rax
mov    (%rax),%ecx
mov    0x2e6d(%rip),%rax
mov    %ecx,(%rax)
mov    0x2e7c(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11b6 <wcstoll+0xa6>
mov    -0x28(%rbp),%rax
mov    0x2e55(%rip),%rcx
cmp    (%rcx),%rax
jge    11a9 <wcstoll+0x99>
mov    0x2e5d(%rip),%rax
mov    (%rax),%ecx
mov    0x2e34(%rip),%rax
mov    %ecx,(%rax)
mov    0x2e33(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11b6 <wcstoll+0xa6>
jmp    11ae <wcstoll+0x9e>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcstoll>:
push   %rax
call   1030 <wcstoimax@plt>
mov    0x2ec3(%rip),%rcx
mov    (%rcx),%rcx
cmp    %rcx,%rax
jg     1134 <wcstoll+0x24>
mov    0x2ea4(%rip),%rcx
mov    (%rcx),%rcx
cmp    %rcx,%rax
jge    1149 <wcstoll+0x39>
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
mov    0x2e84(%rip),%rdx
mov    %eax,(%rdx)
mov    %rcx,%rax
pop    %rcx
ret

LLVM IR (-O0):
@LLONG_MAX = global i64 0
@ERANGE = global i32 0
@errno = global i32 0
@LLONG_MIN = global i64 0
define i64 @wcstoll(i32* %0, i32** %1, i32 %2) {
%4 = alloca i64
%5 = alloca i32*
%6 = alloca i32**
%7 = alloca i32
%8 = alloca i64
store i32* %0, i32** %5
store i32** %1, i32*** %6
store i32 %2, i32* %7
%9 = load i32*, i32** %5
%10 = load i32**, i32*** %6
%11 = load i32, i32* %7
%12 = call i64 @wcstoimax(i32* %9, i32** %10, i32 %11)
store i64 %12, i64* %8
%13 = load i64, i64* %8
%14 = load i64, i64* @LLONG_MAX
%15 = icmp sgt i64 %13, %14
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = load i32, i32* @ERANGE
store i32 %17, i32* @errno
%18 = load i64, i64* @LLONG_MAX
store i64 %18, i64* %4
br label %29
19: ; preds = %3
%20 = load i64, i64* %8
%21 = load i64, i64* @LLONG_MIN
%22 = icmp slt i64 %20, %21
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i32, i32* @ERANGE
store i32 %24, i32* @errno
%25 = load i64, i64* @LLONG_MIN
store i64 %25, i64* %4
br label %29
26: ; preds = %19
br label %27
27: ; preds = %26
%28 = load i64, i64* %8
store i64 %28, i64* %4
br label %29
29: ; preds = %27, %23, %16
%30 = load i64, i64* %4
ret i64 %30
}

LLVM IR (-O2):
@LLONG_MAX = global i64 0
@ERANGE = global i32 0
@errno = global i32 0
@LLONG_MIN = global i64 0
define i64 @wcstoll(i32* %0, i32** %1, i32 %2) {
%4 = tail call i64 @wcstoimax(i32* %0, i32** %1, i32 %2)
%5 = load i64, i64* @LLONG_MAX
%6 = icmp sgt i64 %4, %5
br i1 %6, label %10, label %7
7: ; preds = %3
%8 = load i64, i64* @LLONG_MIN
%9 = icmp slt i64 %4, %8
br i1 %9, label %10, label %13
10: ; preds = %7, %3
%11 = phi i64 [ %5, %3 ], [ %8, %7 ]
%12 = load i32, i32* @ERANGE
store i32 %12, i32* @errno
br label %13
13: ; preds = %10, %7
%14 = phi i64 [ %4, %7 ], [ %11, %10 ]
ret i64 %14
}