#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*/ uart1_putc(char);
int /*<<< orphan*/ uart1_write(char *);
void uart1_write_hex(unsigned int i) {
  char buffer[8];
  int b = 7;
  int tmp;
  while (b >= 0) {
    tmp = i % 16;
    if (tmp < 10) {
      buffer[b] = tmp + 0x30;
    } else {
      buffer[b] = tmp + 0x37;
    }
    i /= 16;
    b--;
  }
  uart1_write("0x");
  for (b = 0; b < 8; b++) {
    uart1_putc(buffer[b]);
  }
  uart1_write("\r\n");
}


x86 assembly (clang, -O0):
<uart1_write_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x7,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     118b <uart1_write_hex+0x6b>
mov    -0x4(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    1164 <uart1_write_hex+0x44>
mov    -0x14(%rbp),%eax
add    $0x30,%eax
mov    %al,%cl
movslq -0x10(%rbp),%rax
mov    %cl,-0xc(%rbp,%rax,1)
jmp    1174 <uart1_write_hex+0x54>
mov    -0x14(%rbp),%eax
add    $0x37,%eax
mov    %al,%cl
movslq -0x10(%rbp),%rax
mov    %cl,-0xc(%rbp,%rax,1)
mov    -0x4(%rbp),%eax
shr    $0x4,%eax
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1132 <uart1_write_hex+0x12>
lea    0xe6e(%rip),%rdi
call   1030 <uart1_write@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x8,-0x10(%rbp)
jge    11c4 <uart1_write_hex+0xa4>
movslq -0x10(%rbp),%rax
movsbl -0xc(%rbp,%rax,1),%edi
call   1040 <uart1_putc@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    119e <uart1_write_hex+0x7e>
lea    0xe38(%rip),%rdi
call   1030 <uart1_write@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uart1_write_hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%eax
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x37(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ecx
cmovb  %eax,%ecx
mov    %ecx,0x4(%rsp)
mov    %edi,%eax
shr    $0x4,%eax
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x37(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ecx
cmovb  %eax,%ecx
mov    %ecx,(%rsp)
mov    %edi,%eax
shr    $0x8,%eax
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x37(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%r12d
cmovb  %eax,%r12d
mov    %edi,%eax
shr    $0xc,%eax
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x37(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%r13d
cmovb  %eax,%r13d
mov    %edi,%eax
shr    $0x10,%eax
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x37(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ebx
cmovb  %eax,%ebx
mov    %edi,%eax
shr    $0x14,%eax
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x37(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ebp
cmovb  %eax,%ebp
mov    %edi,%eax
shr    $0x18,%eax
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x37(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%r14d
cmovb  %eax,%r14d
mov    %edi,%eax
shr    $0x1c,%eax
lea    0x30(%rax),%ecx
add    $0x37,%al
cmp    $0xa0000000,%edi
movzbl %cl,%ecx
movzbl %al,%r15d
cmovb  %ecx,%r15d
lea    0xdf3(%rip),%rdi
call   1030 <uart1_write@plt>
movzbl %r15b,%edi
call   1040 <uart1_putc@plt>
movzbl %r14b,%edi
call   1040 <uart1_putc@plt>
movzbl %bpl,%edi
call   1040 <uart1_putc@plt>
movzbl %bl,%edi
call   1040 <uart1_putc@plt>
movzbl %r13b,%edi
call   1040 <uart1_putc@plt>
movzbl %r12b,%edi
call   1040 <uart1_putc@plt>
movzbl (%rsp),%edi
call   1040 <uart1_putc@plt>
movzbl 0x4(%rsp),%edi
call   1040 <uart1_putc@plt>
lea    0xda2(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <uart1_write@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"0x\00"
@.str.1 = [3 x i8] c"\0D\0A\00"
define void @uart1_write_hex(i32 %0) {
%2 = alloca i32
%3 = alloca [8 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 7, i32* %4
br label %6
6: ; preds = %28, %1
%7 = load i32, i32* %4
%8 = icmp sge i32 %7, 0
br i1 %8, label %9, label %33
9: ; preds = %6
%10 = load i32, i32* %2
%11 = urem i32 %10, 16
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 10
br i1 %13, label %14, label %21
14: ; preds = %9
%15 = load i32, i32* %5
%16 = add nsw i32 %15, 48
%17 = trunc i32 %16 to i8
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 %19
store i8 %17, i8* %20
br label %28
21: ; preds = %9
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 55
%24 = trunc i32 %23 to i8
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 %26
store i8 %24, i8* %27
br label %28
28: ; preds = %21, %14
%29 = load i32, i32* %2
%30 = udiv i32 %29, 16
store i32 %30, i32* %2
%31 = load i32, i32* %4
%32 = add nsw i32 %31, -1
store i32 %32, i32* %4
br label %6
33: ; preds = %6
%34 = call i32 @uart1_write(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %35
35: ; preds = %44, %33
%36 = load i32, i32* %4
%37 = icmp slt i32 %36, 8
br i1 %37, label %38, label %47
38: ; preds = %35
%39 = load i32, i32* %4
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = call i32 @uart1_putc(i8 signext %42)
br label %44
44: ; preds = %38
%45 = load i32, i32* %4
%46 = add nsw i32 %45, 1
store i32 %46, i32* %4
br label %35
47: ; preds = %35
%48 = call i32 @uart1_write(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"0x\00"
@.str.1 = [3 x i8] c"\0D\0A\00"
define void @uart1_write_hex(i32 %0) {
%2 = and i32 %0, 15
%3 = icmp ult i32 %2, 10
%4 = trunc i32 %2 to i8
%5 = or i8 %4, 48
%6 = add nuw nsw i8 %4, 55
%7 = select i1 %3, i8 %5, i8 %6
%8 = lshr i32 %0, 4
%9 = and i32 %8, 15
%10 = icmp ult i32 %9, 10
%11 = trunc i32 %9 to i8
%12 = or i8 %11, 48
%13 = trunc i32 %9 to i8
%14 = add nuw nsw i8 %13, 55
%15 = select i1 %10, i8 %12, i8 %14
%16 = lshr i32 %0, 8
%17 = and i32 %16, 15
%18 = icmp ult i32 %17, 10
%19 = trunc i32 %17 to i8
%20 = or i8 %19, 48
%21 = trunc i32 %17 to i8
%22 = add nuw nsw i8 %21, 55
%23 = select i1 %18, i8 %20, i8 %22
%24 = lshr i32 %0, 12
%25 = and i32 %24, 15
%26 = icmp ult i32 %25, 10
%27 = trunc i32 %25 to i8
%28 = or i8 %27, 48
%29 = trunc i32 %25 to i8
%30 = add nuw nsw i8 %29, 55
%31 = select i1 %26, i8 %28, i8 %30
%32 = lshr i32 %0, 16
%33 = and i32 %32, 15
%34 = icmp ult i32 %33, 10
%35 = trunc i32 %33 to i8
%36 = or i8 %35, 48
%37 = trunc i32 %33 to i8
%38 = add nuw nsw i8 %37, 55
%39 = select i1 %34, i8 %36, i8 %38
%40 = lshr i32 %0, 20
%41 = and i32 %40, 15
%42 = icmp ult i32 %41, 10
%43 = trunc i32 %41 to i8
%44 = or i8 %43, 48
%45 = trunc i32 %41 to i8
%46 = add nuw nsw i8 %45, 55
%47 = select i1 %42, i8 %44, i8 %46
%48 = lshr i32 %0, 24
%49 = and i32 %48, 15
%50 = icmp ult i32 %49, 10
%51 = trunc i32 %49 to i8
%52 = or i8 %51, 48
%53 = trunc i32 %49 to i8
%54 = add nuw nsw i8 %53, 55
%55 = select i1 %50, i8 %52, i8 %54
%56 = lshr i32 %0, 28
%57 = icmp ult i32 %0, -1610612736
%58 = trunc i32 %56 to i8
%59 = or i8 %58, 48
%60 = trunc i32 %56 to i8
%61 = add nuw nsw i8 %60, 55
%62 = select i1 %57, i8 %59, i8 %61
%63 = tail call i32 @uart1_write(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%64 = tail call i32 @uart1_putc(i8 signext %62)
%65 = tail call i32 @uart1_putc(i8 signext %55)
%66 = tail call i32 @uart1_putc(i8 signext %47)
%67 = tail call i32 @uart1_putc(i8 signext %39)
%68 = tail call i32 @uart1_putc(i8 signext %31)
%69 = tail call i32 @uart1_putc(i8 signext %23)
%70 = tail call i32 @uart1_putc(i8 signext %15)
%71 = tail call i32 @uart1_putc(i8 signext %7)
%72 = tail call i32 @uart1_write(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
ret void
}