#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*/ USARTPutc(char);
void putchex(char c) {
  char nib;
  USARTPutc('0');
  USARTPutc('x');
  nib = (c & 0xF0) >> 4;
  if (nib < 10)
    USARTPutc('0' + nib);
  else
    USARTPutc('a' + nib - 10);
  nib = c & 0x0F;
  if (nib < 10)
    USARTPutc('0' + nib);
  else
    USARTPutc('a' + nib - 10);
}


x86 assembly (clang, -O0):
<putchex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    $0x30,%edi
call   1030 <USARTPutc@plt>
mov    $0x78,%edi
call   1030 <USARTPutc@plt>
movsbl -0x1(%rbp),%eax
and    $0xf0,%eax
sar    $0x4,%eax
mov    %al,-0x2(%rbp)
movsbl -0x2(%rbp),%eax
cmp    $0xa,%eax
jge    1162 <putchex+0x52>
movsbl -0x2(%rbp),%eax
add    $0x30,%eax
movsbl %al,%edi
call   1030 <USARTPutc@plt>
jmp    1174 <putchex+0x64>
movsbl -0x2(%rbp),%eax
add    $0x61,%eax
sub    $0xa,%eax
movsbl %al,%edi
call   1030 <USARTPutc@plt>
movsbl -0x1(%rbp),%eax
and    $0xf,%eax
mov    %al,-0x2(%rbp)
movsbl -0x2(%rbp),%eax
cmp    $0xa,%eax
jge    119f <putchex+0x8f>
movsbl -0x2(%rbp),%eax
add    $0x30,%eax
movsbl %al,%edi
call   1030 <USARTPutc@plt>
jmp    11b1 <putchex+0xa1>
movsbl -0x2(%rbp),%eax
add    $0x61,%eax
sub    $0xa,%eax
movsbl %al,%edi
call   1030 <USARTPutc@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putchex>:
push   %rbx
mov    %edi,%ebx
mov    $0x30,%edi
call   1030 <USARTPutc@plt>
mov    $0x78,%edi
call   1030 <USARTPutc@plt>
mov    %ebx,%eax
shr    $0x4,%al
lea    0x57(%rax),%ecx
or     $0x30,%al
cmp    $0xa0,%bl
movzbl %al,%eax
movzbl %cl,%ecx
cmovb  %eax,%ecx
movzbl %cl,%edi
call   1030 <USARTPutc@plt>
and    $0xf,%bl
lea    0x57(%rbx),%eax
lea    0x30(%rbx),%ecx
cmp    $0xa,%bl
movzbl %cl,%ecx
movzbl %al,%eax
cmovb  %ecx,%eax
movzbl %al,%edi
pop    %rbx
jmp    1030 <USARTPutc@plt>

LLVM IR (-O0):
define void @putchex(i8 signext %0) {
%2 = alloca i8
%3 = alloca i8
store i8 %0, i8* %2
%4 = call i32 @USARTPutc(i8 signext 48)
%5 = call i32 @USARTPutc(i8 signext 120)
%6 = load i8, i8* %2
%7 = sext i8 %6 to i32
%8 = and i32 %7, 240
%9 = ashr i32 %8, 4
%10 = trunc i32 %9 to i8
store i8 %10, i8* %3
%11 = load i8, i8* %3
%12 = sext i8 %11 to i32
%13 = icmp slt i32 %12, 10
br i1 %13, label %14, label %20
14: ; preds = %1
%15 = load i8, i8* %3
%16 = sext i8 %15 to i32
%17 = add nsw i32 48, %16
%18 = trunc i32 %17 to i8
%19 = call i32 @USARTPutc(i8 signext %18)
br label %27
20: ; preds = %1
%21 = load i8, i8* %3
%22 = sext i8 %21 to i32
%23 = add nsw i32 97, %22
%24 = sub nsw i32 %23, 10
%25 = trunc i32 %24 to i8
%26 = call i32 @USARTPutc(i8 signext %25)
br label %27
27: ; preds = %20, %14
%28 = load i8, i8* %2
%29 = sext i8 %28 to i32
%30 = and i32 %29, 15
%31 = trunc i32 %30 to i8
store i8 %31, i8* %3
%32 = load i8, i8* %3
%33 = sext i8 %32 to i32
%34 = icmp slt i32 %33, 10
br i1 %34, label %35, label %41
35: ; preds = %27
%36 = load i8, i8* %3
%37 = sext i8 %36 to i32
%38 = add nsw i32 48, %37
%39 = trunc i32 %38 to i8
%40 = call i32 @USARTPutc(i8 signext %39)
br label %48
41: ; preds = %27
%42 = load i8, i8* %3
%43 = sext i8 %42 to i32
%44 = add nsw i32 97, %43
%45 = sub nsw i32 %44, 10
%46 = trunc i32 %45 to i8
%47 = call i32 @USARTPutc(i8 signext %46)
br label %48
48: ; preds = %41, %35
ret void
}

LLVM IR (-O2):
define void @putchex(i8 signext %0) {
%2 = tail call i32 @USARTPutc(i8 signext 48)
%3 = tail call i32 @USARTPutc(i8 signext 120)
%4 = lshr i8 %0, 4
%5 = icmp ult i8 %0, -96
%6 = add nuw nsw i8 %4, 87
%7 = or i8 %4, 48
%8 = select i1 %5, i8 %7, i8 %6
%9 = tail call i32 @USARTPutc(i8 signext %8)
%10 = and i8 %0, 15
%11 = icmp ult i8 %10, 10
%12 = add nuw nsw i8 %10, 87
%13 = or i8 %10, 48
%14 = select i1 %11, i8 %13, i8 %12
%15 = tail call i32 @USARTPutc(i8 signext %14)
ret void
}