void led_putnum(char num) {
  static unsigned char *leds = (unsigned char *)0xd00003;
  static unsigned char num_bits[18] = {0xff, 0xc0, 0xf9, 0xa4, 0xb0, 0x99,
                                       0x92, 0x82, 0xf8, 0x80, 0x98, 0x98,
                                       0x20, 0x3,  0x27, 0x21, 0x4,  0xe};
  if (num >= '0' && num <= '9')
    num = (num - '0') + 1;
  if (num >= 'a' && num <= 'f')
    num = (num - 'a') + 12;
  if (num == ' ')
    num = 0;
  *leds = num_bits[(int)num];
}


x86 assembly (clang, -O0):
<led_putnum>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0x30,%eax
jl     1131 <led_putnum+0x31>
movsbl -0x1(%rbp),%eax
cmp    $0x39,%eax
jg     1131 <led_putnum+0x31>
movsbl -0x1(%rbp),%eax
sub    $0x30,%eax
add    $0x1,%eax
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0x61,%eax
jl     1158 <led_putnum+0x58>
movsbl -0x1(%rbp),%eax
cmp    $0x66,%eax
jg     1158 <led_putnum+0x58>
movsbl -0x1(%rbp),%eax
sub    $0x61,%eax
add    $0xc,%eax
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0x20,%eax
jne    1169 <led_putnum+0x69>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
movslq %eax,%rcx
lea    0x2ec9(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    0x2eaf(%rip),%rax
mov    %cl,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<led_putnum>:
lea    -0x30(%rdi),%eax
lea    -0x2f(%rdi),%ecx
cmp    $0xa,%al
movzbl %cl,%eax
cmovae %edi,%eax
lea    -0x61(%rax),%ecx
lea    -0x55(%rax),%edx
cmp    $0x6,%cl
movzbl %dl,%ecx
cmovae %eax,%ecx
xor    %eax,%eax
cmp    $0x20,%cl
cmovne %ecx,%eax
movsbq %al,%rax
lea    0xed0(%rip),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,0xd00003
ret

LLVM IR (-O0):
@led_putnum.leds = internal global i8* inttoptr (i64 13631491 to i8*)
@led_putnum.num_bits = internal global [18 x i8] c"\FF\C0\F9\A4\B0\99\92\82\F8\80\98\98 \03'!\04\0E"
define void @led_putnum(i8 signext %0) {
%2 = alloca i8
store i8 %0, i8* %2
%3 = load i8, i8* %2
%4 = sext i8 %3 to i32
%5 = icmp sge i32 %4, 48
br i1 %5, label %6, label %16
6: ; preds = %1
%7 = load i8, i8* %2
%8 = sext i8 %7 to i32
%9 = icmp sle i32 %8, 57
br i1 %9, label %10, label %16
10: ; preds = %6
%11 = load i8, i8* %2
%12 = sext i8 %11 to i32
%13 = sub nsw i32 %12, 48
%14 = add nsw i32 %13, 1
%15 = trunc i32 %14 to i8
store i8 %15, i8* %2
br label %16
16: ; preds = %10, %6, %1
%17 = load i8, i8* %2
%18 = sext i8 %17 to i32
%19 = icmp sge i32 %18, 97
br i1 %19, label %20, label %30
20: ; preds = %16
%21 = load i8, i8* %2
%22 = sext i8 %21 to i32
%23 = icmp sle i32 %22, 102
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = load i8, i8* %2
%26 = sext i8 %25 to i32
%27 = sub nsw i32 %26, 97
%28 = add nsw i32 %27, 12
%29 = trunc i32 %28 to i8
store i8 %29, i8* %2
br label %30
30: ; preds = %24, %20, %16
%31 = load i8, i8* %2
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 32
br i1 %33, label %34, label %35
34: ; preds = %30
store i8 0, i8* %2
br label %35
35: ; preds = %34, %30
%36 = load i8, i8* %2
%37 = sext i8 %36 to i32
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [18 x i8], [18 x i8]* @led_putnum.num_bits, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = load i8*, i8** @led_putnum.leds
store i8 %40, i8* %41
ret void
}

LLVM IR (-O2):
@led_putnum.num_bits = internal unnamed_addr constant [18 x i8] c"\FF\C0\F9\A4\B0\99\92\82\F8\80\98\98 \03'!\04\0E"
define void @led_putnum(i8 signext %0) {
%2 = add i8 %0, -48
%3 = icmp ult i8 %2, 10
%4 = add i8 %0, -47
%5 = select i1 %3, i8 %4, i8 %0
%6 = add i8 %5, -97
%7 = icmp ult i8 %6, 6
%8 = add i8 %5, -85
%9 = select i1 %7, i8 %8, i8 %5
%10 = icmp eq i8 %9, 32
%11 = select i1 %10, i8 0, i8 %9
%12 = sext i8 %11 to i64
%13 = getelementptr inbounds [18 x i8], [18 x i8]* @led_putnum.num_bits, i64 0, i64 %12
%14 = load i8, i8* %13
store i8 %14, i8* inttoptr (i64 13631491 to i8*)
ret void
}