#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 */
double fabs(double);
double floor(double);
void ihex(double x, int nhx, char chx[]) {
  int i;
  double y;
  char hx[] = "0123456789ABCDEF";
  y = fabs(x);
  for (i = 0; i < nhx; i++) {
    y = 16. * (y - floor(y));
    chx[i] = hx[(int)y];
  }
}


x86 assembly (clang, -O0):
<ihex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0xef5(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xef2(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xef0(%rip),%al
mov    %al,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
movaps 0xeb1(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11bd <ihex+0xad>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <floor@plt>
movsd  -0x48(%rbp),%xmm1
subsd  %xmm0,%xmm1
movsd  0xe80(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
cvttsd2si -0x28(%rbp),%eax
cltq
mov    -0x40(%rbp,%rax,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115f <ihex+0x4f>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ihex>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %edi,%edi
jle    120a <ihex+0xfa>
mov    %rsi,%r14
andpd  0xed0(%rip),%xmm0
mov    %edi,%r15d
cmp    $0x1,%edi
jne    113f <ihex+0x2f>
xor    %ebx,%ebx
jmp    11d5 <ihex+0xc5>
mov    %r15d,%r12d
and    $0xfffffffe,%r12d
xor    %ebx,%ebx
lea    0xed1(%rip),%r13
nop
movapd %xmm0,(%rsp)
movapd (%rsp),%xmm0
call   1030 <floor@plt>
movapd (%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,(%rsp)
movapd (%rsp),%xmm0
movsd  0xe96(%rip),%xmm1
mulsd  %xmm1,%xmm0
movapd %xmm0,(%rsp)
cvttsd2si (%rsp),%eax
cltq
movzbl (%rax,%r13,1),%eax
mov    %al,(%r14,%rbx,1)
movapd (%rsp),%xmm0
call   1030 <floor@plt>
movapd (%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,(%rsp)
movapd (%rsp),%xmm0
mulsd  0xe58(%rip),%xmm0
cvttsd2si %xmm0,%eax
cltq
movzbl (%rax,%r13,1),%eax
mov    %al,0x1(%r14,%rbx,1)
add    $0x2,%rbx
cmp    %rbx,%r12
jne    1150 <ihex+0x40>
test   $0x1,%r15b
je     120a <ihex+0xfa>
movapd %xmm0,(%rsp)
call   1030 <floor@plt>
movapd (%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  0xe1a(%rip),%xmm1
cvttsd2si %xmm1,%eax
cltq
lea    0xe1d(%rip),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,(%r14,%rbx,1)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.ihex.hx = [17 x i8] c"0123456789ABCDEF\00"
define void @ihex(double %0, i32 %1, i8* %2) {
%4 = alloca double
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca double
%9 = alloca [17 x i8]
store double %0, double* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%10 = bitcast [17 x i8]* %9 to i8*
%11 = load double, double* %4
%12 = call double @llvm.fabs.f64(double %11)
store double %12, double* %8
store i32 0, i32* %7
br label %13
13: ; preds = %32, %3
%14 = load i32, i32* %7
%15 = load i32, i32* %5
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %35
17: ; preds = %13
%18 = load double, double* %8
%19 = load double, double* %8
%20 = call double @llvm.floor.f64(double %19)
%21 = fsub double %18, %20
%22 = fmul double 1.600000e+01, %21
store double %22, double* %8
%23 = load double, double* %8
%24 = fptosi double %23 to i32
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [17 x i8], [17 x i8]* %9, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = load i8*, i8** %6
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 %27, i8* %31
br label %32
32: ; preds = %17
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %13
35: ; preds = %13
ret void
}

LLVM IR (-O2):
@__const.ihex.hx = [17 x i8] c"0123456789ABCDEF\00"
define void @ihex(double %0, i32 %1, i8* nocapture writeonly %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %49
5: ; preds = %3
%6 = tail call double @llvm.fabs.f64(double %0)
%7 = zext i32 %1 to i64
%8 = and i64 %7, 1
%9 = icmp eq i32 %1, 1
br i1 %9, label %36, label %10
10: ; preds = %5
%11 = and i64 %7, 4294967294
br label %12
12: ; preds = %12, %10
%13 = phi i64 [ 0, %10 ], [ %33, %12 ]
%14 = phi double [ %6, %10 ], [ %27, %12 ]
%15 = phi i64 [ 0, %10 ], [ %34, %12 ]
%16 = tail call double @llvm.floor.f64(double %14)
%17 = fsub double %14, %16
%18 = fmul double %17, 1.600000e+01
%19 = fptosi double %18 to i32
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.ihex.hx, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = getelementptr inbounds i8, i8* %2, i64 %13
store i8 %22, i8* %23
%24 = or i64 %13, 1
%25 = tail call double @llvm.floor.f64(double %18)
%26 = fsub double %18, %25
%27 = fmul double %26, 1.600000e+01
%28 = fptosi double %27 to i32
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.ihex.hx, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = getelementptr inbounds i8, i8* %2, i64 %24
store i8 %31, i8* %32
%33 = add nuw nsw i64 %13, 2
%34 = add i64 %15, 2
%35 = icmp eq i64 %34, %11
br i1 %35, label %36, label %12
36: ; preds = %12, %5
%37 = phi i64 [ 0, %5 ], [ %33, %12 ]
%38 = phi double [ %6, %5 ], [ %27, %12 ]
%39 = icmp eq i64 %8, 0
br i1 %39, label %49, label %40
40: ; preds = %36
%41 = tail call double @llvm.floor.f64(double %38)
%42 = fsub double %38, %41
%43 = fmul double %42, 1.600000e+01
%44 = fptosi double %43 to i32
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.ihex.hx, i64 0, i64 %45
%47 = load i8, i8* %46
%48 = getelementptr inbounds i8, i8* %2, i64 %37
store i8 %47, i8* %48
br label %49
49: ; preds = %40, %36, %3
ret void
}