#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 */
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(float *, float const *, int);
int vec_pack(float *, int, float const *, int, float);
uint32_t vec_pack_auto(float *result, uint32_t result_capacity,
                       const float *data, uint32_t data_length,
                       float *threshold_p) {
  if (data_length <= result_capacity) {
    *threshold_p = 0;
    memcpy(result, data, data_length * sizeof(float));
    return data_length;
  }
  float thr = 0.1;
  uint32_t ref_pack_len;
  while (true) {
    ref_pack_len = vec_pack(result, result_capacity, data, data_length, thr);
    if (ref_pack_len <= result_capacity) {
      if (threshold_p != NULL)
        *threshold_p = thr;
      return ref_pack_len;
    } else {
      float r = (result_capacity / (float)ref_pack_len);
      if (r < 0.5) {
        thr += 0.8;
      } else if (r < 0.6) {
        thr += 0.5;
      } else if (r < 0.75) {
        thr += 0.4;
      } else if (r < 0.90) {
        thr += 0.25;
      } else {
        thr += 0.1;
      }
    }
  }
}


x86 assembly (clang, -O0):
<vec_pack_auto>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1173 <vec_pack_auto+0x53>
mov    -0x30(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    130c <vec_pack_auto+0x1ec>
movss  0xe85(%rip),%xmm0
movss  %xmm0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
movss  -0x34(%rbp),%xmm0
call   1030 <vec_pack@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11ca <vec_pack_auto+0xaa>
cmpq   $0x0,-0x30(%rbp)
je     11bf <vec_pack_auto+0x9f>
movss  -0x34(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    130c <vec_pack_auto+0x1ec>
cvtsi2ssl -0x14(%rbp),%xmm0
cvtsi2ssl -0x38(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x3c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe1a(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    121b <vec_pack_auto+0xfb>
movss  -0x34(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe37(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x34(%rbp)
jmp    1302 <vec_pack_auto+0x1e2>
movss  -0x3c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xde4(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1259 <vec_pack_auto+0x139>
movss  -0x34(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdc1(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x34(%rbp)
jmp    12fd <vec_pack_auto+0x1dd>
movss  -0x3c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xdae(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1297 <vec_pack_auto+0x177>
movss  -0x34(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdb3(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x34(%rbp)
jmp    12f8 <vec_pack_auto+0x1d8>
movss  -0x3c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xd78(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    12d5 <vec_pack_auto+0x1b5>
movss  -0x34(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd6d(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x34(%rbp)
jmp    12f3 <vec_pack_auto+0x1d3>
movss  -0x34(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd42(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x34(%rbp)
jmp    12f8 <vec_pack_auto+0x1d8>
jmp    12fd <vec_pack_auto+0x1dd>
jmp    1302 <vec_pack_auto+0x1e2>
jmp    1307 <vec_pack_auto+0x1e7>
jmp    1180 <vec_pack_auto+0x60>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vec_pack_auto>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8,%r14
mov    %ecx,%ebx
mov    %rdx,%r15
mov    %rdi,%r12
cmp    %esi,%ecx
jle    1250 <vec_pack_auto+0x130>
mov    %esi,%ebp
movss  0xeb7(%rip),%xmm0
mov    %r12,%rdi
mov    %r15,%rdx
mov    %ebx,%ecx
call   1030 <vec_pack@plt>
cmp    %ebp,%eax
jle    126b <vec_pack_auto+0x14b>
xorps  %xmm0,%xmm0
cvtsi2ss %ebp,%xmm0
movss  %xmm0,0xc(%rsp)
movss  0xe8d(%rip),%xmm0
movss  %xmm0,0x8(%rsp)
jmp    11b3 <vec_pack_auto+0x93>
nopl   0x0(%rax,%rax,1)
movss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
addsd  0xeae(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    %r12,%rdi
mov    %ebp,%esi
mov    %r15,%rdx
mov    %ebx,%ecx
movss  %xmm0,0x8(%rsp)
call   1030 <vec_pack@plt>
cmp    %ebp,%eax
jle    1279 <vec_pack_auto+0x159>
xorps  %xmm1,%xmm1
cvtsi2ss %eax,%xmm1
movss  0xc(%rsp),%xmm0
divss  %xmm1,%xmm0
movss  0xe38(%rip),%xmm1
ucomiss %xmm0,%xmm1
ja     1180 <vec_pack_auto+0x60>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  0xe30(%rip),%xmm2
ucomisd %xmm1,%xmm2
jbe    1200 <vec_pack_auto+0xe0>
movss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
addsd  0xe40(%rip),%xmm0
jmp    1192 <vec_pack_auto+0x72>
nopw   0x0(%rax,%rax,1)
movss  0xe00(%rip),%xmm2
ucomiss %xmm0,%xmm2
movss  0x8(%rsp),%xmm0
jbe    1224 <vec_pack_auto+0x104>
cvtss2sd %xmm0,%xmm0
addsd  0xe11(%rip),%xmm0
jmp    1192 <vec_pack_auto+0x72>
movsd  0xdec(%rip),%xmm2
ucomisd %xmm1,%xmm2
cvtss2sd %xmm0,%xmm0
jbe    1243 <vec_pack_auto+0x123>
addsd  0xdea(%rip),%xmm0
jmp    1192 <vec_pack_auto+0x72>
addsd  0xdd5(%rip),%xmm0
jmp    1192 <vec_pack_auto+0x72>
movl   $0x0,(%r14)
lea    0x0(,%rbx,4),%edx
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <memcpy@plt>
jmp    128b <vec_pack_auto+0x16b>
movss  0xd8d(%rip),%xmm0
movss  %xmm0,0x8(%rsp)
test   %r14,%r14
je     1289 <vec_pack_auto+0x169>
movss  0x8(%rsp),%xmm0
movss  %xmm0,(%r14)
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @vec_pack_auto(float* %0, i32 %1, float* %2, i32 %3, float* %4) {
%6 = alloca i32
%7 = alloca float*
%8 = alloca i32
%9 = alloca float*
%10 = alloca i32
%11 = alloca float*
%12 = alloca float
%13 = alloca i32
%14 = alloca float
store float* %0, float** %7
store i32 %1, i32* %8
store float* %2, float** %9
store i32 %3, i32* %10
store float* %4, float** %11
%15 = load i32, i32* %10
%16 = load i32, i32* %8
%17 = icmp sle i32 %15, %16
br i1 %17, label %18, label %28
18: ; preds = %5
%19 = load float*, float** %11
store float 0.000000e+00, float* %19
%20 = load float*, float** %7
%21 = load float*, float** %9
%22 = load i32, i32* %10
%23 = sext i32 %22 to i64
%24 = mul i64 %23, 4
%25 = trunc i64 %24 to i32
%26 = call i32 @memcpy(float* %20, float* %21, i32 %25)
%27 = load i32, i32* %10
store i32 %27, i32* %6
br label %98
28: ; preds = %5
store float 0x3FB99999A0000000, float* %12
br label %29
29: ; preds = %28, %97
%30 = load float*, float** %7
%31 = load i32, i32* %8
%32 = load float*, float** %9
%33 = load i32, i32* %10
%34 = load float, float* %12
%35 = call i32 @vec_pack(float* %30, i32 %31, float* %32, i32 %33, float %34)
store i32 %35, i32* %13
%36 = load i32, i32* %13
%37 = load i32, i32* %8
%38 = icmp sle i32 %36, %37
br i1 %38, label %39, label %47
39: ; preds = %29
%40 = load float*, float** %11
%41 = icmp ne float* %40, null
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load float, float* %12
%44 = load float*, float** %11
store float %43, float* %44
br label %45
45: ; preds = %42, %39
%46 = load i32, i32* %13
store i32 %46, i32* %6
br label %98
47: ; preds = %29
%48 = load i32, i32* %8
%49 = sitofp i32 %48 to float
%50 = load i32, i32* %13
%51 = sitofp i32 %50 to float
%52 = fdiv float %49, %51
store float %52, float* %14
%53 = load float, float* %14
%54 = fpext float %53 to double
%55 = fcmp olt double %54, 5.000000e-01
br i1 %55, label %56, label %61
56: ; preds = %47
%57 = load float, float* %12
%58 = fpext float %57 to double
%59 = fadd double %58, 8.000000e-01
%60 = fptrunc double %59 to float
store float %60, float* %12
br label %96
61: ; preds = %47
%62 = load float, float* %14
%63 = fpext float %62 to double
%64 = fcmp olt double %63, 6.000000e-01
br i1 %64, label %65, label %70
65: ; preds = %61
%66 = load float, float* %12
%67 = fpext float %66 to double
%68 = fadd double %67, 5.000000e-01
%69 = fptrunc double %68 to float
store float %69, float* %12
br label %95
70: ; preds = %61
%71 = load float, float* %14
%72 = fpext float %71 to double
%73 = fcmp olt double %72, 7.500000e-01
br i1 %73, label %74, label %79
74: ; preds = %70
%75 = load float, float* %12
%76 = fpext float %75 to double
%77 = fadd double %76, 4.000000e-01
%78 = fptrunc double %77 to float
store float %78, float* %12
br label %94
79: ; preds = %70
%80 = load float, float* %14
%81 = fpext float %80 to double
%82 = fcmp olt double %81, 9.000000e-01
br i1 %82, label %83, label %88
83: ; preds = %79
%84 = load float, float* %12
%85 = fpext float %84 to double
%86 = fadd double %85, 2.500000e-01
%87 = fptrunc double %86 to float
store float %87, float* %12
br label %93
88: ; preds = %79
%89 = load float, float* %12
%90 = fpext float %89 to double
%91 = fadd double %90, 1.000000e-01
%92 = fptrunc double %91 to float
store float %92, float* %12
br label %93
93: ; preds = %88, %83
br label %94
94: ; preds = %93, %74
br label %95
95: ; preds = %94, %65
br label %96
96: ; preds = %95, %56
br label %97
97: ; preds = %96
br label %29
98: ; preds = %45, %18
%99 = load i32, i32* %6
ret i32 %99
}

LLVM IR (-O2):
define i32 @vec_pack_auto(float* %0, i32 %1, float* %2, i32 %3, float* writeonly %4) {
%6 = icmp sgt i32 %3, %1
br i1 %6, label %7, label %12
7: ; preds = %5
%8 = tail call i32 @vec_pack(float* %0, i32 %1, float* %2, i32 %3, float 0x3FB99999A0000000)
%9 = icmp sgt i32 %8, %1
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = sitofp i32 %1 to float
br label %20
12: ; preds = %5
store float 0.000000e+00, float* %4
%13 = shl i32 %3, 2
%14 = tail call i32 @memcpy(float* %0, float* %2, i32 %13)
br label %52
15: ; preds = %47, %7
%16 = phi float [ 0x3FB99999A0000000, %7 ], [ %49, %47 ]
%17 = phi i32 [ %8, %7 ], [ %50, %47 ]
%18 = icmp eq float* %4, null
br i1 %18, label %52, label %19
19: ; preds = %15
store float %16, float* %4
br label %52
20: ; preds = %10, %47
%21 = phi i32 [ %8, %10 ], [ %50, %47 ]
%22 = phi float [ 0x3FB99999A0000000, %10 ], [ %49, %47 ]
%23 = sitofp i32 %21 to float
%24 = fdiv float %11, %23
%25 = fpext float %24 to double
%26 = fcmp olt float %24, 5.000000e-01
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = fpext float %22 to double
%29 = fadd double %28, 8.000000e-01
br label %47
30: ; preds = %20
%31 = fcmp olt double %25, 6.000000e-01
br i1 %31, label %32, label %35
32: ; preds = %30
%33 = fpext float %22 to double
%34 = fadd double %33, 5.000000e-01
br label %47
35: ; preds = %30
%36 = fcmp olt float %24, 7.500000e-01
br i1 %36, label %37, label %40
37: ; preds = %35
%38 = fpext float %22 to double
%39 = fadd double %38, 4.000000e-01
br label %47
40: ; preds = %35
%41 = fcmp olt double %25, 9.000000e-01
%42 = fpext float %22 to double
br i1 %41, label %43, label %45
43: ; preds = %40
%44 = fadd double %42, 2.500000e-01
br label %47
45: ; preds = %40
%46 = fadd double %42, 1.000000e-01
br label %47
47: ; preds = %32, %43, %45, %37, %27
%48 = phi double [ %29, %27 ], [ %34, %32 ], [ %39, %37 ], [ %44, %43 ], [ %46, %45 ]
%49 = fptrunc double %48 to float
%50 = tail call i32 @vec_pack(float* %0, i32 %1, float* %2, i32 %3, float %49)
%51 = icmp sgt i32 %50, %1
br i1 %51, label %20, label %15
52: ; preds = %15, %19, %12
%53 = phi i32 [ %3, %12 ], [ %17, %19 ], [ %17, %15 ]
ret i32 %53
}