#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*/ OPM_WriteString(unsigned char *, long long);
void OPM_WriteHex(long long i) {
  unsigned char s[3];
  int digit;
  digit = ((long long)((int)i) >> (4));
  if (digit < 10) {
    s[0] = (unsigned char)(48 + digit);
  } else {
    s[0] = (unsigned char)(87 + digit);
  }
  digit = (((int)i) & ~(-16));
  if (digit < 10) {
    s[1] = (unsigned char)(48 + digit);
  } else {
    s[1] = (unsigned char)(87 + digit);
  }
  s[2] = 0x00;
  OPM_WriteString(s, ((long long)(3)));
}


x86 assembly (clang, -O0):
<OPM_WriteHex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cltq
sar    $0x4,%rax
mov    %eax,-0x10(%rbp)
cmpl   $0xa,-0x10(%rbp)
jge    1141 <OPM_WriteHex+0x31>
mov    -0x10(%rbp),%eax
add    $0x30,%eax
mov    %al,-0xb(%rbp)
jmp    114a <OPM_WriteHex+0x3a>
mov    -0x10(%rbp),%eax
add    $0x57,%eax
mov    %al,-0xb(%rbp)
mov    -0x8(%rbp),%rax
and    $0xf,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0xa,-0x10(%rbp)
jge    116c <OPM_WriteHex+0x5c>
mov    -0x10(%rbp),%eax
add    $0x30,%eax
mov    %al,-0xa(%rbp)
jmp    1175 <OPM_WriteHex+0x65>
mov    -0x10(%rbp),%eax
add    $0x57,%eax
mov    %al,-0xa(%rbp)
movb   $0x0,-0x9(%rbp)
lea    -0xb(%rbp),%rdi
mov    $0x3,%esi
call   1030 <OPM_WriteString@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OPM_WriteHex>:
push   %rax
movslq %edi,%rax
mov    %rax,%rcx
sar    $0x4,%rcx
cmp    $0xa,%ecx
mov    $0x30,%edx
mov    $0x57,%esi
cmovl  %edx,%esi
add    %cl,%sil
mov    %sil,0x5(%rsp)
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x57(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ecx
cmovb  %eax,%ecx
mov    %cl,0x6(%rsp)
movb   $0x0,0x7(%rsp)
lea    0x5(%rsp),%rdi
mov    $0x3,%esi
call   1030 <OPM_WriteString@plt>
pop    %rax
ret

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

LLVM IR (-O2):
define void @OPM_WriteHex(i64 %0) {
%2 = alloca [3 x i8]
%3 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%4 = trunc i64 %0 to i32
%5 = shl i64 %0, 32
%6 = ashr i64 %5, 36
%7 = trunc i64 %6 to i32
%8 = icmp slt i32 %7, 10
%9 = trunc i64 %6 to i8
%10 = select i1 %8, i8 48, i8 87
%11 = add i8 %10, %9
store i8 %11, i8* %3
%12 = and i32 %4, 15
%13 = icmp ult i32 %12, 10
%14 = trunc i32 %12 to i8
%15 = or i8 %14, 48
%16 = add nuw nsw i8 %14, 87
%17 = select i1 %13, i8 %15, i8 %16
%18 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 1
store i8 %17, i8* %18
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 2
store i8 0, i8* %19
%20 = call i32 @OPM_WriteString(i8* %3, i64 3)
ret void
}