#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*/ vdp_putchar(unsigned char);
void puthex(unsigned char nibbles, unsigned int v) {
  char i = (char)nibbles - 1;
  while (i >= 0) {
    unsigned int aux = (v >> (i << 2)) & 0x000F;
    unsigned char n = aux & 0x000F;
    if (n > 9)
      vdp_putchar('A' + (n - 10));
    else
      vdp_putchar('0' + n);
    i--;
  }
}


x86 assembly (clang, -O0):
<puthex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %esi,-0x8(%rbp)
movsbl -0x1(%rbp),%eax
sub    $0x1,%eax
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x0,%eax
jl     1193 <puthex+0x83>
mov    -0x8(%rbp),%eax
movsbl -0x9(%rbp),%ecx
shl    $0x2,%ecx
shr    %cl,%eax
and    $0xf,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
and    $0xf,%eax
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%eax
cmp    $0x9,%eax
jle    1177 <puthex+0x67>
movzbl -0x11(%rbp),%eax
sub    $0xa,%eax
add    $0x41,%eax
movzbl %al,%edi
call   1030 <vdp_putchar@plt>
jmp    1186 <puthex+0x76>
movzbl -0x11(%rbp),%eax
add    $0x30,%eax
movzbl %al,%edi
call   1030 <vdp_putchar@plt>
mov    -0x9(%rbp),%al
add    $0xff,%al
mov    %al,-0x9(%rbp)
jmp    112b <puthex+0x1b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<puthex>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
add    $0xff,%bl
js     1150 <puthex+0x40>
mov    %esi,%ebp
nopl   0x0(%rax)
movzbl %bl,%ebx
lea    0x0(,%rbx,4),%ecx
mov    %ebp,%eax
shr    %cl,%eax
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x37(%rax),%edx
cmp    $0xa,%eax
movzbl %dl,%eax
movzbl %cl,%ecx
cmovae %eax,%ecx
movzbl %cl,%edi
call   1030 <vdp_putchar@plt>
add    $0xff,%bl
jns    1120 <puthex+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define void @puthex(i8 zeroext %0, i32 %1) {
%3 = add i8 %0, -1
%4 = icmp sgt i8 %3, -1
br i1 %4, label %5, label %19
5: ; preds = %2, %5
%6 = phi i8 [ %17, %5 ], [ %3, %2 ]
%7 = zext i8 %6 to i32
%8 = shl nuw nsw i32 %7, 2
%9 = lshr i32 %1, %8
%10 = and i32 %9, 15
%11 = icmp ugt i32 %10, 9
%12 = trunc i32 %10 to i8
%13 = or i8 %12, 48
%14 = add nuw nsw i8 %12, 55
%15 = select i1 %11, i8 %14, i8 %13
%16 = tail call i32 @vdp_putchar(i8 zeroext %15)
%17 = add i8 %6, -1
%18 = icmp sgt i8 %17, -1
br i1 %18, label %5, label %19
19: ; preds = %5, %2
ret void
}