#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 SHRT_MAX;
long SHRT_MIN;
int /*<<< orphan*/ printf(char *, long);
int longToShort(long makeMeAShort) {
  if (makeMeAShort < SHRT_MIN || makeMeAShort > SHRT_MAX) {
    printf("%ld is out of int range\n", makeMeAShort);
    return !makeMeAShort;
  }
  return (int)makeMeAShort;
}


x86 assembly (clang, -O0):
<longToShort>:
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 <longToShort+0x34>
mov    -0x10(%rbp),%rax
mov    0x2e9d(%rip),%rcx
cmp    (%rcx),%rax
jle    116b <longToShort+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    %eax,-0x4(%rbp)
jmp    1172 <longToShort+0x62>
mov    -0x10(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<longToShort>:
push   %rbx
mov    %rdi,%rbx
mov    0x2ec5(%rip),%rax
cmp    %rdi,(%rax)
jg     1130 <longToShort+0x20>
mov    0x2eb1(%rip),%rax
cmp    %rbx,(%rax)
jl     1130 <longToShort+0x20>
mov    %ebx,%eax
pop    %rbx
ret
lea    0xec9(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
test   %rbx,%rbx
sete   %al
pop    %rbx
ret

LLVM IR (-O0):
@SHRT_MIN = global i64 0
@SHRT_MAX = global i64 0
@.str = [25 x i8] c"%ld is out of int range\0A\00"
define i32 @longToShort(i64 %0) {
%2 = alloca i32
%3 = alloca i64
store i64 %0, i64* %3
%4 = load i64, i64* %3
%5 = load i64, i64* @SHRT_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* @SHRT_MAX
%10 = icmp sgt i64 %8, %9
br i1 %10, label %11, label %18
11: ; preds = %7, %1
%12 = load i64, i64* %3
%13 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 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
store i32 %17, i32* %2
br label %21
18: ; preds = %7
%19 = load i64, i64* %3
%20 = trunc i64 %19 to i32
store i32 %20, i32* %2
br label %21
21: ; preds = %18, %11
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@SHRT_MIN = global i64 0
@SHRT_MAX = global i64 0
@.str = [25 x i8] c"%ld is out of int range\0A\00"
define i32 @longToShort(i64 %0) {
%2 = load i64, i64* @SHRT_MIN
%3 = icmp sgt i64 %2, %0
%4 = load i64, i64* @SHRT_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 ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i64 %0)
%9 = icmp eq i64 %0, 0
%10 = zext i1 %9 to i32
br label %13
11: ; preds = %1
%12 = trunc i64 %0 to i32
br label %13
13: ; preds = %11, %7
%14 = phi i32 [ %10, %7 ], [ %12, %11 ]
ret i32 %14
}