#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
void ihex_set_hex8(FILE *fp, unsigned char c) {
  int tmp;
  tmp = (c >> 4) & 0x0f;
  tmp += (tmp <= 9) ? '0' : ('A' - 10);
  fputc(tmp, fp);
  tmp = c & 0x0f;
  tmp += (tmp <= 9) ? '0' : ('A' - 10);
  fputc(tmp, fp);
}


x86 assembly (clang, -O0):
<ihex_set_hex8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
sar    $0x4,%eax
and    $0xf,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edx
mov    $0x37,%eax
mov    $0x30,%ecx
cmp    $0x9,%edx
cmovle %ecx,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1030 <fputc@plt>
movzbl -0x9(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edx
mov    $0x37,%eax
mov    $0x30,%ecx
cmp    $0x9,%edx
cmovle %ecx,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1030 <fputc@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ihex_set_hex8>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
mov    %esi,%edi
shr    $0x4,%edi
lea    0x37(%rdi),%eax
or     $0x30,%edi
cmp    $0xa0,%bl
cmovae %eax,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
and    $0xf,%ebx
lea    0x37(%rbx),%eax
lea    0x30(%rbx),%edi
cmp    $0xa,%ebx
cmovae %eax,%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fputc@plt>

LLVM IR (-O0):
define void @ihex_set_hex8(i32* %0, i8 zeroext %1) {
%3 = alloca i32*
%4 = alloca i8
%5 = alloca i32
store i32* %0, i32** %3
store i8 %1, i8* %4
%6 = load i8, i8* %4
%7 = zext i8 %6 to i32
%8 = ashr i32 %7, 4
%9 = and i32 %8, 15
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp sle i32 %10, 9
%12 = zext i1 %11 to i64
%13 = select i1 %11, i32 48, i32 55
%14 = load i32, i32* %5
%15 = add nsw i32 %14, %13
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = load i32*, i32** %3
%18 = call i32 @fputc(i32 %16, i32* %17)
%19 = load i8, i8* %4
%20 = zext i8 %19 to i32
%21 = and i32 %20, 15
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = icmp sle i32 %22, 9
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 48, i32 55
%26 = load i32, i32* %5
%27 = add nsw i32 %26, %25
store i32 %27, i32* %5
%28 = load i32, i32* %5
%29 = load i32*, i32** %3
%30 = call i32 @fputc(i32 %28, i32* %29)
ret void
}

LLVM IR (-O2):
define void @ihex_set_hex8(i32* nocapture %0, i8 zeroext %1) {
%3 = zext i8 %1 to i32
%4 = lshr i32 %3, 4
%5 = icmp ult i8 %1, -96
%6 = select i1 %5, i32 48, i32 55
%7 = add nuw nsw i32 %4, %6
%8 = tail call i32 @fputc(i32 %7, i32* %0)
%9 = and i32 %3, 15
%10 = icmp ult i32 %9, 10
%11 = select i1 %10, i32 48, i32 55
%12 = add nuw nsw i32 %11, %9
%13 = tail call i32 @fputc(i32 %12, i32* %0)
ret void
}