#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ uart_put(int);
void uart_puthex(uint32_t value) {
  uint32_t shift;
  uint32_t tempchar;
  shift = 32;
  while (1) {
    shift -= 4;
    tempchar = (value >> shift) & 0xF;
    if (tempchar > 9) {
      tempchar += 0x37;
    } else {
      tempchar += 0x30;
    }
    uart_put(tempchar);
    if (shift == 0) {
      break;
    }
  }
}


x86 assembly (clang, -O0):
<uart_puthex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x20,-0x8(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
sar    %cl,%eax
and    $0xf,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x9,-0xc(%rbp)
jle    1151 <uart_puthex+0x41>
mov    -0xc(%rbp),%eax
add    $0x37,%eax
mov    %eax,-0xc(%rbp)
jmp    115a <uart_puthex+0x4a>
mov    -0xc(%rbp),%eax
add    $0x30,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <uart_put@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1171 <uart_puthex+0x61>
jmp    1176 <uart_puthex+0x66>
jmp    1122 <uart_puthex+0x12>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uart_puthex>:
push   %rbx
mov    %edi,%ebx
shr    $0x1c,%edi
lea    0x37(%rdi),%eax
or     $0x30,%edi
cmp    $0xa0000000,%ebx
cmovae %eax,%edi
call   1030 <uart_put@plt>
mov    %ebx,%eax
shr    $0x18,%eax
and    $0xf,%eax
lea    0x37(%rax),%ecx
lea    0x30(%rax),%edi
cmp    $0xa,%eax
cmovae %ecx,%edi
call   1030 <uart_put@plt>
mov    %ebx,%eax
shr    $0x14,%eax
and    $0xf,%eax
lea    0x37(%rax),%ecx
lea    0x30(%rax),%edi
cmp    $0xa,%eax
cmovae %ecx,%edi
call   1030 <uart_put@plt>
mov    %ebx,%eax
shr    $0x10,%eax
and    $0xf,%eax
lea    0x37(%rax),%ecx
lea    0x30(%rax),%edi
cmp    $0xa,%eax
cmovae %ecx,%edi
call   1030 <uart_put@plt>
mov    %ebx,%eax
shr    $0xc,%eax
and    $0xf,%eax
lea    0x37(%rax),%ecx
lea    0x30(%rax),%edi
cmp    $0xa,%eax
cmovae %ecx,%edi
call   1030 <uart_put@plt>
mov    %ebx,%eax
shr    $0x8,%eax
and    $0xf,%eax
lea    0x37(%rax),%ecx
lea    0x30(%rax),%edi
cmp    $0xa,%eax
cmovae %ecx,%edi
call   1030 <uart_put@plt>
mov    %ebx,%eax
shr    $0x4,%eax
and    $0xf,%eax
lea    0x37(%rax),%ecx
lea    0x30(%rax),%edi
cmp    $0xa,%eax
cmovae %ecx,%edi
call   1030 <uart_put@plt>
and    $0xf,%ebx
lea    0x37(%rbx),%eax
lea    0x30(%rbx),%edi
cmp    $0xa,%ebx
cmovae %eax,%edi
pop    %rbx
jmp    1030 <uart_put@plt>

LLVM IR (-O0):
define void @uart_puthex(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 32, i32* %3
br label %5
5: ; preds = %1, %26
%6 = load i32, i32* %3
%7 = sub nsw i32 %6, 4
store i32 %7, i32* %3
%8 = load i32, i32* %2
%9 = load i32, i32* %3
%10 = ashr i32 %8, %9
%11 = and i32 %10, 15
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 9
br i1 %13, label %14, label %17
14: ; preds = %5
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 55
store i32 %16, i32* %4
br label %20
17: ; preds = %5
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 48
store i32 %19, i32* %4
br label %20
20: ; preds = %17, %14
%21 = load i32, i32* %4
%22 = call i32 @uart_put(i32 %21)
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %20
br label %27
26: ; preds = %20
br label %5
27: ; preds = %25
ret void
}

LLVM IR (-O2):
define void @uart_puthex(i32 %0) {
%2 = lshr i32 %0, 28
%3 = icmp ugt i32 %0, -1610612737
%4 = add nuw nsw i32 %2, 55
%5 = or i32 %2, 48
%6 = select i1 %3, i32 %4, i32 %5
%7 = tail call i32 @uart_put(i32 %6)
%8 = lshr i32 %0, 24
%9 = and i32 %8, 15
%10 = icmp ugt i32 %9, 9
%11 = add nuw nsw i32 %9, 55
%12 = or i32 %9, 48
%13 = select i1 %10, i32 %11, i32 %12
%14 = tail call i32 @uart_put(i32 %13)
%15 = lshr i32 %0, 20
%16 = and i32 %15, 15
%17 = icmp ugt i32 %16, 9
%18 = add nuw nsw i32 %16, 55
%19 = or i32 %16, 48
%20 = select i1 %17, i32 %18, i32 %19
%21 = tail call i32 @uart_put(i32 %20)
%22 = lshr i32 %0, 16
%23 = and i32 %22, 15
%24 = icmp ugt i32 %23, 9
%25 = add nuw nsw i32 %23, 55
%26 = or i32 %23, 48
%27 = select i1 %24, i32 %25, i32 %26
%28 = tail call i32 @uart_put(i32 %27)
%29 = lshr i32 %0, 12
%30 = and i32 %29, 15
%31 = icmp ugt i32 %30, 9
%32 = add nuw nsw i32 %30, 55
%33 = or i32 %30, 48
%34 = select i1 %31, i32 %32, i32 %33
%35 = tail call i32 @uart_put(i32 %34)
%36 = lshr i32 %0, 8
%37 = and i32 %36, 15
%38 = icmp ugt i32 %37, 9
%39 = add nuw nsw i32 %37, 55
%40 = or i32 %37, 48
%41 = select i1 %38, i32 %39, i32 %40
%42 = tail call i32 @uart_put(i32 %41)
%43 = lshr i32 %0, 4
%44 = and i32 %43, 15
%45 = icmp ugt i32 %44, 9
%46 = add nuw nsw i32 %44, 55
%47 = or i32 %44, 48
%48 = select i1 %45, i32 %46, i32 %47
%49 = tail call i32 @uart_put(i32 %48)
%50 = and i32 %0, 15
%51 = icmp ugt i32 %50, 9
%52 = add nuw nsw i32 %50, 55
%53 = or i32 %50, 48
%54 = select i1 %51, i32 %52, i32 %53
%55 = tail call i32 @uart_put(i32 %54)
ret void
}