#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 int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ LOG_WARNING;
int /*<<< orphan*/ logIT(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int sscanf(char *, char *, int *);
char hex2chr(char *hex) {
  char buffer[16];
  int hex_value = -1;
  snprintf(buffer, sizeof(buffer), "0x%s", hex);
  if (sscanf(hex, "%x", &hex_value) != 1) {
    logIT(LOG_WARNING, "Ungültige Hex Zeichen in %s", hex);
  }
  return hex_value;
}


x86 assembly (clang, -O0):
<hex2chr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0x24(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x10,%esi
lea    0xea9(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe9e(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
je     1192 <hex2chr+0x62>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe7b(%rip),%rsi
call   1050 <logIT@plt>
mov    -0x24(%rbp),%eax
movsbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex2chr>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xeb9(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x10,%esi
mov    %rbx,%rcx
call   1030 <snprintf@plt>
lea    0xea5(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1040 <sscanf@plt>
cmp    $0x1,%eax
je     118a <hex2chr+0x5a>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
lea    0xe86(%rip),%rsi
mov    %rbx,%rdx
call   1050 <logIT@plt>
mov    0xc(%rsp),%al
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"0x%s\00"
@.str.1 = [3 x i8] c"%x\00"
@LOG_WARNING = global i32 0
@.str.2 = [29 x i8] c"Ung\C3\BCltige Hex Zeichen in %s\00"
define signext i8 @hex2chr(i8* %0) {
%2 = alloca i8*
%3 = alloca [16 x i8]
%4 = alloca i32
store i8* %0, i8** %2
store i32 -1, i32* %4
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%6 = load i8*, i8** %2
%7 = call i32 @snprintf(i8* %5, i32 16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i8*, i8** %2
%9 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%10 = icmp ne i32 %9, 1
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = load i32, i32* @LOG_WARNING
%13 = load i8*, i8** %2
%14 = call i32 @logIT(i32 %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %11, %1
%16 = load i32, i32* %4
%17 = trunc i32 %16 to i8
ret i8 %17
}

LLVM IR (-O2):
@.str = [5 x i8] c"0x%s\00"
@.str.1 = [3 x i8] c"%x\00"
@LOG_WARNING = global i32 0
@.str.2 = [29 x i8] c"Ung\C3\BCltige Hex Zeichen in %s\00"
define signext i8 @hex2chr(i8* %0) {
%2 = alloca [16 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
store i32 -1, i32* %3
%6 = call i32 @snprintf(i8* %4, i32 16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%8 = icmp eq i32 %7, 1
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = load i32, i32* @LOG_WARNING
%11 = call i32 @logIT(i32 %10, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %12
12: ; preds = %9, %1
%13 = load i32, i32* %3
%14 = trunc i32 %13 to i8
ret i8 %14
}