#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__ ERANGE;
long long LLONG_MAX;
long long LLONG_MIN;
scalar_t__ errno;
int /*<<< orphan*/ snprintf(char *, size_t, char *, ...);
long long strtoll(char const *, char **, int);
void str_to_ll(const char *str, int base, long long *ll, char *err,
               size_t err_len) {
  long long zll;
  char *endptr;
  errno = 0;
  zll = strtoll(str, &endptr, base);
  if ((zll == LLONG_MIN) && (errno == ERANGE)) {
    snprintf(err, err_len, "underflow");
    return;
  }
  if ((zll == LLONG_MAX) && (errno == ERANGE)) {
    snprintf(err, err_len, "overflow");
    return;
  }
  if (str == endptr) {
    snprintf(err, err_len, "no digits found");
    return;
  }
  if (*endptr != '\0') {
    snprintf(err, err_len, "junk at end of string: %s", endptr);
    return;
  }
  *ll = zll;
}


x86 assembly (clang, -O0):
<str_to_ll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    0x2e86(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    -0x38(%rbp),%rsi
call   1040 <strtoll@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2e68(%rip),%rcx
cmp    (%rcx),%rax
jne    11a6 <str_to_ll+0x86>
mov    0x2e50(%rip),%rax
mov    (%rax),%rax
mov    0x2e66(%rip),%rcx
cmp    (%rcx),%rax
jne    11a6 <str_to_ll+0x86>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    0xe66(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    1252 <str_to_ll+0x132>
mov    -0x30(%rbp),%rax
mov    0x2e2f(%rip),%rcx
cmp    (%rcx),%rax
jne    11ef <str_to_ll+0xcf>
mov    0x2e07(%rip),%rax
mov    (%rax),%rax
mov    0x2e1d(%rip),%rcx
cmp    (%rcx),%rax
jne    11ef <str_to_ll+0xcf>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    0xe27(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    1252 <str_to_ll+0x132>
mov    -0x8(%rbp),%rax
cmp    -0x38(%rbp),%rax
jne    1218 <str_to_ll+0xf8>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    0xe07(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    1252 <str_to_ll+0x132>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1247 <str_to_ll+0x127>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rcx
lea    0xde8(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    1252 <str_to_ll+0x132>
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_to_ll>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8,%r14
mov    %rcx,%r12
mov    %rdx,%r15
mov    %esi,%edx
mov    %rdi,%rbx
mov    0x2e86(%rip),%r13
movq   $0x0,0x0(%r13)
lea    0x8(%rsp),%rsi
call   1040 <strtoll@plt>
mov    0x2e75(%rip),%rcx
cmp    (%rcx),%rax
jne    1179 <str_to_ll+0x59>
mov    0x0(%r13),%rcx
mov    0x2e7d(%rip),%rdx
cmp    (%rdx),%rcx
jne    1179 <str_to_ll+0x59>
lea    0xe89(%rip),%rdx
jmp    11d5 <str_to_ll+0xb5>
mov    0x2e60(%rip),%rcx
cmp    (%rcx),%rax
jne    119e <str_to_ll+0x7e>
mov    0x0(%r13),%rcx
mov    0x2e58(%rip),%rdx
cmp    (%rdx),%rcx
jne    119e <str_to_ll+0x7e>
lea    0xe6e(%rip),%rdx
jmp    11d5 <str_to_ll+0xb5>
mov    0x8(%rsp),%rcx
cmp    %rbx,%rcx
je     11ce <str_to_ll+0xae>
cmpb   $0x0,(%rcx)
je     11ef <str_to_ll+0xcf>
lea    0xe6f(%rip),%rdx
mov    %r12,%rdi
mov    %r14,%rsi
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <snprintf@plt>
lea    0xe3e(%rip),%rdx
mov    %r12,%rdi
mov    %r14,%rsi
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <snprintf@plt>
mov    %rax,(%r15)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@LLONG_MIN = global i64 0
@ERANGE = global i64 0
@.str = [10 x i8] c"underflow\00"
@LLONG_MAX = global i64 0
@.str.1 = [9 x i8] c"overflow\00"
@.str.2 = [16 x i8] c"no digits found\00"
@.str.3 = [26 x i8] c"junk at end of string: %s\00"
define void @str_to_ll(i8* %0, i32 %1, i64* %2, i8* %3, i64 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i64* %2, i64** %8
store i8* %3, i8** %9
store i64 %4, i64* %10
store i64 0, i64* @errno
%13 = load i8*, i8** %6
%14 = load i32, i32* %7
%15 = call i64 @strtoll(i8* %13, i8** %12, i32 %14)
store i64 %15, i64* %11
%16 = load i64, i64* %11
%17 = load i64, i64* @LLONG_MIN
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %27
19: ; preds = %5
%20 = load i64, i64* @errno
%21 = load i64, i64* @ERANGE
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i8*, i8** %9
%25 = load i64, i64* %10
%26 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %24, i64 %25, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %60
27: ; preds = %19, %5
%28 = load i64, i64* %11
%29 = load i64, i64* @LLONG_MAX
%30 = icmp eq i64 %28, %29
br i1 %30, label %31, label %39
31: ; preds = %27
%32 = load i64, i64* @errno
%33 = load i64, i64* @ERANGE
%34 = icmp eq i64 %32, %33
br i1 %34, label %35, label %39
35: ; preds = %31
%36 = load i8*, i8** %9
%37 = load i64, i64* %10
%38 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %36, i64 %37, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %60
39: ; preds = %31, %27
%40 = load i8*, i8** %6
%41 = load i8*, i8** %12
%42 = icmp eq i8* %40, %41
br i1 %42, label %43, label %47
43: ; preds = %39
%44 = load i8*, i8** %9
%45 = load i64, i64* %10
%46 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %44, i64 %45, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %60
47: ; preds = %39
%48 = load i8*, i8** %12
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %57
52: ; preds = %47
%53 = load i8*, i8** %9
%54 = load i64, i64* %10
%55 = load i8*, i8** %12
%56 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %53, i64 %54, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %55)
br label %60
57: ; preds = %47
%58 = load i64, i64* %11
%59 = load i64*, i64** %8
store i64 %58, i64* %59
br label %60
60: ; preds = %57, %52, %43, %35, %23
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@LLONG_MIN = global i64 0
@ERANGE = global i64 0
@.str = [10 x i8] c"underflow\00"
@LLONG_MAX = global i64 0
@.str.1 = [9 x i8] c"overflow\00"
@.str.2 = [16 x i8] c"no digits found\00"
@.str.3 = [26 x i8] c"junk at end of string: %s\00"
define void @str_to_ll(i8* %0, i32 %1, i64* nocapture writeonly %2, i8* nocapture writeonly %3, i64 %4) {
%6 = alloca i8*
%7 = bitcast i8** %6 to i8*
store i64 0, i64* @errno
%8 = call i64 @strtoll(i8* %0, i8** %6, i32 %1)
%9 = load i64, i64* @LLONG_MIN
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %17
11: ; preds = %5
%12 = load i64, i64* @errno
%13 = load i64, i64* @ERANGE
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %3, i64 %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %37
17: ; preds = %11, %5
%18 = load i64, i64* @LLONG_MAX
%19 = icmp eq i64 %8, %18
br i1 %19, label %20, label %26
20: ; preds = %17
%21 = load i64, i64* @errno
%22 = load i64, i64* @ERANGE
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %3, i64 %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %37
26: ; preds = %20, %17
%27 = load i8*, i8** %6
%28 = icmp eq i8* %27, %0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %3, i64 %4, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %37
31: ; preds = %26
%32 = load i8, i8* %27
%33 = icmp eq i8 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %31
%35 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %3, i64 %4, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %27)
br label %37
36: ; preds = %31
store i64 %8, i64* %2
br label %37
37: ; preds = %36, %34, %29, %24, %15
ret void
}