#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 */
char hexDigit(int);
int /*<<< orphan*/ write(int, char *, int);
void fwriteHex(int f, int v) {
  char s[10];
  s[0] = '0';
  s[1] = 'x';
  int i;
  for (i = 0; i < 8; i++) {
    int h = (v >> (i * 4)) & 0xf;
    s[9 - i] = hexDigit(h);
  }
  write(f, s, 10);
}


x86 assembly (clang, -O0):
<fwriteHex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movb   $0x30,-0x12(%rbp)
movb   $0x78,-0x11(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x8,-0x18(%rbp)
jge    117e <fwriteHex+0x5e>
mov    -0x8(%rbp),%eax
mov    -0x18(%rbp),%ecx
shl    $0x2,%ecx
sar    %cl,%eax
and    $0xf,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <hexDigit@plt>
mov    %al,%cl
mov    $0x9,%eax
sub    -0x18(%rbp),%eax
cltq
mov    %cl,-0x12(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113d <fwriteHex+0x1d>
mov    -0x4(%rbp),%edi
lea    -0x12(%rbp),%rsi
mov    $0xa,%edx
call   1030 <write@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fwriteHex>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
movw   $0x7830,0xe(%rsp)
mov    %esi,%edi
and    $0xf,%edi
call   1040 <hexDigit@plt>
mov    %al,0x17(%rsp)
mov    %ebp,%edi
shr    $0x4,%edi
and    $0xf,%edi
call   1040 <hexDigit@plt>
mov    %al,0x16(%rsp)
mov    %ebp,%edi
shr    $0x8,%edi
and    $0xf,%edi
call   1040 <hexDigit@plt>
mov    %al,0x15(%rsp)
mov    %ebp,%edi
shr    $0xc,%edi
and    $0xf,%edi
call   1040 <hexDigit@plt>
mov    %al,0x14(%rsp)
mov    %ebp,%edi
shr    $0x10,%edi
and    $0xf,%edi
call   1040 <hexDigit@plt>
mov    %al,0x13(%rsp)
mov    %ebp,%edi
shr    $0x14,%edi
and    $0xf,%edi
call   1040 <hexDigit@plt>
mov    %al,0x12(%rsp)
mov    %ebp,%edi
shr    $0x18,%edi
and    $0xf,%edi
call   1040 <hexDigit@plt>
mov    %al,0x11(%rsp)
shr    $0x1c,%ebp
mov    %ebp,%edi
call   1040 <hexDigit@plt>
mov    %al,0x10(%rsp)
lea    0xe(%rsp),%rsi
mov    %ebx,%edi
mov    $0xa,%edx
call   1030 <write@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @fwriteHex(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [10 x i8]
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
store i8 48, i8* %8
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 1
store i8 120, i8* %9
store i32 0, i32* %6
br label %10
10: ; preds = %25, %2
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 8
br i1 %12, label %13, label %28
13: ; preds = %10
%14 = load i32, i32* %4
%15 = load i32, i32* %6
%16 = mul nsw i32 %15, 4
%17 = ashr i32 %14, %16
%18 = and i32 %17, 15
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = call signext i8 @hexDigit(i32 %19)
%21 = load i32, i32* %6
%22 = sub nsw i32 9, %21
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 %23
store i8 %20, i8* %24
br label %25
25: ; preds = %13
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %10
28: ; preds = %10
%29 = load i32, i32* %3
%30 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%31 = call i32 @write(i32 %29, i8* %30, i32 10)
ret void
}

LLVM IR (-O2):
define void @fwriteHex(i32 %0, i32 %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
store i8 48, i8* %4
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 1
store i8 120, i8* %5
%6 = and i32 %1, 15
%7 = tail call signext i8 @hexDigit(i32 %6)
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 9
store i8 %7, i8* %8
%9 = lshr i32 %1, 4
%10 = and i32 %9, 15
%11 = tail call signext i8 @hexDigit(i32 %10)
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 8
store i8 %11, i8* %12
%13 = lshr i32 %1, 8
%14 = and i32 %13, 15
%15 = tail call signext i8 @hexDigit(i32 %14)
%16 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 7
store i8 %15, i8* %16
%17 = lshr i32 %1, 12
%18 = and i32 %17, 15
%19 = tail call signext i8 @hexDigit(i32 %18)
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 6
store i8 %19, i8* %20
%21 = lshr i32 %1, 16
%22 = and i32 %21, 15
%23 = tail call signext i8 @hexDigit(i32 %22)
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 5
store i8 %23, i8* %24
%25 = lshr i32 %1, 20
%26 = and i32 %25, 15
%27 = tail call signext i8 @hexDigit(i32 %26)
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 4
store i8 %27, i8* %28
%29 = lshr i32 %1, 24
%30 = and i32 %29, 15
%31 = tail call signext i8 @hexDigit(i32 %30)
%32 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 3
store i8 %31, i8* %32
%33 = lshr i32 %1, 28
%34 = tail call signext i8 @hexDigit(i32 %33)
%35 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 2
store i8 %34, i8* %35
%36 = call i32 @write(i32 %0, i8* %4, i32 10)
ret void
}