#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 */
typedef scalar_t__ uint32_t;
typedef scalar_t__ int16_t;

/* Variables and functions */
scalar_t__ SHRT_MAX;
scalar_t__ SHRT_MIN;
scalar_t__ signed32_value(char const *, char const *, unsigned int, int *);
int /*<<< orphan*/ warn(char *, char const *, unsigned int);
int16_t signed16_value(const char *value, const char *filename,
                       unsigned linenum, int *error) {
  uint32_t ret = signed32_value(value, filename, linenum, error);
  if ((*error == 0) && (ret > (uint32_t)SHRT_MAX || ret < (uint32_t)SHRT_MIN)) {
    warn("Value out of range %s:%d", filename, linenum);
    *error = -1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<signed16_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1030 <signed32_value@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jne    11a1 <signed16_value+0x81>
mov    -0x28(%rbp),%rax
mov    0x2e71(%rip),%rcx
cmp    (%rcx),%rax
jg     1184 <signed16_value+0x64>
mov    -0x28(%rbp),%rax
mov    0x2e65(%rip),%rcx
cmp    (%rcx),%rax
jge    11a1 <signed16_value+0x81>
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xe6e(%rip),%rdi
call   1040 <warn@plt>
mov    -0x20(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signed16_value>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %edx,%r14d
mov    %rsi,%r15
call   1030 <signed32_value@plt>
mov    %rax,%rbp
cmpl   $0x0,(%rbx)
jne    116d <signed16_value+0x4d>
mov    0x2e94(%rip),%rax
cmp    (%rax),%rbp
jg     1155 <signed16_value+0x35>
mov    0x2e90(%rip),%rax
cmp    (%rax),%rbp
jge    116d <signed16_value+0x4d>
lea    0xea4(%rip),%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1040 <warn@plt>
movl   $0xffffffff,(%rbx)
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SHRT_MAX = global i64 0
@SHRT_MIN = global i64 0
@.str = [25 x i8] c"Value out of range %s:%d\00"
define i64 @signed16_value(i8* %0, i8* %1, i32 %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%10 = load i8*, i8** %5
%11 = load i8*, i8** %6
%12 = load i32, i32* %7
%13 = load i32*, i32** %8
%14 = call i64 @signed32_value(i8* %10, i8* %11, i32 %12, i32* %13)
store i64 %14, i64* %9
%15 = load i32*, i32** %8
%16 = load i32, i32* %15
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %31
18: ; preds = %4
%19 = load i64, i64* %9
%20 = load i64, i64* @SHRT_MAX
%21 = icmp sgt i64 %19, %20
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = load i64, i64* %9
%24 = load i64, i64* @SHRT_MIN
%25 = icmp slt i64 %23, %24
br i1 %25, label %26, label %31
26: ; preds = %22, %18
%27 = load i8*, i8** %6
%28 = load i32, i32* %7
%29 = call i32 @warn(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %27, i32 %28)
%30 = load i32*, i32** %8
store i32 -1, i32* %30
br label %31
31: ; preds = %26, %22, %4
%32 = load i64, i64* %9
ret i64 %32
}

LLVM IR (-O2):
@SHRT_MAX = global i64 0
@SHRT_MIN = global i64 0
@.str = [25 x i8] c"Value out of range %s:%d\00"
define i64 @signed16_value(i8* %0, i8* %1, i32 %2, i32* %3) {
%5 = tail call i64 @signed32_value(i8* %0, i8* %1, i32 %2, i32* %3)
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %4
%9 = load i64, i64* @SHRT_MAX
%10 = icmp sgt i64 %5, %9
%11 = load i64, i64* @SHRT_MIN
%12 = icmp slt i64 %5, %11
%13 = select i1 %10, i1 true, i1 %12
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = tail call i32 @warn(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %2)
store i32 -1, i32* %3
br label %16
16: ; preds = %8, %14, %4
ret i64 %5
}