#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;
int /*<<< orphan*/ EXIT_FAILURE;
long LONG_MAX;
long LONG_MIN;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
long strtol(char const *, char **, int);
long parseShiftValue(const char *shiftAmount) {
  char *endptr;
  errno = 0;
  long shiftValue = strtol(shiftAmount, &endptr, 10);
  if ((errno == ERANGE && (shiftValue == LONG_MAX || shiftValue == LONG_MIN)) ||
      (errno != 0 && shiftValue == 0)) {
    perror("Error (strtol)");
    exit(EXIT_FAILURE);
  }
  if (endptr == shiftAmount) {
    fprintf(stderr,
            "Error (strtol): No digits were found in the shift value\n");
    exit(EXIT_FAILURE);
  }
  if (*endptr != '\0') {
    fprintf(stderr,
            "Error (strtol): The non-numerical character(s) \"%s\" were "
            "detected after shift value\n",
            endptr);
    exit(EXIT_FAILURE);
  }
  return shiftValue;
}


x86 assembly (clang, -O0):
<parseShiftValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e6d(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e49(%rip),%rax
mov    (%rax),%rax
mov    0x2e5f(%rip),%rcx
cmp    (%rcx),%rax
jne    11b2 <parseShiftValue+0x72>
mov    -0x18(%rbp),%rax
mov    0x2e33(%rip),%rcx
cmp    (%rcx),%rax
je     11ce <parseShiftValue+0x8e>
mov    -0x18(%rbp),%rax
mov    0x2e3f(%rip),%rcx
cmp    (%rcx),%rax
je     11ce <parseShiftValue+0x8e>
mov    0x2e07(%rip),%rax
cmpq   $0x0,(%rax)
je     11e8 <parseShiftValue+0xa8>
cmpq   $0x0,-0x18(%rbp)
jne    11e8 <parseShiftValue+0xa8>
lea    0xe2b(%rip),%rdi
call   1050 <perror@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    121b <parseShiftValue+0xdb>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    0xe09(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1254 <parseShiftValue+0x114>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe09(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseShiftValue>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e72(%rip),%r14
movq   $0x0,(%r14)
mov    %rsp,%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    (%r14),%rcx
mov    0x2e74(%rip),%rdx
cmp    (%rdx),%rcx
jne    1189 <parseShiftValue+0x49>
mov    0x2e50(%rip),%rdx
cmp    (%rdx),%rax
je     11a9 <parseShiftValue+0x69>
mov    0x2e64(%rip),%rdx
cmp    (%rdx),%rax
je     11a9 <parseShiftValue+0x69>
test   %rcx,%rcx
je     1193 <parseShiftValue+0x53>
test   %rax,%rax
je     11a9 <parseShiftValue+0x69>
mov    (%rsp),%rdx
cmp    %rbx,%rdx
je     11b7 <parseShiftValue+0x77>
cmpb   $0x0,(%rdx)
jne    11d0 <parseShiftValue+0x90>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe50(%rip),%rdi
call   1050 <perror@plt>
jmp    11e7 <parseShiftValue+0xa7>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11e7 <parseShiftValue+0xa7>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@ERANGE = global i64 0
@LONG_MAX = global i64 0
@LONG_MIN = global i64 0
@.str = [15 x i8] c"Error (strtol)\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [57 x i8] c"Error (strtol): No digits were found in the shift value\0A\00"
@.str.2 = [85 x i8] c"Error (strtol): The non-numerical character(s) \22%s\22 were detected after shift value\0A\00"
define i64 @parseShiftValue(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %2
store i64 0, i64* @errno
%5 = load i8*, i8** %2
%6 = call i64 @strtol(i8* %5, i8** %3, i32 10)
store i64 %6, i64* %4
%7 = load i64, i64* @errno
%8 = load i64, i64* @ERANGE
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %18
10: ; preds = %1
%11 = load i64, i64* %4
%12 = load i64, i64* @LONG_MAX
%13 = icmp eq i64 %11, %12
br i1 %13, label %24, label %14
14: ; preds = %10
%15 = load i64, i64* %4
%16 = load i64, i64* @LONG_MIN
%17 = icmp eq i64 %15, %16
br i1 %17, label %24, label %18
18: ; preds = %14, %1
%19 = load i64, i64* @errno
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = load i64, i64* %4
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %21, %14, %10
%25 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %21, %18
%29 = load i8*, i8** %3
%30 = load i8*, i8** %2
%31 = icmp eq i8* %29, %30
br i1 %31, label %32, label %37
32: ; preds = %28
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %28
%38 = load i8*, i8** %3
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %37
%43 = load i32, i32* @stderr
%44 = load i8*, i8** %3
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.2, i64 0, i64 0), i8* %44)
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %37
%49 = load i64, i64* %4
ret i64 %49
}

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
@LONG_MAX = global i64 0
@LONG_MIN = global i64 0
@.str = [15 x i8] c"Error (strtol)\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [57 x i8] c"Error (strtol): No digits were found in the shift value\0A\00"
@.str.2 = [85 x i8] c"Error (strtol): The non-numerical character(s) \22%s\22 were detected after shift value\0A\00"
define i64 @parseShiftValue(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i64 0, i64* @errno
%4 = call i64 @strtol(i8* %0, i8** %2, i32 10)
%5 = load i64, i64* @errno
%6 = load i64, i64* @ERANGE
%7 = icmp eq i64 %5, %6
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = load i64, i64* @LONG_MAX
%10 = icmp eq i64 %4, %9
%11 = load i64, i64* @LONG_MIN
%12 = icmp eq i64 %4, %11
%13 = select i1 %10, i1 true, i1 %12
br i1 %13, label %18, label %14
14: ; preds = %8, %1
%15 = icmp ne i64 %5, 0
%16 = icmp eq i64 %4, 0
%17 = select i1 %15, i1 %16, i1 false
br i1 %17, label %18, label %22
18: ; preds = %14, %8
%19 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %14
%23 = load i8*, i8** %2
%24 = icmp eq i8* %23, %0
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = tail call i32 @exit(i32 %28)
unreachable
30: ; preds = %22
%31 = load i8, i8* %23
%32 = icmp eq i8 %31, 0
br i1 %32, label %38, label %33
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = tail call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%36 = load i32, i32* @EXIT_FAILURE
%37 = tail call i32 @exit(i32 %36)
unreachable
38: ; preds = %30
ret i64 %4
}