#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__ floor(double);
scalar_t__ isinf(double const);
scalar_t__ isnan(double const);
int /*<<< orphan*/ push_signed_int(char *, int, long);
int /*<<< orphan*/ push_unsigned_int(char *, int, unsigned long);
void pack_float(char *dest, int num_bits, const double precision,
                const long offset, int has_sign, const double val,
                char *nan_repr) {
  if (nan_repr && (isnan(val) || isinf(val))) {
    if (has_sign)
      push_signed_int(dest, num_bits, *(long *)(nan_repr));
    else
      push_unsigned_int(dest, num_bits, *(unsigned long *)(nan_repr));
  } else {
    if (has_sign)
      push_signed_int(dest, num_bits,
                      (long)(floor(0.5 + val / precision)) - offset);
    else
      push_unsigned_int(dest, num_bits,
                        (unsigned long)(floor(0.5 + val / precision)) - offset);
  }
}


x86 assembly (clang, -O0):
<pack_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movsd  %xmm1,-0x30(%rbp)
mov    %r8,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11e1 <pack_float+0x91>
movsd  -0x30(%rbp),%xmm0
call   1040 <isnan@plt>
cmp    $0x0,%rax
jne    11a7 <pack_float+0x57>
movsd  -0x30(%rbp),%xmm0
call   1070 <isinf@plt>
cmp    $0x0,%rax
je     11e1 <pack_float+0x91>
cmpl   $0x0,-0x24(%rbp)
je     11c9 <pack_float+0x79>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x38(%rbp),%rax
mov    (%rax),%rdx
call   1050 <push_signed_int@plt>
jmp    11dc <pack_float+0x8c>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x38(%rbp),%rax
mov    (%rax),%rdx
call   1030 <push_unsigned_int@plt>
jmp    126d <pack_float+0x11d>
cmpl   $0x0,-0x24(%rbp)
je     122c <pack_float+0xdc>
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x3c(%rbp)
movsd  -0x30(%rbp),%xmm1
divsd  -0x18(%rbp),%xmm1
movsd  0xdf5(%rip),%xmm0
addsd  %xmm1,%xmm0
call   1060 <floor@plt>
mov    -0x48(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    %rax,%rdx
sub    -0x20(%rbp),%rdx
call   1050 <push_signed_int@plt>
jmp    1268 <pack_float+0x118>
mov    -0x8(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x4c(%rbp)
movsd  -0x30(%rbp),%xmm1
divsd  -0x18(%rbp),%xmm1
movsd  0xdb4(%rip),%xmm0
addsd  %xmm1,%xmm0
call   1060 <floor@plt>
mov    -0x58(%rbp),%rdi
mov    -0x4c(%rbp),%esi
mov    %rax,%rdx
sub    -0x20(%rbp),%rdx
call   1030 <push_unsigned_int@plt>
jmp    126d <pack_float+0x11d>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pack_float>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%ebp
mov    %rdx,%r15
movsd  %xmm0,0x8(%rsp)
mov    %esi,%r14d
mov    %rdi,%r12
test   %r8,%r8
je     11a7 <pack_float+0x57>
mov    %r8,%rbx
movapd %xmm1,%xmm0
movsd  %xmm1,(%rsp)
call   1040 <isnan@plt>
movsd  (%rsp),%xmm0
test   %rax,%rax
jne    119c <pack_float+0x4c>
call   1070 <isinf@plt>
movsd  (%rsp),%xmm1
test   %rax,%rax
je     11a7 <pack_float+0x57>
mov    (%rbx),%rdx
mov    %r12,%rdi
mov    %r14d,%esi
jmp    11ca <pack_float+0x7a>
divsd  0x8(%rsp),%xmm1
addsd  0xe4b(%rip),%xmm1
movapd %xmm1,%xmm0
call   1060 <floor@plt>
sub    %r15,%rax
mov    %r12,%rdi
mov    %r14d,%esi
mov    %rax,%rdx
add    $0x10,%rsp
test   %ebp,%ebp
je     11df <pack_float+0x8f>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <push_signed_int@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <push_unsigned_int@plt>

LLVM IR (-O0):
define void @pack_float(i8* %0, i32 %1, double %2, i64 %3, i32 %4, double %5, i8* %6) {
%8 = alloca i8*
%9 = alloca i32
%10 = alloca double
%11 = alloca i64
%12 = alloca i32
%13 = alloca double
%14 = alloca i8*
store i8* %0, i8** %8
store i32 %1, i32* %9
store double %2, double* %10
store i64 %3, i64* %11
store i32 %4, i32* %12
store double %5, double* %13
store i8* %6, i8** %14
%15 = load i8*, i8** %14
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %43
17: ; preds = %7
%18 = load double, double* %13
%19 = call i64 @isnan(double %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %17
%22 = load double, double* %13
%23 = call i64 @isinf(double %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %43
25: ; preds = %21, %17
%26 = load i32, i32* %12
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %25
%29 = load i8*, i8** %8
%30 = load i32, i32* %9
%31 = load i8*, i8** %14
%32 = bitcast i8* %31 to i64*
%33 = load i64, i64* %32
%34 = call i32 @push_signed_int(i8* %29, i32 %30, i64 %33)
br label %42
35: ; preds = %25
%36 = load i8*, i8** %8
%37 = load i32, i32* %9
%38 = load i8*, i8** %14
%39 = bitcast i8* %38 to i64*
%40 = load i64, i64* %39
%41 = call i32 @push_unsigned_int(i8* %36, i32 %37, i64 %40)
br label %42
42: ; preds = %35, %28
br label %69
43: ; preds = %21, %7
%44 = load i32, i32* %12
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %57
46: ; preds = %43
%47 = load i8*, i8** %8
%48 = load i32, i32* %9
%49 = load double, double* %13
%50 = load double, double* %10
%51 = fdiv double %49, %50
%52 = fadd double 5.000000e-01, %51
%53 = call i64 @floor(double %52)
%54 = load i64, i64* %11
%55 = sub nsw i64 %53, %54
%56 = call i32 @push_signed_int(i8* %47, i32 %48, i64 %55)
br label %68
57: ; preds = %43
%58 = load i8*, i8** %8
%59 = load i32, i32* %9
%60 = load double, double* %13
%61 = load double, double* %10
%62 = fdiv double %60, %61
%63 = fadd double 5.000000e-01, %62
%64 = call i64 @floor(double %63)
%65 = load i64, i64* %11
%66 = sub i64 %64, %65
%67 = call i32 @push_unsigned_int(i8* %58, i32 %59, i64 %66)
br label %68
68: ; preds = %57, %46
br label %69
69: ; preds = %68, %42
ret void
}

LLVM IR (-O2):
define void @pack_float(i8* %0, i32 %1, double %2, i64 %3, i32 %4, double %5, i8* %6) {
%8 = icmp eq i8* %6, null
br i1 %8, label %23, label %9
9: ; preds = %7
%10 = tail call i64 @isnan(double %5)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = tail call i64 @isinf(double %5)
%14 = icmp eq i64 %13, 0
br i1 %14, label %23, label %15
15: ; preds = %12, %9
%16 = icmp eq i32 %4, 0
%17 = bitcast i8* %6 to i64*
%18 = load i64, i64* %17
br i1 %16, label %21, label %19
19: ; preds = %15
%20 = tail call i32 @push_signed_int(i8* %0, i32 %1, i64 %18)
br label %33
21: ; preds = %15
%22 = tail call i32 @push_unsigned_int(i8* %0, i32 %1, i64 %18)
br label %33
23: ; preds = %12, %7
%24 = icmp eq i32 %4, 0
%25 = fdiv double %5, %2
%26 = fadd double %25, 5.000000e-01
%27 = tail call i64 @floor(double %26)
%28 = sub i64 %27, %3
br i1 %24, label %31, label %29
29: ; preds = %23
%30 = tail call i32 @push_signed_int(i8* %0, i32 %1, i64 %28)
br label %33
31: ; preds = %23
%32 = tail call i32 @push_unsigned_int(i8* %0, i32 %1, i64 %28)
br label %33
33: ; preds = %29, %31, %19, %21
ret void
}