#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*/ GetLongCfgValue(char *, long *, int);
long SHRT_MAX;
long SHRT_MIN;
int /*<<< orphan*/ printf(char *, int, long, long, char *);
int GetShortCfgValue(char *str, short *value, int lineCnt) {
  long longval;
  if (!GetLongCfgValue(str, &longval, lineCnt)) {
    return 0;
  }
  if (longval < SHRT_MIN || longval > SHRT_MAX) {
    printf("Invalid config line %d, value must be between %d and %d: %s\n",
           lineCnt, SHRT_MIN, SHRT_MAX, str);
    return 0;
  }
  *value = longval;
  return 1;
}


x86 assembly (clang, -O0):
<GetShortCfgValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    -0x28(%rbp),%rsi
call   1030 <GetLongCfgValue@plt>
cmp    $0x0,%eax
jne    1158 <GetShortCfgValue+0x38>
movl   $0x0,-0x4(%rbp)
jmp    11c8 <GetShortCfgValue+0xa8>
mov    -0x28(%rbp),%rax
mov    0x2e7d(%rip),%rcx
cmp    (%rcx),%rax
jl     1180 <GetShortCfgValue+0x60>
mov    -0x28(%rbp),%rax
mov    0x2e61(%rip),%rcx
cmp    (%rcx),%rax
jle    11b3 <GetShortCfgValue+0x93>
mov    -0x1c(%rbp),%esi
mov    0x2e56(%rip),%rax
mov    (%rax),%rdx
mov    0x2e44(%rip),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%r8
lea    0xe5e(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c8 <GetShortCfgValue+0xa8>
mov    -0x28(%rbp),%rax
mov    %ax,%cx
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetShortCfgValue>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1030 <GetLongCfgValue@plt>
xor    %r14d,%r14d
test   %eax,%eax
je     117d <GetShortCfgValue+0x5d>
mov    (%rsp),%rax
mov    0x2e97(%rip),%rcx
mov    (%rcx),%rdx
mov    0x2e85(%rip),%rcx
mov    (%rcx),%rcx
cmp    %rdx,%rax
jl     116c <GetShortCfgValue+0x4c>
cmp    %rcx,%rax
jg     116c <GetShortCfgValue+0x4c>
mov    %ax,(%r15)
mov    $0x1,%r14d
jmp    117d <GetShortCfgValue+0x5d>
lea    0xe8d(%rip),%rdi
mov    %ebp,%esi
mov    %rbx,%r8
call   1040 <printf@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SHRT_MIN = global i64 0
@SHRT_MAX = global i64 0
@.str = [61 x i8] c"Invalid config line %d, value must be between %d and %d: %s\0A\00"
define i32 @GetShortCfgValue(i8* %0, i16* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i16*
%7 = alloca i32
%8 = alloca i64
store i8* %0, i8** %5
store i16* %1, i16** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = load i32, i32* %7
%11 = call i32 @GetLongCfgValue(i8* %9, i64* %8, i32 %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %3
store i32 0, i32* %4
br label %32
14: ; preds = %3
%15 = load i64, i64* %8
%16 = load i64, i64* @SHRT_MIN
%17 = icmp slt i64 %15, %16
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = load i64, i64* %8
%20 = load i64, i64* @SHRT_MAX
%21 = icmp sgt i64 %19, %20
br i1 %21, label %22, label %28
22: ; preds = %18, %14
%23 = load i32, i32* %7
%24 = load i64, i64* @SHRT_MIN
%25 = load i64, i64* @SHRT_MAX
%26 = load i8*, i8** %5
%27 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i32 %23, i64 %24, i64 %25, i8* %26)
store i32 0, i32* %4
br label %32
28: ; preds = %18
%29 = load i64, i64* %8
%30 = trunc i64 %29 to i16
%31 = load i16*, i16** %6
store i16 %30, i16* %31
store i32 1, i32* %4
br label %32
32: ; preds = %28, %22, %13
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
@SHRT_MIN = global i64 0
@SHRT_MAX = global i64 0
@.str = [61 x i8] c"Invalid config line %d, value must be between %d and %d: %s\0A\00"
define i32 @GetShortCfgValue(i8* %0, i16* nocapture writeonly %1, i32 %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
%6 = call i32 @GetLongCfgValue(i8* %0, i64* %4, i32 %2)
%7 = icmp eq i32 %6, 0
br i1 %7, label %19, label %8
8: ; preds = %3
%9 = load i64, i64* %4
%10 = load i64, i64* @SHRT_MIN
%11 = icmp slt i64 %9, %10
%12 = load i64, i64* @SHRT_MAX
%13 = icmp sgt i64 %9, %12
%14 = select i1 %11, i1 true, i1 %13
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i32 %2, i64 %10, i64 %12, i8* %0)
br label %19
17: ; preds = %8
%18 = trunc i64 %9 to i16
store i16 %18, i16* %1
br label %19
19: ; preds = %3, %17, %15
%20 = phi i32 [ 0, %15 ], [ 1, %17 ], [ 0, %3 ]
ret i32 %20
}