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


x86 assembly (clang, -O0):
<GetShortCfgValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <GetLongCfgValue@plt>
cmp    $0x0,%eax
jne    1152 <GetShortCfgValue+0x32>
movl   $0x0,-0x4(%rbp)
jmp    11bf <GetShortCfgValue+0x9f>
mov    -0x20(%rbp),%rax
mov    0x2e83(%rip),%rcx
cmp    (%rcx),%rax
jl     117a <GetShortCfgValue+0x5a>
mov    -0x20(%rbp),%rax
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%rax
jle    11aa <GetShortCfgValue+0x8a>
mov    0x2e5f(%rip),%rax
mov    (%rax),%rsi
mov    0x2e4d(%rip),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe67(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11bf <GetShortCfgValue+0x9f>
mov    -0x20(%rbp),%rax
mov    %ax,%cx
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetShortCfgValue>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1030 <GetLongCfgValue@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     117b <GetShortCfgValue+0x5b>
mov    0x8(%rsp),%rax
mov    0x2e96(%rip),%rcx
mov    (%rcx),%rsi
mov    0x2e84(%rip),%rcx
mov    (%rcx),%rdx
cmp    %rsi,%rax
jl     116c <GetShortCfgValue+0x4c>
cmp    %rdx,%rax
jg     116c <GetShortCfgValue+0x4c>
mov    %ax,(%r14)
mov    $0x1,%ebp
jmp    117b <GetShortCfgValue+0x5b>
lea    0xe8d(%rip),%rdi
mov    %rbx,%rcx
call   1040 <printf@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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