#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char);
int /*<<< orphan*/ stderr;
int to_int(char c) {
  if (c == '-') {
    return -1;
  } else {
    if (c < 'A' || c > 'Z') {
      fprintf(
          stderr,
          "ERROR: Invalid conversion to int value, char '%c' out of range\n",
          c);
      exit(1);
    }
    return c - 'A';
  }
}


x86 assembly (clang, -O0):
<to_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x2d,%eax
jne    1147 <to_int+0x27>
movl   $0xffffffff,-0x4(%rbp)
jmp    118e <to_int+0x6e>
movsbl -0x5(%rbp),%eax
cmp    $0x41,%eax
jl     1161 <to_int+0x41>
movsbl -0x5(%rbp),%eax
cmp    $0x5a,%eax
jle    1184 <to_int+0x64>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
lea    0xe8f(%rip),%rsi
movsbl -0x5(%rbp),%edx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
movsbl -0x5(%rbp),%eax
sub    $0x41,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<to_int>:
mov    $0xffffffff,%eax
cmp    $0x2d,%dil
je     1137 <to_int+0x17>
lea    -0x5b(%rdi),%eax
cmp    $0xe5,%al
jbe    1138 <to_int+0x18>
add    $0xffffffbf,%edi
mov    %edi,%eax
ret
push   %rax
mov    0x2ea0(%rip),%rax
mov    (%rax),%eax
movsbl %dil,%edx
lea    0xeb3(%rip),%rsi
mov    %eax,%edi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [64 x i8] c"ERROR: Invalid conversion to int value, char '%c' out of range\0A\00"
define i32 @to_int(i8 signext %0) {
%2 = alloca i32
%3 = alloca i8
store i8 %0, i8* %3
%4 = load i8, i8* %3
%5 = sext i8 %4 to i32
%6 = icmp eq i32 %5, 45
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 -1, i32* %2
br label %25
8: ; preds = %1
%9 = load i8, i8* %3
%10 = sext i8 %9 to i32
%11 = icmp slt i32 %10, 65
br i1 %11, label %16, label %12
12: ; preds = %8
%13 = load i8, i8* %3
%14 = sext i8 %13 to i32
%15 = icmp sgt i32 %14, 90
br i1 %15, label %16, label %21
16: ; preds = %12, %8
%17 = load i32, i32* @stderr
%18 = load i8, i8* %3
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i8 signext %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %12
%22 = load i8, i8* %3
%23 = sext i8 %22 to i32
%24 = sub nsw i32 %23, 65
store i32 %24, i32* %2
br label %25
25: ; preds = %21, %7
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [64 x i8] c"ERROR: Invalid conversion to int value, char '%c' out of range\0A\00"
define i32 @to_int(i8 signext %0) {
%2 = sext i8 %0 to i32
%3 = icmp eq i8 %0, 45
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = add i8 %0, -91
%6 = icmp ult i8 %5, -26
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i8 signext %0)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %4
%12 = add nsw i32 %2, -65
br label %13
13: ; preds = %1, %11
%14 = phi i32 [ %12, %11 ], [ -1, %1 ]
ret i32 %14
}