#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*/ fwrite(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int unhexc(char);
void unhex(char c) {
  static int prev = -1;
  int cv = unhexc(c);
  char h;
  if (cv == -1)
    return;
  if (prev == -1) {
    prev = cv;
    return;
  }
  h = (prev << 4) | cv;
  fwrite(&h, 1, 1, stdout);
  prev = -1;
}


x86 assembly (clang, -O0):
<unhex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%edi
call   1030 <unhexc@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1149 <unhex+0x29>
jmp    1196 <unhex+0x76>
cmpl   $0xffffffff,0x2ee0(%rip)
jne    1164 <unhex+0x44>
mov    -0x8(%rbp),%eax
mov    %eax,0x2ed1(%rip)
jmp    1196 <unhex+0x76>
mov    0x2ec6(%rip),%eax
shl    $0x4,%eax
or     -0x8(%rbp),%eax
mov    %al,-0x9(%rbp)
mov    0x2e66(%rip),%rax
mov    (%rax),%ecx
lea    -0x9(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fwrite@plt>
movl   $0xffffffff,0x2e9a(%rip)
ff ff ff
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unhex>:
push   %rax
call   1030 <unhexc@plt>
cmp    $0xffffffff,%eax
je     1167 <unhex+0x47>
mov    0x2eff(%rip),%ecx
cmp    $0xffffffff,%ecx
je     1161 <unhex+0x41>
shl    $0x4,%ecx
or     %eax,%ecx
mov    %cl,0x7(%rsp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%ecx
lea    0x7(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
mov    $0xffffffff,%eax
mov    %eax,0x2ec9(%rip)
pop    %rax
ret

LLVM IR (-O0):
@unhex.prev = internal global i32 -1
@stdout = global i32 0
define void @unhex(i8 signext %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca i8
store i8 %0, i8* %2
%5 = load i8, i8* %2
%6 = call i32 @unhexc(i8 signext %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %10
9: ; preds = %1
br label %23
10: ; preds = %1
%11 = load i32, i32* @unhex.prev
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = load i32, i32* %3
store i32 %14, i32* @unhex.prev
br label %23
15: ; preds = %10
%16 = load i32, i32* @unhex.prev
%17 = shl i32 %16, 4
%18 = load i32, i32* %3
%19 = or i32 %17, %18
%20 = trunc i32 %19 to i8
store i8 %20, i8* %4
%21 = load i32, i32* @stdout
%22 = call i32 @fwrite(i8* %4, i32 1, i32 1, i32 %21)
store i32 -1, i32* @unhex.prev
br label %23
23: ; preds = %15, %13, %9
ret void
}

LLVM IR (-O2):
@unhex.prev = internal unnamed_addr global i32 -1
@stdout = global i32 0
define void @unhex(i8 signext %0) {
%2 = alloca i8
%3 = tail call i32 @unhexc(i8 signext %0)
%4 = icmp eq i32 %3, -1
br i1 %4, label %16, label %5
5: ; preds = %1
%6 = load i32, i32* @unhex.prev
%7 = icmp eq i32 %6, -1
br i1 %7, label %14, label %8
8: ; preds = %5
%9 = shl i32 %6, 4
%10 = or i32 %9, %3
%11 = trunc i32 %10 to i8
store i8 %11, i8* %2
%12 = load i32, i32* @stdout
%13 = call i32 @fwrite(i8* %2, i32 1, i32 1, i32 %12)
br label %14
14: ; preds = %5, %8
%15 = phi i32 [ -1, %8 ], [ %3, %5 ]
store i32 %15, i32* @unhex.prev
br label %16
16: ; preds = %14, %1
ret void
}