#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*/ write(int, char *, int);
void ft_print_hex(unsigned char c) {
  char ch[2];
  if (c / 16 > 9)
    ch[0] = c / 16 + 87;
  else
    ch[0] = c / 16 + 48;
  if (c % 16 > 9)
    ch[1] = c % 16 + 87;
  else
    ch[1] = c % 16 + 48;
  write(1, ch, 2);
}


x86 assembly (clang, -O0):
<ft_print_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x9,%eax
jle    114a <ft_print_hex+0x3a>
movzbl -0x1(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
add    $0x57,%eax
mov    %al,-0x3(%rbp)
jmp    115c <ft_print_hex+0x4c>
movzbl -0x1(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
add    $0x30,%eax
mov    %al,-0x3(%rbp)
movzbl -0x1(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x9,%edx
jle    118a <ft_print_hex+0x7a>
movzbl -0x1(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
add    $0x57,%edx
mov    %dl,%al
mov    %al,-0x2(%rbp)
jmp    119e <ft_print_hex+0x8e>
movzbl -0x1(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%al
mov    %al,-0x2(%rbp)
lea    -0x3(%rbp),%rsi
mov    $0x1,%edi
mov    $0x2,%edx
call   1030 <write@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_print_hex>:
push   %rax
mov    %edi,%eax
shr    $0x4,%al
lea    0x30(%rax),%ecx
add    $0x57,%al
cmp    $0xa0,%dil
movzbl %al,%eax
movzbl %cl,%ecx
cmovae %eax,%ecx
mov    %cl,0x6(%rsp)
and    $0xf,%dil
lea    0x57(%rdi),%eax
lea    0x30(%rdi),%ecx
cmp    $0xa,%dil
movzbl %al,%eax
movzbl %cl,%ecx
cmovae %eax,%ecx
mov    %cl,0x7(%rsp)
lea    0x6(%rsp),%rsi
mov    $0x1,%edi
mov    $0x2,%edx
call   1030 <write@plt>
pop    %rax
ret

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

LLVM IR (-O2):
define void @ft_print_hex(i8 zeroext %0) {
%2 = alloca [2 x i8]
%3 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%4 = lshr i8 %0, 4
%5 = icmp ugt i8 %0, -97
%6 = or i8 %4, 48
%7 = add nuw nsw i8 %4, 87
%8 = select i1 %5, i8 %7, i8 %6
store i8 %8, i8* %3
%9 = and i8 %0, 15
%10 = icmp ugt i8 %9, 9
%11 = add nuw nsw i8 %9, 87
%12 = or i8 %9, 48
%13 = select i1 %10, i8 %11, i8 %12
%14 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 1
store i8 %13, i8* %14
%15 = call i32 @write(i32 1, i8* %3, i32 2)
ret void
}