#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 frexp(float, int *);
void float2rgbe(unsigned char rgbe[4], float red, float green, float blue) {
  float v;
  int e;
  v = red;
  if (green > v)
    v = green;
  if (blue > v)
    v = blue;
  if (v < 1e-32) {
    rgbe[0] = rgbe[1] = rgbe[2] = rgbe[3] = 0;
  } else {
    v = frexp(v, &e) * 256.0 / v;
    rgbe[0] = (unsigned char)(red * v);
    rgbe[1] = (unsigned char)(green * v);
    rgbe[2] = (unsigned char)(blue * v);
    rgbe[3] = (unsigned char)(e + 128);
  }
}


x86 assembly (clang, -O0):
<float2rgbe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
movss  %xmm1,-0x10(%rbp)
movss  %xmm2,-0x14(%rbp)
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x10(%rbp),%xmm0
ucomiss -0x18(%rbp),%xmm0
jbe    114e <float2rgbe+0x3e>
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x14(%rbp),%xmm0
ucomiss -0x18(%rbp),%xmm0
jbe    1167 <float2rgbe+0x57>
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe88(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11a6 <float2rgbe+0x96>
mov    -0x8(%rbp),%rax
movb   $0x0,0x3(%rax)
mov    -0x8(%rbp),%rax
movb   $0x0,0x2(%rax)
mov    -0x8(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    1237 <float2rgbe+0x127>
movss  -0x18(%rbp),%xmm0
lea    -0x1c(%rbp),%rdi
call   1030 <frexp@plt>
movsd  0xe4c(%rip),%xmm1
mulsd  %xmm1,%xmm0
movss  -0x18(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
movss  -0x18(%rbp),%xmm1
mulss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
movss  -0x10(%rbp),%xmm0
movss  -0x18(%rbp),%xmm1
mulss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x1(%rax)
movss  -0x14(%rbp),%xmm0
movss  -0x18(%rbp),%xmm1
mulss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x1c(%rbp),%eax
add    $0x80,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x3(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<float2rgbe>:
push   %rbx
sub    $0x20,%rsp
movaps %xmm0,%xmm4
mov    %rdi,%rbx
movaps %xmm1,%xmm3
maxss  %xmm0,%xmm3
movaps %xmm2,%xmm0
maxss  %xmm3,%xmm0
cvtss2sd %xmm0,%xmm5
movsd  0xecb(%rip),%xmm3
ucomisd %xmm5,%xmm3
jbe    1143 <float2rgbe+0x33>
movl   $0x0,(%rbx)
jmp    11b2 <float2rgbe+0xa2>
lea    0x14(%rsp),%rdi
movss  %xmm2,0x10(%rsp)
movss  %xmm1,0xc(%rsp)
movss  %xmm4,0x8(%rsp)
movsd  %xmm5,0x18(%rsp)
call   1030 <frexp@plt>
mulsd  0xe9b(%rip),%xmm0
divsd  0x18(%rsp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  0x8(%rsp),%xmm1
mulss  %xmm0,%xmm1
cvttss2si %xmm1,%eax
mov    %al,(%rbx)
movss  0xc(%rsp),%xmm1
mulss  %xmm0,%xmm1
cvttss2si %xmm1,%eax
mov    %al,0x1(%rbx)
movss  0x10(%rsp),%xmm1
mulss  %xmm0,%xmm1
cvttss2si %xmm1,%eax
mov    %al,0x2(%rbx)
mov    0x14(%rsp),%al
xor    $0x80,%al
mov    %al,0x3(%rbx)
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @float2rgbe(i8* %0, float %1, float %2, float %3) {
%5 = alloca i8*
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca i32
store i8* %0, i8** %5
store float %1, float* %6
store float %2, float* %7
store float %3, float* %8
%11 = load float, float* %6
store float %11, float* %9
%12 = load float, float* %7
%13 = load float, float* %9
%14 = fcmp ogt float %12, %13
br i1 %14, label %15, label %17
15: ; preds = %4
%16 = load float, float* %7
store float %16, float* %9
br label %17
17: ; preds = %15, %4
%18 = load float, float* %8
%19 = load float, float* %9
%20 = fcmp ogt float %18, %19
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = load float, float* %8
store float %22, float* %9
br label %23
23: ; preds = %21, %17
%24 = load float, float* %9
%25 = fpext float %24 to double
%26 = fcmp olt double %25, 1.000000e-32
br i1 %26, label %27, label %36
27: ; preds = %23
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i64 3
store i8 0, i8* %29
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i64 2
store i8 0, i8* %31
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i64 1
store i8 0, i8* %33
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i64 0
store i8 0, i8* %35
br label %67
36: ; preds = %23
%37 = load float, float* %9
%38 = call double @frexp(float %37, i32* %10)
%39 = fmul double %38, 2.560000e+02
%40 = load float, float* %9
%41 = fpext float %40 to double
%42 = fdiv double %39, %41
%43 = fptrunc double %42 to float
store float %43, float* %9
%44 = load float, float* %6
%45 = load float, float* %9
%46 = fmul float %44, %45
%47 = fptoui float %46 to i8
%48 = load i8*, i8** %5
%49 = getelementptr inbounds i8, i8* %48, i64 0
store i8 %47, i8* %49
%50 = load float, float* %7
%51 = load float, float* %9
%52 = fmul float %50, %51
%53 = fptoui float %52 to i8
%54 = load i8*, i8** %5
%55 = getelementptr inbounds i8, i8* %54, i64 1
store i8 %53, i8* %55
%56 = load float, float* %8
%57 = load float, float* %9
%58 = fmul float %56, %57
%59 = fptoui float %58 to i8
%60 = load i8*, i8** %5
%61 = getelementptr inbounds i8, i8* %60, i64 2
store i8 %59, i8* %61
%62 = load i32, i32* %10
%63 = add nsw i32 %62, 128
%64 = trunc i32 %63 to i8
%65 = load i8*, i8** %5
%66 = getelementptr inbounds i8, i8* %65, i64 3
store i8 %64, i8* %66
br label %67
67: ; preds = %36, %27
ret void
}

LLVM IR (-O2):
define void @float2rgbe(i8* nocapture writeonly %0, float %1, float %2, float %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = fcmp ogt float %2, %1
%8 = select i1 %7, float %2, float %1
%9 = fcmp olt float %8, %3
%10 = select i1 %9, float %3, float %8
%11 = fpext float %10 to double
%12 = fcmp olt double %11, 1.000000e-32
br i1 %12, label %13, label %15
13: ; preds = %4
%14 = bitcast i8* %0 to i32*
store i32 0, i32* %14
br label %32
15: ; preds = %4
%16 = call double @frexp(float %10, i32* %5)
%17 = fmul double %16, 2.560000e+02
%18 = fdiv double %17, %11
%19 = fptrunc double %18 to float
%20 = fmul float %19, %1
%21 = fptoui float %20 to i8
store i8 %21, i8* %0
%22 = fmul float %19, %2
%23 = fptoui float %22 to i8
%24 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %23, i8* %24
%25 = fmul float %19, %3
%26 = fptoui float %25 to i8
%27 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %26, i8* %27
%28 = load i32, i32* %5
%29 = trunc i32 %28 to i8
%30 = xor i8 %29, -128
%31 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %30, i8* %31
br label %32
32: ; preds = %15, %13
ret void
}