#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*/ serial_putc(unsigned char);
void send_hex(unsigned char number) {
  unsigned char hexChar;
  char i;
  for (i = 0; i < 2; i++) {
    if (i == 0)
      hexChar = number >> 4;
    else
      hexChar = number & 0x0F;
    if (hexChar < 10)
      hexChar = hexChar + '0';
    else
      hexChar = hexChar + ('A' - 10);
    serial_putc(hexChar);
  }
}


x86 assembly (clang, -O0):
<send_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movb   $0x0,-0x3(%rbp)
movsbl -0x3(%rbp),%eax
cmp    $0x2,%eax
jge    1191 <send_hex+0x81>
movsbl -0x3(%rbp),%eax
cmp    $0x0,%eax
jne    114b <send_hex+0x3b>
movzbl -0x1(%rbp),%eax
sar    $0x4,%eax
mov    %al,-0x2(%rbp)
jmp    1155 <send_hex+0x45>
movzbl -0x1(%rbp),%eax
and    $0xf,%eax
mov    %al,-0x2(%rbp)
movzbl -0x2(%rbp),%eax
cmp    $0xa,%eax
jge    1171 <send_hex+0x61>
movzbl -0x2(%rbp),%eax
add    $0x30,%eax
mov    %al,-0x2(%rbp)
jmp    117b <send_hex+0x6b>
movzbl -0x2(%rbp),%eax
add    $0x37,%eax
mov    %al,-0x2(%rbp)
movzbl -0x2(%rbp),%edi
call   1030 <serial_putc@plt>
mov    -0x3(%rbp),%al
add    $0x1,%al
mov    %al,-0x3(%rbp)
jmp    1122 <send_hex+0x12>
add    $0x10,%rsp
pop    %rbp
ret

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

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

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