#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 outhex(int fdes, char c) {
  unsigned char uc;
  char tc;
  uc = *(unsigned char *)(&c);
  tc = ((uc / 16) % 16);
  tc = ((tc >= 0) && (tc <= 9)) ? (tc + '0') : (tc - 10 + 'A');
  write(fdes, &tc, 1);
  tc = (uc % 16);
  tc = ((tc >= 0) && (tc <= 9)) ? (tc + '0') : (tc - 10 + 'A');
  write(fdes, &tc, 1);
}


x86 assembly (clang, -O0):
<outhex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
mov    -0x5(%rbp),%al
mov    %al,-0x6(%rbp)
movzbl -0x6(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0x7(%rbp)
movsbl -0x7(%rbp),%eax
cmp    $0x0,%eax
jl     1169 <outhex+0x59>
movsbl -0x7(%rbp),%eax
cmp    $0x9,%eax
jg     1169 <outhex+0x59>
movsbl -0x7(%rbp),%eax
add    $0x30,%eax
mov    %eax,-0xc(%rbp)
jmp    1176 <outhex+0x66>
movsbl -0x7(%rbp),%eax
sub    $0xa,%eax
add    $0x41,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %al,-0x7(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x7(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
movzbl -0x6(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0x7(%rbp)
movsbl -0x7(%rbp),%eax
cmp    $0x0,%eax
jl     11c7 <outhex+0xb7>
movsbl -0x7(%rbp),%eax
cmp    $0x9,%eax
jg     11c7 <outhex+0xb7>
movsbl -0x7(%rbp),%eax
add    $0x30,%eax
mov    %eax,-0x10(%rbp)
jmp    11d4 <outhex+0xc4>
movsbl -0x7(%rbp),%eax
sub    $0xa,%eax
add    $0x41,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %al,-0x7(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x7(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<outhex>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %edi,%ebp
mov    %ebx,%eax
shr    $0x4,%al
lea    0x30(%rax),%ecx
add    $0x37,%al
cmp    $0xa0,%bl
movzbl %cl,%ecx
movzbl %al,%eax
cmovb  %ecx,%eax
mov    %al,0xf(%rsp)
lea    0xf(%rsp),%r14
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
and    $0xf,%bl
lea    0x30(%rbx),%eax
lea    0x37(%rbx),%ecx
cmp    $0xa,%bl
movzbl %al,%eax
movzbl %cl,%ecx
cmovb  %eax,%ecx
mov    %cl,0xf(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @outhex(i32 %0, i8 signext %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
store i32 %0, i32* %3
store i8 %1, i8* %4
%7 = load i8, i8* %4
store i8 %7, i8* %5
%8 = load i8, i8* %5
%9 = zext i8 %8 to i32
%10 = sdiv i32 %9, 16
%11 = srem i32 %10, 16
%12 = trunc i32 %11 to i8
store i8 %12, i8* %6
%13 = load i8, i8* %6
%14 = sext i8 %13 to i32
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %2
%17 = load i8, i8* %6
%18 = sext i8 %17 to i32
%19 = icmp sle i32 %18, 9
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i8, i8* %6
%22 = sext i8 %21 to i32
%23 = add nsw i32 %22, 48
br label %29
24: ; preds = %16, %2
%25 = load i8, i8* %6
%26 = sext i8 %25 to i32
%27 = sub nsw i32 %26, 10
%28 = add nsw i32 %27, 65
br label %29
29: ; preds = %24, %20
%30 = phi i32 [ %23, %20 ], [ %28, %24 ]
%31 = trunc i32 %30 to i8
store i8 %31, i8* %6
%32 = load i32, i32* %3
%33 = call i32 @write(i32 %32, i8* %6, i32 1)
%34 = load i8, i8* %5
%35 = zext i8 %34 to i32
%36 = srem i32 %35, 16
%37 = trunc i32 %36 to i8
store i8 %37, i8* %6
%38 = load i8, i8* %6
%39 = sext i8 %38 to i32
%40 = icmp sge i32 %39, 0
br i1 %40, label %41, label %49
41: ; preds = %29
%42 = load i8, i8* %6
%43 = sext i8 %42 to i32
%44 = icmp sle i32 %43, 9
br i1 %44, label %45, label %49
45: ; preds = %41
%46 = load i8, i8* %6
%47 = sext i8 %46 to i32
%48 = add nsw i32 %47, 48
br label %54
49: ; preds = %41, %29
%50 = load i8, i8* %6
%51 = sext i8 %50 to i32
%52 = sub nsw i32 %51, 10
%53 = add nsw i32 %52, 65
br label %54
54: ; preds = %49, %45
%55 = phi i32 [ %48, %45 ], [ %53, %49 ]
%56 = trunc i32 %55 to i8
store i8 %56, i8* %6
%57 = load i32, i32* %3
%58 = call i32 @write(i32 %57, i8* %6, i32 1)
ret void
}

LLVM IR (-O2):
define void @outhex(i32 %0, i8 signext %1) {
%3 = alloca i8
%4 = lshr i8 %1, 4
%5 = icmp ult i8 %1, -96
%6 = or i8 %4, 48
%7 = add nuw nsw i8 %4, 55
%8 = select i1 %5, i8 %6, i8 %7
store i8 %8, i8* %3
%9 = call i32 @write(i32 %0, i8* %3, i32 1)
%10 = and i8 %1, 15
%11 = icmp ult i8 %10, 10
%12 = or i8 %10, 48
%13 = add nuw nsw i8 %10, 55
%14 = select i1 %11, i8 %12, i8 %13
store i8 %14, i8* %3
%15 = call i32 @write(i32 %0, i8* %3, i32 1)
ret void
}