#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*/ EINVAL;
int /*<<< orphan*/ ERANGE;
long long LLONG_MAX;
long long LLONG_MIN;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ errno;
long long strtoll(char const *, char **, int);
bool strict_strtoll(const char *str, int base, long long *result) {
  char *end;
  assert(base == 0 || (base >= 2 && base <= 36));
  *result = strtoll(str, &end, base);
  if ((*result == LLONG_MIN || *result == LLONG_MAX) && errno == ERANGE)
    return false;
  if (end == str || *end) {
    errno = -EINVAL;
    return false;
  }
  return true;
}


x86 assembly (clang, -O0):
<strict_strtoll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    $0x1,%al
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x29(%rbp)
je     1161 <strict_strtoll+0x41>
xor    %eax,%eax
cmpl   $0x2,-0x14(%rbp)
mov    %al,-0x2a(%rbp)
jl     115b <strict_strtoll+0x3b>
cmpl   $0x24,-0x14(%rbp)
setle  %al
mov    %al,-0x2a(%rbp)
mov    -0x2a(%rbp),%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    -0x28(%rbp),%rsi
call   1030 <strtoll@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x2e3a(%rip),%rcx
cmp    (%rcx),%rax
je     11b6 <strict_strtoll+0x96>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x2e33(%rip),%rcx
cmp    (%rcx),%rax
jne    11da <strict_strtoll+0xba>
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    0x2e22(%rip),%rcx
cmp    (%rcx),%eax
jne    11da <strict_strtoll+0xba>
movl   $0x0,-0x4(%rbp)
jmp    121f <strict_strtoll+0xff>
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11f8 <strict_strtoll+0xd8>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1218 <strict_strtoll+0xf8>
xor    %ecx,%ecx
mov    0x2dbf(%rip),%rax
sub    (%rax),%ecx
mov    0x2dbe(%rip),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    121f <strict_strtoll+0xff>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strict_strtoll>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %esi,%ebx
mov    %rdi,%r14
test   %esi,%esi
sete   %al
lea    -0x2(%rbx),%ecx
cmp    $0x23,%ecx
setb   %cl
or     %al,%cl
movzbl %cl,%edi
call   1040 <assert@plt>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
call   1030 <strtoll@plt>
mov    %rax,(%r15)
mov    0x2e6e(%rip),%rcx
cmp    (%rcx),%rax
je     1173 <strict_strtoll+0x53>
mov    0x2e72(%rip),%rcx
cmp    (%rcx),%rax
jne    1189 <strict_strtoll+0x69>
mov    0x2e4e(%rip),%rax
mov    (%rax),%ecx
mov    0x2e65(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%ecx
je     11b5 <strict_strtoll+0x95>
mov    0x8(%rsp),%rax
cmp    %r14,%rax
je     1198 <strict_strtoll+0x78>
cmpb   $0x0,(%rax)
je     11b0 <strict_strtoll+0x90>
mov    0x2e21(%rip),%rcx
xor    %eax,%eax
xor    %edx,%edx
sub    (%rcx),%edx
mov    0x2e1c(%rip),%rcx
mov    %edx,(%rcx)
jmp    11b5 <strict_strtoll+0x95>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@LLONG_MIN = global i64 0
@LLONG_MAX = global i64 0
@errno = global i32 0
@ERANGE = global i32 0
@EINVAL = global i32 0
define i32 @strict_strtoll(i8* %0, i32 %1, i64* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64*
%8 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i64* %2, i64** %7
%9 = load i32, i32* %6
%10 = icmp eq i32 %9, 0
br i1 %10, label %19, label %11
11: ; preds = %3
%12 = load i32, i32* %6
%13 = icmp sge i32 %12, 2
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* %6
%16 = icmp sle i32 %15, 36
br label %17
17: ; preds = %14, %11
%18 = phi i1 [ false, %11 ], [ %16, %14 ]
br label %19
19: ; preds = %17, %3
%20 = phi i1 [ true, %3 ], [ %18, %17 ]
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i8*, i8** %5
%24 = load i32, i32* %6
%25 = call i64 @strtoll(i8* %23, i8** %8, i32 %24)
%26 = load i64*, i64** %7
store i64 %25, i64* %26
%27 = load i64*, i64** %7
%28 = load i64, i64* %27
%29 = load i64, i64* @LLONG_MIN
%30 = icmp eq i64 %28, %29
br i1 %30, label %36, label %31
31: ; preds = %19
%32 = load i64*, i64** %7
%33 = load i64, i64* %32
%34 = load i64, i64* @LLONG_MAX
%35 = icmp eq i64 %33, %34
br i1 %35, label %36, label %41
36: ; preds = %31, %19
%37 = load i32, i32* @errno
%38 = load i32, i32* @ERANGE
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %41
40: ; preds = %36
store i32 0, i32* %4
br label %54
41: ; preds = %36, %31
%42 = load i8*, i8** %8
%43 = load i8*, i8** %5
%44 = icmp eq i8* %42, %43
br i1 %44, label %50, label %45
45: ; preds = %41
%46 = load i8*, i8** %8
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %45, %41
%51 = load i32, i32* @EINVAL
%52 = sub nsw i32 0, %51
store i32 %52, i32* @errno
store i32 0, i32* %4
br label %54
53: ; preds = %45
store i32 1, i32* %4
br label %54
54: ; preds = %53, %50, %40
%55 = load i32, i32* %4
ret i32 %55
}

LLVM IR (-O2):
@LLONG_MIN = global i64 0
@LLONG_MAX = global i64 0
@errno = global i32 0
@ERANGE = global i32 0
@EINVAL = global i32 0
define i32 @strict_strtoll(i8* %0, i32 %1, i64* nocapture writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = icmp eq i32 %1, 0
%7 = add i32 %1, -2
%8 = icmp ult i32 %7, 35
%9 = or i1 %6, %8
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = call i64 @strtoll(i8* %0, i8** %4, i32 %1)
store i64 %12, i64* %2
%13 = load i64, i64* @LLONG_MIN
%14 = icmp eq i64 %12, %13
%15 = load i64, i64* @LLONG_MAX
%16 = icmp eq i64 %12, %15
%17 = select i1 %14, i1 true, i1 %16
br i1 %17, label %18, label %22
18: ; preds = %3
%19 = load i32, i32* @errno
%20 = load i32, i32* @ERANGE
%21 = icmp eq i32 %19, %20
br i1 %21, label %31, label %22
22: ; preds = %3, %18
%23 = load i8*, i8** %4
%24 = icmp eq i8* %23, %0
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load i8, i8* %23
%27 = icmp eq i8 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %25, %22
%29 = load i32, i32* @EINVAL
%30 = sub nsw i32 0, %29
store i32 %30, i32* @errno
br label %31
31: ; preds = %25, %18, %28
%32 = phi i32 [ 0, %28 ], [ 0, %18 ], [ 1, %25 ]
ret i32 %32
}