#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 */
long SCHAR_MAX;
long SCHAR_MIN;
int /*<<< orphan*/ printf(char *, long);
signed char longToChar(long makeMeAChar) {
  if (makeMeAChar < SCHAR_MIN || makeMeAChar > SCHAR_MAX) {
    printf("%ld is out of char range\n", makeMeAChar);
    return !makeMeAChar;
  }
  return (char)makeMeAChar;
}


x86 assembly (clang, -O0):
<longToChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2eb9(%rip),%rcx
cmp    (%rcx),%rax
jl     1144 <longToChar+0x34>
mov    -0x10(%rbp),%rax
mov    0x2e9d(%rip),%rcx
cmp    (%rcx),%rax
jle    116b <longToChar+0x5b>
mov    -0x10(%rbp),%rsi
lea    0xeb1(%rip),%rdi
call   1030 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %al,-0x1(%rbp)
jmp    1172 <longToChar+0x62>
mov    -0x10(%rbp),%rax
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<longToChar>:
push   %rbx
mov    %rdi,%rbx
mov    0x2ec5(%rip),%rax
cmp    %rdi,(%rax)
jg     112c <longToChar+0x1c>
mov    0x2eb1(%rip),%rax
cmp    %rbx,(%rax)
jge    1141 <longToChar+0x31>
lea    0xecd(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
test   %rbx,%rbx
sete   %bl
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@SCHAR_MIN = global i64 0
@SCHAR_MAX = global i64 0
@.str = [26 x i8] c"%ld is out of char range\0A\00"
define signext i8 @longToChar(i64 %0) {
%2 = alloca i8
%3 = alloca i64
store i64 %0, i64* %3
%4 = load i64, i64* %3
%5 = load i64, i64* @SCHAR_MIN
%6 = icmp slt i64 %4, %5
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = load i64, i64* %3
%9 = load i64, i64* @SCHAR_MAX
%10 = icmp sgt i64 %8, %9
br i1 %10, label %11, label %19
11: ; preds = %7, %1
%12 = load i64, i64* %3
%13 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i64 %12)
%14 = load i64, i64* %3
%15 = icmp ne i64 %14, 0
%16 = xor i1 %15, true
%17 = zext i1 %16 to i32
%18 = trunc i32 %17 to i8
store i8 %18, i8* %2
br label %22
19: ; preds = %7
%20 = load i64, i64* %3
%21 = trunc i64 %20 to i8
store i8 %21, i8* %2
br label %22
22: ; preds = %19, %11
%23 = load i8, i8* %2
ret i8 %23
}

LLVM IR (-O2):
@SCHAR_MIN = global i64 0
@SCHAR_MAX = global i64 0
@.str = [26 x i8] c"%ld is out of char range\0A\00"
define signext i8 @longToChar(i64 %0) {
%2 = load i64, i64* @SCHAR_MIN
%3 = icmp sgt i64 %2, %0
%4 = load i64, i64* @SCHAR_MAX
%5 = icmp slt i64 %4, %0
%6 = select i1 %3, i1 true, i1 %5
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i64 %0)
%9 = icmp eq i64 %0, 0
%10 = zext i1 %9 to i8
br label %13
11: ; preds = %1
%12 = trunc i64 %0 to i8
br label %13
13: ; preds = %11, %7
%14 = phi i8 [ %10, %7 ], [ %12, %11 ]
ret i8 %14
}