#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 *, int);
int /*<<< orphan*/ stderr;
char to_char(int i) {
  char characters[26] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  if (i < -1 || i >= 26) {
    fprintf(stderr,
            "ERROR: Invalid conversion to character value, integer '%d' out of "
            "range\n",
            i);
    exit(1);
  }
  if (i == -1) {
    return '-';
  } else {
    return characters[i];
  }
}


x86 assembly (clang, -O0):
<to_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    0xece(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xecb(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xec8(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xec5(%rip),%ax
mov    %ax,-0x18(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jl     116b <to_char+0x4b>
cmpl   $0x1a,-0x8(%rbp)
jl     118d <to_char+0x6d>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe9c(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
cmpl   $0xffffffff,-0x8(%rbp)
jne    11a0 <to_char+0x80>
movb   $0x2d,-0x1(%rbp)
jmp    11ab <to_char+0x8b>
movslq -0x8(%rbp),%rax
mov    -0x30(%rbp,%rax,1),%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<to_char>:
push   %rax
mov    %edi,%edx
lea    -0x1a(%rdx),%eax
cmp    $0xffffffe4,%eax
jbe    1142 <to_char+0x22>
cmp    $0xffffffff,%edx
je     113e <to_char+0x1e>
mov    %edx,%eax
lea    0xec7(%rip),%rcx
mov    (%rax,%rcx,1),%al
pop    %rcx
ret
mov    $0x2d,%al
pop    %rcx
ret
mov    0x2e97(%rip),%rax
mov    (%rax),%edi
lea    0xec8(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

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

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