#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 */
unsigned int SCE_Encode_GetFloatData(float, int *, float *);
unsigned char *SCE_Encode_Write(unsigned long, int *, unsigned char,
                                unsigned char *);
int SCE_Encode_Float(float a, int se, unsigned char ne, unsigned char nm,
                     int *offset, unsigned char **out) {
  unsigned int s;
  int e;
  float fm;
  unsigned long m;
  unsigned int max_e;
  s = SCE_Encode_GetFloatData(a, &e, &fm);
  max_e = (unsigned int)(1 << (ne - 1));
  if (se)
    e += (int)(max_e / 2u);
  if (e < 0) {
    e = 0;
    s = 0;
    m = 0;
  } else {
    m = (unsigned long)(fm * (float)(1 << (nm - 1)));
  }
  *out = SCE_Encode_Write(s, offset, 1, *out);
  *out = SCE_Encode_Write(e, offset, ne, *out);
  *out = SCE_Encode_Write(m, offset, nm, *out);
  return 0;
}


x86 assembly (clang, -O0):
<SCE_Encode_Float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dl,%al
mov    %sil,%dl
movss  %xmm0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %dl,-0x9(%rbp)
mov    %al,-0xa(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
movss  -0x4(%rbp),%xmm0
lea    -0x28(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
call   1040 <SCE_Encode_GetFloatData@plt>
mov    %eax,-0x24(%rbp)
movzbl -0x9(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     117f <SCE_Encode_Float+0x5f>
mov    -0x3c(%rbp),%eax
shr    $0x1,%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    11a4 <SCE_Encode_Float+0x84>
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x38(%rbp)
jmp    11e8 <SCE_Encode_Float+0xc8>
movss  -0x2c(%rbp),%xmm0
mov    -0xa(%rbp),%cl
add    $0xff,%cl
mov    $0x1,%eax
shl    %cl,%eax
cvtsi2ss %eax,%xmm1
mulss  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttss2si %xmm1,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
movss  0xe2b(%rip),%xmm1
subss  %xmm1,%xmm0
cvttss2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
mov    $0x1,%edx
call   1030 <SCE_Encode_Write@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movslq -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x9(%rbp),%al
mov    -0x20(%rbp),%rcx
mov    (%rcx),%rcx
movzbl %al,%edx
call   1030 <SCE_Encode_Write@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xa(%rbp),%al
mov    -0x20(%rbp),%rcx
mov    (%rcx),%rcx
movzbl %al,%edx
call   1030 <SCE_Encode_Write@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SCE_Encode_Float>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8,%r13
mov    %rcx,%r14
mov    %edx,%r15d
mov    %esi,%r12d
mov    %edi,%ebx
lea    0x8(%rsp),%rdi
lea    0xc(%rsp),%rsi
call   1040 <SCE_Encode_GetFloatData@plt>
test   %ebx,%ebx
je     11a3 <SCE_Encode_Float+0x83>
lea    -0x1(%r12),%ecx
mov    $0x1,%edx
shl    %cl,%edx
shr    %edx
add    0x8(%rsp),%edx
mov    %edx,0x8(%rsp)
test   %edx,%edx
js     11ab <SCE_Encode_Float+0x8b>
lea    -0x1(%r15),%ecx
mov    $0x1,%edx
shl    %cl,%edx
xorps  %xmm0,%xmm0
cvtsi2ss %edx,%xmm0
mulss  0xc(%rsp),%xmm0
cvttss2si %xmm0,%rcx
mov    %rcx,%rdx
subss  0xe70(%rip),%xmm0
cvttss2si %xmm0,%rbx
sar    $0x3f,%rdx
and    %rdx,%rbx
or     %rcx,%rbx
mov    %eax,%edi
jmp    11b7 <SCE_Encode_Float+0x97>
mov    0x8(%rsp),%edx
test   %edx,%edx
jns    1168 <SCE_Encode_Float+0x48>
movl   $0x0,0x8(%rsp)
xor    %ebx,%ebx
xor    %edi,%edi
mov    0x0(%r13),%rcx
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <SCE_Encode_Write@plt>
mov    %rax,0x0(%r13)
movslq 0x8(%rsp),%rdi
movzbl %r12b,%edx
mov    %r14,%rsi
mov    %rax,%rcx
call   1030 <SCE_Encode_Write@plt>
mov    %rax,0x0(%r13)
movzbl %r15b,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rax,%rcx
call   1030 <SCE_Encode_Write@plt>
mov    %rax,0x0(%r13)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @SCE_Encode_Float(float %0, i32 %1, i8 zeroext %2, i8 zeroext %3, i32* %4, i8** %5) {
%7 = alloca float
%8 = alloca i32
%9 = alloca i8
%10 = alloca i8
%11 = alloca i32*
%12 = alloca i8**
%13 = alloca i32
%14 = alloca i32
%15 = alloca float
%16 = alloca i64
%17 = alloca i32
store float %0, float* %7
store i32 %1, i32* %8
store i8 %2, i8* %9
store i8 %3, i8* %10
store i32* %4, i32** %11
store i8** %5, i8*** %12
%18 = load float, float* %7
%19 = call i32 @SCE_Encode_GetFloatData(float %18, i32* %14, float* %15)
store i32 %19, i32* %13
%20 = load i8, i8* %9
%21 = zext i8 %20 to i32
%22 = sub nsw i32 %21, 1
%23 = shl i32 1, %22
store i32 %23, i32* %17
%24 = load i32, i32* %8
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %6
%27 = load i32, i32* %17
%28 = udiv i32 %27, 2
%29 = load i32, i32* %14
%30 = add nsw i32 %29, %28
store i32 %30, i32* %14
br label %31
31: ; preds = %26, %6
%32 = load i32, i32* %14
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %31
store i32 0, i32* %14
store i32 0, i32* %13
store i64 0, i64* %16
br label %44
35: ; preds = %31
%36 = load float, float* %15
%37 = load i8, i8* %10
%38 = zext i8 %37 to i32
%39 = sub nsw i32 %38, 1
%40 = shl i32 1, %39
%41 = sitofp i32 %40 to float
%42 = fmul float %36, %41
%43 = fptoui float %42 to i64
store i64 %43, i64* %16
br label %44
44: ; preds = %35, %34
%45 = load i32, i32* %13
%46 = zext i32 %45 to i64
%47 = load i32*, i32** %11
%48 = load i8**, i8*** %12
%49 = load i8*, i8** %48
%50 = call i8* @SCE_Encode_Write(i64 %46, i32* %47, i8 zeroext 1, i8* %49)
%51 = load i8**, i8*** %12
store i8* %50, i8** %51
%52 = load i32, i32* %14
%53 = sext i32 %52 to i64
%54 = load i32*, i32** %11
%55 = load i8, i8* %9
%56 = load i8**, i8*** %12
%57 = load i8*, i8** %56
%58 = call i8* @SCE_Encode_Write(i64 %53, i32* %54, i8 zeroext %55, i8* %57)
%59 = load i8**, i8*** %12
store i8* %58, i8** %59
%60 = load i64, i64* %16
%61 = load i32*, i32** %11
%62 = load i8, i8* %10
%63 = load i8**, i8*** %12
%64 = load i8*, i8** %63
%65 = call i8* @SCE_Encode_Write(i64 %60, i32* %61, i8 zeroext %62, i8* %64)
%66 = load i8**, i8*** %12
store i8* %65, i8** %66
ret i32 0
}

LLVM IR (-O2):
define i32 @SCE_Encode_Float(float %0, i32 %1, i8 zeroext %2, i8 zeroext %3, i32* %4, i8** nocapture %5) {
%7 = alloca i32
%8 = alloca float
%9 = bitcast i32* %7 to i8*
%10 = bitcast float* %8 to i8*
%11 = call i32 @SCE_Encode_GetFloatData(float %0, i32* %7, float* %8)
%12 = icmp eq i32 %1, 0
br i1 %12, label %20, label %13
13: ; preds = %6
%14 = zext i8 %2 to i32
%15 = add nsw i32 %14, -1
%16 = shl nuw i32 1, %15
%17 = lshr i32 %16, 1
%18 = load i32, i32* %7
%19 = add nsw i32 %18, %17
store i32 %19, i32* %7
br label %22
20: ; preds = %6
%21 = load i32, i32* %7
br label %22
22: ; preds = %20, %13
%23 = phi i32 [ %21, %20 ], [ %19, %13 ]
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 0, i32* %7
br label %35
26: ; preds = %22
%27 = load float, float* %8
%28 = zext i8 %3 to i32
%29 = add nsw i32 %28, -1
%30 = shl nuw i32 1, %29
%31 = sitofp i32 %30 to float
%32 = fmul float %27, %31
%33 = fptoui float %32 to i64
%34 = zext i32 %11 to i64
br label %35
35: ; preds = %26, %25
%36 = phi i64 [ 0, %25 ], [ %33, %26 ]
%37 = phi i64 [ 0, %25 ], [ %34, %26 ]
%38 = load i8*, i8** %5
%39 = call i8* @SCE_Encode_Write(i64 %37, i32* %4, i8 zeroext 1, i8* %38)
store i8* %39, i8** %5
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = call i8* @SCE_Encode_Write(i64 %41, i32* %4, i8 zeroext %2, i8* %39)
store i8* %42, i8** %5
%43 = call i8* @SCE_Encode_Write(i64 %36, i32* %4, i8 zeroext %3, i8* %42)
store i8* %43, i8** %5
ret i32 0
}