#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*/ EXIT_FAILURE;
int char2hex(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ file_print(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int hexify(int c, int high) {
  int i = char2hex(c);
  if (0 > i) {
    file_print("Tried to print non-hex number\n", stderr);
    exit(EXIT_FAILURE);
  }
  if (high) {
    i = i << 4;
  }
  return i;
}


x86 assembly (clang, -O0):
<hexify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <char2hex@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
jle    1177 <hexify+0x47>
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
lea    0xe9c(%rip),%rdi
call   1050 <file_print@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
cmpl   $0x0,-0x8(%rbp)
je     118a <hexify+0x5a>
mov    -0xc(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexify>:
push   %rbx
mov    %esi,%ebx
call   1030 <char2hex@plt>
test   %eax,%eax
js     114a <hexify+0x1a>
mov    %eax,%ecx
shl    $0x4,%ecx
test   %ebx,%ebx
cmove  %eax,%ecx
mov    %ecx,%eax
pop    %rbx
ret
mov    0x2e8f(%rip),%rax
mov    (%rax),%esi
lea    0xea6(%rip),%rdi
call   1050 <file_print@plt>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"Tried to print non-hex number\0A\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @hexify(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = call i32 @char2hex(i32 %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp sgt i32 0, %8
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @file_print(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* %5
%20 = shl i32 %19, 4
store i32 %20, i32* %5
br label %21
21: ; preds = %18, %15
%22 = load i32, i32* %5
ret i32 %22
}

LLVM IR (-O2):
@.str = [31 x i8] c"Tried to print non-hex number\0A\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @hexify(i32 %0, i32 %1) {
%3 = tail call i32 @char2hex(i32 %0)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @file_print(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = icmp eq i32 %1, 0
%12 = shl i32 %3, 4
%13 = select i1 %11, i32 %3, i32 %12
ret i32 %13
}