#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*/ mesg(char *);
void phex(long x) {
  char buf[9];
  int i;
  buf[8] = '\0';
  for (i = 7; i >= 0; i--) {
    char c = x & 0x0f;
    buf[i] = c < 10 ? c + '0' : c - 10 + 'A';
    x >>= 4;
  }
  mesg(buf);
}


x86 assembly (clang, -O0):
<phex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0x9(%rbp)
movl   $0x7,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     118c <phex+0x7c>
mov    -0x8(%rbp),%rax
and    $0xf,%rax
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
jge    1158 <phex+0x48>
movsbl -0x19(%rbp),%eax
add    $0x30,%eax
mov    %eax,-0x20(%rbp)
jmp    1165 <phex+0x55>
movsbl -0x19(%rbp),%eax
sub    $0xa,%eax
add    $0x41,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %al,%cl
movslq -0x18(%rbp),%rax
mov    %cl,-0x11(%rbp,%rax,1)
mov    -0x8(%rbp),%rax
sar    $0x4,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1127 <phex+0x17>
lea    -0x11(%rbp),%rdi
call   1030 <mesg@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<phex>:
sub    $0x18,%rsp
mov    %edi,%eax
shr    $0x4,%eax
mov    %edi,%ecx
shr    $0x8,%ecx
mov    %edi,%edx
shr    $0xc,%edx
movd   %edi,%xmm0
movd   %eax,%xmm1
punpckldq %xmm0,%xmm1
movd   %ecx,%xmm0
movd   %edx,%xmm2
punpckldq %xmm0,%xmm2
punpcklqdq %xmm1,%xmm2
pand   0xeb9(%rip),%xmm2
movb   $0x0,0x17(%rsp)
movdqa 0xebc(%rip),%xmm0
pcmpgtd %xmm2,%xmm0
movdqa 0xec0(%rip),%xmm1
por    %xmm2,%xmm1
paddd  0xec4(%rip),%xmm2
pand   %xmm0,%xmm1
pandn  %xmm2,%xmm0
por    %xmm1,%xmm0
packuswb %xmm0,%xmm0
packuswb %xmm0,%xmm0
movd   %xmm0,0x13(%rsp)
mov    %edi,%eax
shr    $0x10,%eax
and    $0xf,%eax
lea    0x37(%rax),%ecx
lea    0x30(%rax),%edx
cmp    $0xa,%eax
movzbl %dl,%eax
movzbl %cl,%ecx
cmovb  %eax,%ecx
mov    %cl,0x12(%rsp)
mov    %edi,%eax
shr    $0x14,%eax
and    $0xf,%eax
lea    0x37(%rax),%ecx
lea    0x30(%rax),%edx
cmp    $0xa,%eax
movzbl %dl,%eax
movzbl %cl,%ecx
cmovb  %eax,%ecx
mov    %cl,0x11(%rsp)
mov    %edi,%eax
shr    $0x18,%eax
and    $0xf,%eax
lea    0x37(%rax),%ecx
lea    0x30(%rax),%edx
cmp    $0xa,%eax
movzbl %dl,%eax
movzbl %cl,%ecx
cmovb  %eax,%ecx
mov    %cl,0x10(%rsp)
mov    %edi,%eax
shr    $0x1c,%eax
lea    0x37(%rax),%ecx
or     $0x30,%al
cmp    $0xa0000000,%edi
movzbl %al,%eax
movzbl %cl,%ecx
cmovb  %eax,%ecx
mov    %cl,0xf(%rsp)
lea    0xf(%rsp),%rdi
call   1030 <mesg@plt>
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
define void @phex(i64 %0) {
%2 = alloca [9 x i8]
%3 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 8
store i8 0, i8* %4
%5 = trunc i64 %0 to i32
%6 = trunc i64 %0 to i32
%7 = lshr i32 %6, 4
%8 = trunc i64 %0 to i32
%9 = lshr i32 %8, 8
%10 = trunc i64 %0 to i32
%11 = lshr i32 %10, 12
%12 = insertelement <4 x i32> poison, i32 %11, i64 0
%13 = insertelement <4 x i32> %12, i32 %9, i64 1
%14 = insertelement <4 x i32> %13, i32 %7, i64 2
%15 = insertelement <4 x i32> %14, i32 %5, i64 3
%16 = and <4 x i32> %15, <i32 15, i32 15, i32 15, i32 15>
%17 = icmp ult <4 x i32> %16, <i32 10, i32 10, i32 10, i32 10>
%18 = or <4 x i32> %16, <i32 48, i32 48, i32 48, i32 48>
%19 = add nuw nsw <4 x i32> %16, <i32 55, i32 55, i32 55, i32 55>
%20 = select <4 x i1> %17, <4 x i32> %18, <4 x i32> %19
%21 = trunc <4 x i32> %20 to <4 x i8>
%22 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 4
%23 = bitcast i8* %22 to <4 x i8>*
store <4 x i8> %21, <4 x i8>* %23
%24 = trunc i64 %0 to i32
%25 = lshr i32 %24, 16
%26 = and i32 %25, 15
%27 = icmp ult i32 %26, 10
%28 = or i32 %26, 48
%29 = add nuw nsw i32 %26, 55
%30 = select i1 %27, i32 %28, i32 %29
%31 = trunc i32 %30 to i8
%32 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 3
store i8 %31, i8* %32
%33 = trunc i64 %0 to i32
%34 = lshr i32 %33, 20
%35 = and i32 %34, 15
%36 = icmp ult i32 %35, 10
%37 = or i32 %35, 48
%38 = add nuw nsw i32 %35, 55
%39 = select i1 %36, i32 %37, i32 %38
%40 = trunc i32 %39 to i8
%41 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 2
store i8 %40, i8* %41
%42 = trunc i64 %0 to i32
%43 = lshr i32 %42, 24
%44 = and i32 %43, 15
%45 = icmp ult i32 %44, 10
%46 = or i32 %44, 48
%47 = add nuw nsw i32 %44, 55
%48 = select i1 %45, i32 %46, i32 %47
%49 = trunc i32 %48 to i8
%50 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 1
store i8 %49, i8* %50
%51 = trunc i64 %0 to i32
%52 = lshr i32 %51, 28
%53 = icmp ult i32 %51, -1610612736
%54 = or i32 %52, 48
%55 = add nuw nsw i32 %52, 55
%56 = select i1 %53, i32 %54, i32 %55
%57 = trunc i32 %56 to i8
store i8 %57, i8* %3
%58 = call i32 @mesg(i8* %3)
ret void
}