#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 */
scalar_t__ 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 = (float)frexp(v, &e) * 256.0f / 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    1234 <float2rgbe+0x124>
movss  -0x18(%rbp),%xmm0
lea    -0x1c(%rbp),%rdi
call   1030 <frexp@plt>
cvtsi2ss %rax,%xmm0
movss  0xe47(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  -0x18(%rbp),%xmm1
divss  %xmm1,%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    0x1c(%rsp),%rdi
movss  %xmm2,0x18(%rsp)
movss  %xmm1,0x14(%rsp)
movss  %xmm4,0x10(%rsp)
movss  %xmm0,0xc(%rsp)
call   1030 <frexp@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
mulss  0xe93(%rip),%xmm0
divss  0xc(%rsp),%xmm0
movss  0x10(%rsp),%xmm1
mulss  %xmm0,%xmm1
cvttss2si %xmm1,%eax
mov    %al,(%rbx)
movss  0x14(%rsp),%xmm1
mulss  %xmm0,%xmm1
cvttss2si %xmm1,%eax
mov    %al,0x1(%rbx)
mulss  0x18(%rsp),%xmm0
cvttss2si %xmm0,%eax
mov    %al,0x2(%rbx)
mov    0x1c(%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 %66
36: ; preds = %23
%37 = load float, float* %9
%38 = call i64 @frexp(float %37, i32* %10)
%39 = sitofp i64 %38 to float
%40 = fmul float %39, 2.560000e+02
%41 = load float, float* %9
%42 = fdiv float %40, %41
store float %42, float* %9
%43 = load float, float* %6
%44 = load float, float* %9
%45 = fmul float %43, %44
%46 = fptoui float %45 to i8
%47 = load i8*, i8** %5
%48 = getelementptr inbounds i8, i8* %47, i64 0
store i8 %46, i8* %48
%49 = load float, float* %7
%50 = load float, float* %9
%51 = fmul float %49, %50
%52 = fptoui float %51 to i8
%53 = load i8*, i8** %5
%54 = getelementptr inbounds i8, i8* %53, i64 1
store i8 %52, i8* %54
%55 = load float, float* %8
%56 = load float, float* %9
%57 = fmul float %55, %56
%58 = fptoui float %57 to i8
%59 = load i8*, i8** %5
%60 = getelementptr inbounds i8, i8* %59, i64 2
store i8 %58, i8* %60
%61 = load i32, i32* %10
%62 = add nsw i32 %61, 128
%63 = trunc i32 %62 to i8
%64 = load i8*, i8** %5
%65 = getelementptr inbounds i8, i8* %64, i64 3
store i8 %63, i8* %65
br label %66
66: ; 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 i64 @frexp(float %10, i32* %5)
%17 = sitofp i64 %16 to float
%18 = fmul float %17, 2.560000e+02
%19 = fdiv float %18, %10
%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
}