#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 hue_to_rgb(float, float, float);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int);
void hsl_to_hex(char *hex, float hue, float sat, float light) {
  int r, g, b;
  float x, y;
  hue /= 360.0;
  sat /= 100.0;
  light /= 100.0;
  if (light < 0.5) {
    y = light * (1 + sat);
  } else {
    y = (light + sat) - (light * sat);
  }
  x = 2 * light - y;
  r = 255 * hue_to_rgb(x, y, hue + 1.0 / 3.0);
  g = 255 * hue_to_rgb(x, y, hue);
  b = 255 * hue_to_rgb(x, y, hue - 1.0 / 3.0);
  snprintf(hex, 8, "#%02X%02X%02X", r, g, b);
}


x86 assembly (clang, -O0):
<hsl_to_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
movss  %xmm1,-0x10(%rbp)
movss  %xmm2,-0x14(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xec4(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe9e(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe80(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe5a(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11d0 <hsl_to_hex+0xb0>
movss  -0x14(%rbp),%xmm0
movss  0xe63(%rip),%xmm1
addss  -0x10(%rbp),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x28(%rbp)
jmp    11fe <hsl_to_hex+0xde>
movss  -0x14(%rbp),%xmm1
addss  -0x10(%rbp),%xmm1
movss  -0x14(%rbp),%xmm0
movss  -0x10(%rbp),%xmm2
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x14(%rbp),%xmm0
movss  -0x28(%rbp),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
addss  %xmm0,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
movss  -0x28(%rbp),%xmm1
movss  -0xc(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
movsd  0xddb(%rip),%xmm3
addsd  %xmm3,%xmm2
cvtsd2ss %xmm2,%xmm2
call   1040 <hue_to_rgb@plt>
imul   $0xff,%eax,%eax
mov    %eax,-0x18(%rbp)
movss  -0x24(%rbp),%xmm0
movss  -0x28(%rbp),%xmm1
movss  -0xc(%rbp),%xmm2
call   1040 <hue_to_rgb@plt>
imul   $0xff,%eax,%eax
mov    %eax,-0x1c(%rbp)
movss  -0x24(%rbp),%xmm0
movss  -0x28(%rbp),%xmm1
movss  -0xc(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
movsd  0xd8d(%rip),%xmm3
subsd  %xmm3,%xmm2
cvtsd2ss %xmm2,%xmm2
call   1040 <hue_to_rgb@plt>
imul   $0xff,%eax,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x20(%rbp),%r9d
mov    $0x8,%esi
lea    0xd68(%rip),%rdx
call   1030 <snprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hsl_to_hex>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
movaps %xmm0,%xmm3
mov    %rdi,%r14
divss  0xeca(%rip),%xmm3
movss  0xec6(%rip),%xmm0
divss  %xmm0,%xmm1
divss  %xmm0,%xmm2
movss  0xeba(%rip),%xmm0
ucomiss %xmm2,%xmm0
jbe    1161 <hsl_to_hex+0x41>
addss  0xeb1(%rip),%xmm1
mulss  %xmm2,%xmm1
jmp    1170 <hsl_to_hex+0x50>
movaps %xmm2,%xmm0
mulss  %xmm1,%xmm0
addss  %xmm2,%xmm1
subss  %xmm0,%xmm1
addss  %xmm2,%xmm2
subss  %xmm1,%xmm2
xorps  %xmm0,%xmm0
cvtss2sd %xmm3,%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0xe83(%rip),%xmm4
addsd  %xmm0,%xmm4
movaps %xmm2,%xmm0
movss  %xmm2,0x10(%rsp)
xorps  %xmm2,%xmm2
cvtsd2ss %xmm4,%xmm2
movss  %xmm1,0xc(%rsp)
movss  %xmm3,0x14(%rsp)
call   1040 <hue_to_rgb@plt>
mov    %eax,%ebp
shl    $0x8,%ebp
sub    %eax,%ebp
movss  0x10(%rsp),%xmm0
movss  0xc(%rsp),%xmm1
movss  0x14(%rsp),%xmm2
call   1040 <hue_to_rgb@plt>
mov    %eax,%ebx
shl    $0x8,%ebx
sub    %eax,%ebx
movsd  0x18(%rsp),%xmm0
addsd  0xe33(%rip),%xmm0
xorps  %xmm2,%xmm2
cvtsd2ss %xmm0,%xmm2
movss  0x10(%rsp),%xmm0
movss  0xc(%rsp),%xmm1
call   1040 <hue_to_rgb@plt>
mov    %eax,%r9d
shl    $0x8,%r9d
sub    %eax,%r9d
lea    0xe12(%rip),%rdx
mov    %r14,%rdi
mov    $0x8,%esi
mov    %ebp,%ecx
mov    %ebx,%r8d
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <snprintf@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"#%02X%02X%02X\00"
define void @hsl_to_hex(i8* %0, float %1, float %2, float %3) {
%5 = alloca i8*
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca float
%13 = alloca float
store i8* %0, i8** %5
store float %1, float* %6
store float %2, float* %7
store float %3, float* %8
%14 = load float, float* %6
%15 = fpext float %14 to double
%16 = fdiv double %15, 3.600000e+02
%17 = fptrunc double %16 to float
store float %17, float* %6
%18 = load float, float* %7
%19 = fpext float %18 to double
%20 = fdiv double %19, 1.000000e+02
%21 = fptrunc double %20 to float
store float %21, float* %7
%22 = load float, float* %8
%23 = fpext float %22 to double
%24 = fdiv double %23, 1.000000e+02
%25 = fptrunc double %24 to float
store float %25, float* %8
%26 = load float, float* %8
%27 = fpext float %26 to double
%28 = fcmp olt double %27, 5.000000e-01
br i1 %28, label %29, label %34
29: ; preds = %4
%30 = load float, float* %8
%31 = load float, float* %7
%32 = fadd float 1.000000e+00, %31
%33 = fmul float %30, %32
store float %33, float* %13
br label %42
34: ; preds = %4
%35 = load float, float* %8
%36 = load float, float* %7
%37 = fadd float %35, %36
%38 = load float, float* %8
%39 = load float, float* %7
%40 = fneg float %38
%41 = call float @llvm.fmuladd.f32(float %40, float %39, float %37)
store float %41, float* %13
br label %42
42: ; preds = %34, %29
%43 = load float, float* %8
%44 = load float, float* %13
%45 = fneg float %44
%46 = call float @llvm.fmuladd.f32(float 2.000000e+00, float %43, float %45)
store float %46, float* %12
%47 = load float, float* %12
%48 = load float, float* %13
%49 = load float, float* %6
%50 = fpext float %49 to double
%51 = fadd double %50, 0x3FD5555555555555
%52 = fptrunc double %51 to float
%53 = call i32 @hue_to_rgb(float %47, float %48, float %52)
%54 = mul nsw i32 255, %53
store i32 %54, i32* %9
%55 = load float, float* %12
%56 = load float, float* %13
%57 = load float, float* %6
%58 = call i32 @hue_to_rgb(float %55, float %56, float %57)
%59 = mul nsw i32 255, %58
store i32 %59, i32* %10
%60 = load float, float* %12
%61 = load float, float* %13
%62 = load float, float* %6
%63 = fpext float %62 to double
%64 = fsub double %63, 0x3FD5555555555555
%65 = fptrunc double %64 to float
%66 = call i32 @hue_to_rgb(float %60, float %61, float %65)
%67 = mul nsw i32 255, %66
store i32 %67, i32* %11
%68 = load i8*, i8** %5
%69 = load i32, i32* %9
%70 = load i32, i32* %10
%71 = load i32, i32* %11
%72 = call i32 @snprintf(i8* %68, i32 8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %69, i32 %70, i32 %71)
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"#%02X%02X%02X\00"
define void @hsl_to_hex(i8* %0, float %1, float %2, float %3) {
%5 = fdiv float %1, 3.600000e+02
%6 = fdiv float %2, 1.000000e+02
%7 = fdiv float %3, 1.000000e+02
%8 = fcmp olt float %7, 5.000000e-01
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = fadd float %6, 1.000000e+00
%11 = fmul float %7, %10
br label %16
12: ; preds = %4
%13 = fadd float %6, %7
%14 = fneg float %7
%15 = tail call float @llvm.fmuladd.f32(float %14, float %6, float %13)
br label %16
16: ; preds = %12, %9
%17 = phi float [ %11, %9 ], [ %15, %12 ]
%18 = fneg float %17
%19 = tail call float @llvm.fmuladd.f32(float %7, float 2.000000e+00, float %18)
%20 = fpext float %5 to double
%21 = fadd double %20, 0x3FD5555555555555
%22 = fptrunc double %21 to float
%23 = tail call i32 @hue_to_rgb(float %19, float %17, float %22)
%24 = mul nsw i32 %23, 255
%25 = tail call i32 @hue_to_rgb(float %19, float %17, float %5)
%26 = mul nsw i32 %25, 255
%27 = fadd double %20, 0xBFD5555555555555
%28 = fptrunc double %27 to float
%29 = tail call i32 @hue_to_rgb(float %19, float %17, float %28)
%30 = mul nsw i32 %29, 255
%31 = tail call i32 @snprintf(i8* %0, i32 8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %24, i32 %26, i32 %30)
ret void
}