#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*/ uart_puts(char *);
void uart_puthex(const unsigned int value) {
  char c;
  int i;
  char buf[11];
  buf[0] = '0';
  buf[1] = 'x';
  for (i = 7; i >= 0; i--) {
    c = (char)((value >> (i * 4)) & 0x0f);
    if (c > 9)
      c += ('a' - 10);
    else
      c += '0';
    buf[9 - i] = c;
  }
  buf[10] = '\0';
  uart_puts(buf);
}


x86 assembly (clang, -O0):
<uart_puthex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movb   $0x30,-0x17(%rbp)
movb   $0x78,-0x16(%rbp)
movl   $0x7,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     118a <uart_puthex+0x7a>
mov    -0x4(%rbp),%eax
mov    -0xc(%rbp),%ecx
shl    $0x2,%ecx
shr    %cl,%eax
and    $0xf,%eax
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x9,%eax
jle    1161 <uart_puthex+0x51>
movsbl -0x5(%rbp),%eax
add    $0x57,%eax
mov    %al,-0x5(%rbp)
jmp    116b <uart_puthex+0x5b>
movsbl -0x5(%rbp),%eax
add    $0x30,%eax
mov    %al,-0x5(%rbp)
mov    -0x5(%rbp),%cl
mov    $0x9,%eax
sub    -0xc(%rbp),%eax
cltq
mov    %cl,-0x17(%rbp,%rax,1)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    112a <uart_puthex+0x1a>
movb   $0x0,-0xd(%rbp)
lea    -0x17(%rbp),%rdi
call   1030 <uart_puts@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uart_puthex>:
sub    $0x18,%rsp
mov    %edi,%eax
shr    $0x1c,%eax
lea    0x57(%rax),%ecx
or     $0x30,%al
cmp    $0xa0000000,%edi
movzbl %cl,%ecx
movzbl %al,%eax
cmovae %ecx,%eax
movw   $0x7830,0xd(%rsp)
mov    %al,0xf(%rsp)
mov    %edi,%eax
shr    $0x18,%eax
and    $0xf,%eax
lea    0x57(%rax),%ecx
lea    0x30(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ecx
cmovae %eax,%ecx
mov    %edi,%eax
shr    $0x14,%eax
and    $0xf,%eax
lea    0x57(%rax),%edx
cmp    $0xa,%eax
lea    0x30(%rax),%eax
movzbl %dl,%edx
movzbl %al,%eax
cmovae %edx,%eax
mov    %cl,0x10(%rsp)
mov    %al,0x11(%rsp)
mov    %edi,%eax
shr    $0x10,%eax
and    $0xf,%eax
lea    0x57(%rax),%ecx
lea    0x30(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ecx
cmovae %eax,%ecx
mov    %edi,%eax
shr    $0xc,%eax
and    $0xf,%eax
lea    0x57(%rax),%edx
cmp    $0xa,%eax
lea    0x30(%rax),%eax
movzbl %dl,%edx
movzbl %al,%eax
cmovae %edx,%eax
mov    %cl,0x12(%rsp)
mov    %al,0x13(%rsp)
mov    %edi,%eax
shr    $0x8,%eax
and    $0xf,%eax
lea    0x57(%rax),%ecx
lea    0x30(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ecx
cmovae %eax,%ecx
mov    %edi,%eax
shr    $0x4,%eax
and    $0xf,%eax
lea    0x57(%rax),%edx
cmp    $0xa,%eax
lea    0x30(%rax),%eax
movzbl %dl,%edx
movzbl %al,%eax
cmovae %edx,%eax
mov    %cl,0x14(%rsp)
mov    %al,0x15(%rsp)
and    $0xf,%edi
lea    0x57(%rdi),%eax
lea    0x30(%rdi),%ecx
cmp    $0xa,%edi
movzbl %al,%eax
movzbl %cl,%ecx
cmovae %eax,%ecx
mov    %cl,0x16(%rsp)
movb   $0x0,0x17(%rsp)
lea    0xd(%rsp),%rdi
call   1030 <uart_puts@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
define void @uart_puthex(i32 %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i32
%5 = alloca [11 x i8]
store i32 %0, i32* %2
%6 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 0
store i8 48, i8* %6
%7 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 1
store i8 120, i8* %7
store i32 7, i32* %4
br label %8
8: ; preds = %37, %1
%9 = load i32, i32* %4
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %40
11: ; preds = %8
%12 = load i32, i32* %2
%13 = load i32, i32* %4
%14 = mul nsw i32 %13, 4
%15 = lshr i32 %12, %14
%16 = and i32 %15, 15
%17 = trunc i32 %16 to i8
store i8 %17, i8* %3
%18 = load i8, i8* %3
%19 = sext i8 %18 to i32
%20 = icmp sgt i32 %19, 9
br i1 %20, label %21, label %26
21: ; preds = %11
%22 = load i8, i8* %3
%23 = sext i8 %22 to i32
%24 = add nsw i32 %23, 87
%25 = trunc i32 %24 to i8
store i8 %25, i8* %3
br label %31
26: ; preds = %11
%27 = load i8, i8* %3
%28 = sext i8 %27 to i32
%29 = add nsw i32 %28, 48
%30 = trunc i32 %29 to i8
store i8 %30, i8* %3
br label %31
31: ; preds = %26, %21
%32 = load i8, i8* %3
%33 = load i32, i32* %4
%34 = sub nsw i32 9, %33
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 %35
store i8 %32, i8* %36
br label %37
37: ; preds = %31
%38 = load i32, i32* %4
%39 = add nsw i32 %38, -1
store i32 %39, i32* %4
br label %8
40: ; preds = %8
%41 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 10
store i8 0, i8* %41
%42 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 0
%43 = call i32 @uart_puts(i8* %42)
ret void
}

LLVM IR (-O2):
define void @uart_puthex(i32 %0) {
%2 = alloca [11 x i8]
%3 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
store i8 48, i8* %3
%4 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 1
store i8 120, i8* %4
%5 = lshr i32 %0, 28
%6 = icmp ugt i32 %0, -1610612737
%7 = trunc i32 %5 to i8
%8 = add nuw nsw i8 %7, 87
%9 = or i8 %7, 48
%10 = select i1 %6, i8 %8, i8 %9
%11 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 2
store i8 %10, i8* %11
%12 = lshr i32 %0, 24
%13 = and i32 %12, 15
%14 = icmp ugt i32 %13, 9
%15 = trunc i32 %13 to i8
%16 = add nuw nsw i8 %15, 87
%17 = or i8 %15, 48
%18 = select i1 %14, i8 %16, i8 %17
%19 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 3
store i8 %18, i8* %19
%20 = lshr i32 %0, 20
%21 = and i32 %20, 15
%22 = icmp ugt i32 %21, 9
%23 = trunc i32 %21 to i8
%24 = add nuw nsw i8 %23, 87
%25 = or i8 %23, 48
%26 = select i1 %22, i8 %24, i8 %25
%27 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 4
store i8 %26, i8* %27
%28 = lshr i32 %0, 16
%29 = and i32 %28, 15
%30 = icmp ugt i32 %29, 9
%31 = trunc i32 %29 to i8
%32 = add nuw nsw i8 %31, 87
%33 = or i8 %31, 48
%34 = select i1 %30, i8 %32, i8 %33
%35 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 5
store i8 %34, i8* %35
%36 = lshr i32 %0, 12
%37 = and i32 %36, 15
%38 = icmp ugt i32 %37, 9
%39 = trunc i32 %37 to i8
%40 = add nuw nsw i8 %39, 87
%41 = or i8 %39, 48
%42 = select i1 %38, i8 %40, i8 %41
%43 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 6
store i8 %42, i8* %43
%44 = lshr i32 %0, 8
%45 = and i32 %44, 15
%46 = icmp ugt i32 %45, 9
%47 = trunc i32 %45 to i8
%48 = add nuw nsw i8 %47, 87
%49 = or i8 %47, 48
%50 = select i1 %46, i8 %48, i8 %49
%51 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 7
store i8 %50, i8* %51
%52 = lshr i32 %0, 4
%53 = and i32 %52, 15
%54 = icmp ugt i32 %53, 9
%55 = trunc i32 %53 to i8
%56 = add nuw nsw i8 %55, 87
%57 = or i8 %55, 48
%58 = select i1 %54, i8 %56, i8 %57
%59 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 8
store i8 %58, i8* %59
%60 = and i32 %0, 15
%61 = icmp ugt i32 %60, 9
%62 = trunc i32 %60 to i8
%63 = add nuw nsw i8 %62, 87
%64 = or i8 %62, 48
%65 = select i1 %61, i8 %63, i8 %64
%66 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 9
store i8 %65, i8* %66
%67 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 10
store i8 0, i8* %67
%68 = call i32 @uart_puts(i8* %3)
ret void
}