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


x86 assembly (clang, -O0):
<GetCharCfgValue>:
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 <GetCharCfgValue+0x32>
movl   $0x0,-0x4(%rbp)
jmp    1197 <GetCharCfgValue+0x77>
cmpq   $0xffffffffffffff80,-0x20(%rbp)
jl     1168 <GetCharCfgValue+0x48>
cmpq   $0x7f,-0x20(%rbp)
jle    1184 <GetCharCfgValue+0x64>
mov    -0x10(%rbp),%rsi
lea    0xe8d(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1197 <GetCharCfgValue+0x77>
mov    -0x20(%rbp),%rax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetCharCfgValue>:
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     1165 <GetCharCfgValue+0x45>
mov    0x8(%rsp),%rax
movsbq %al,%rcx
cmp    %rax,%rcx
je     115d <GetCharCfgValue+0x3d>
lea    0xead(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
jmp    1165 <GetCharCfgValue+0x45>
mov    %al,(%r14)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [61 x i8] c"Invalid config line, value must be between -128 and 127: %s\0A\00"
define i32 @GetCharCfgValue(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %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 %24
11: ; preds = %2
%12 = load i64, i64* %6
%13 = icmp slt i64 %12, -128
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i64, i64* %6
%16 = icmp sgt i64 %15, 127
br i1 %16, label %17, label %20
17: ; preds = %14, %11
%18 = load i8*, i8** %4
%19 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i8* %18)
store i32 0, i32* %3
br label %24
20: ; preds = %14
%21 = load i64, i64* %6
%22 = trunc i64 %21 to i8
%23 = load i8*, i8** %5
store i8 %22, i8* %23
store i32 1, i32* %3
br label %24
24: ; preds = %20, %17, %10
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@.str = [61 x i8] c"Invalid config line, value must be between -128 and 127: %s\0A\00"
define i32 @GetCharCfgValue(i8* %0, i8* 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 %15, label %7
7: ; preds = %2
%8 = load i64, i64* %3
%9 = add i64 %8, -128
%10 = icmp ult i64 %9, -256
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %15
13: ; preds = %7
%14 = trunc i64 %8 to i8
store i8 %14, i8* %1
br label %15
15: ; preds = %2, %13, %11
%16 = phi i32 [ 0, %11 ], [ 1, %13 ], [ 0, %2 ]
ret i32 %16
}