#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 long luaI_collectgarbage();
void lua_pack(void) {
  static unsigned long block = 50;
  static unsigned long nentity = 0;
  unsigned long recovered = 0;
  if (nentity++ < block)
    return;
  recovered = luaI_collectgarbage();
  block = block * 2 * (1.0 - (float)recovered / nentity);
  nentity -= recovered;
}


x86 assembly (clang, -O0):
<lua_pack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x8(%rbp)
mov    0x2f11(%rip),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,0x2f03(%rip)
cmp    0x2eec(%rip),%rax
jae    1147 <lua_pack+0x37>
jmp    1278 <lua_pack+0x168>
xor    %eax,%eax
call   1030 <luaI_collectgarbage@plt>
mov    %rax,-0x8(%rbp)
mov    0x2ecf(%rip),%rax
add    %rax,%rax
movq   %rax,%xmm0
movaps 0xe98(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xe9c(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x10(%rbp)
test   %rax,%rax
movss  %xmm0,-0xc(%rbp)
js     11c5 <lua_pack+0xb5>
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
mov    0x2e62(%rip),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x20(%rbp)
test   %rax,%rax
movss  %xmm0,-0x1c(%rbp)
js     120f <lua_pack+0xff>
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movsd  -0x18(%rbp),%xmm0
movss  -0x24(%rbp),%xmm1
movss  -0x1c(%rbp),%xmm2
divss  %xmm2,%xmm1
cvtss2sd %xmm1,%xmm2
movsd  0xdf2(%rip),%xmm1
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
movsd  0xddb(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,0x2dc5(%rip)
mov    -0x8(%rbp),%rcx
mov    0x2dca(%rip),%rax
sub    %rcx,%rax
mov    %rax,0x2dc0(%rip)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lua_pack>:
push   %rax
mov    0x2f20(%rip),%rax
lea    0x1(%rax),%rcx
mov    %rcx,0x2f15(%rip)
cmp    0x2efe(%rip),%rax
jb     11fd <lua_pack+0xed>
xor    %eax,%eax
call   1030 <luaI_collectgarbage@plt>
mov    0x2eea(%rip),%rcx
add    %rcx,%rcx
movq   %rcx,%xmm2
punpckldq 0xeb2(%rip),%xmm2
subpd  0xeba(%rip),%xmm2
movapd %xmm2,%xmm0
unpckhpd %xmm2,%xmm0
test   %rax,%rax
js     116a <lua_pack+0x5a>
cvtsi2ss %rax,%xmm1
jmp    1181 <lua_pack+0x71>
mov    %rax,%rcx
shr    %rcx
mov    %eax,%edx
and    $0x1,%edx
or     %rcx,%rdx
cvtsi2ss %rdx,%xmm1
addss  %xmm1,%xmm1
addsd  %xmm2,%xmm0
mov    0x2eac(%rip),%rcx
test   %rcx,%rcx
js     119b <lua_pack+0x8b>
xorps  %xmm2,%xmm2
cvtsi2ss %rcx,%xmm2
jmp    11b5 <lua_pack+0xa5>
mov    %rcx,%rdx
shr    %rdx
mov    %ecx,%esi
and    $0x1,%esi
or     %rdx,%rsi
xorps  %xmm2,%xmm2
cvtsi2ss %rsi,%xmm2
addss  %xmm2,%xmm2
divss  %xmm2,%xmm1
cvtss2sd %xmm1,%xmm1
movsd  0xe5b(%rip),%xmm2
subsd  %xmm1,%xmm2
mulsd  %xmm0,%xmm2
cvttsd2si %xmm2,%rdx
mov    %rdx,%rsi
subsd  0xe4b(%rip),%xmm2
sar    $0x3f,%rsi
cvttsd2si %xmm2,%rdi
and    %rsi,%rdi
or     %rdx,%rdi
mov    %rdi,0x2e35(%rip)
sub    %rax,%rcx
mov    %rcx,0x2e3b(%rip)
pop    %rax
ret

LLVM IR (-O0):
@lua_pack.block = internal global i64 50
@lua_pack.nentity = internal global i64 0
define void @lua_pack() {
%1 = alloca i64
store i64 0, i64* %1
%2 = load i64, i64* @lua_pack.nentity
%3 = add i64 %2, 1
store i64 %3, i64* @lua_pack.nentity
%4 = load i64, i64* @lua_pack.block
%5 = icmp ult i64 %2, %4
br i1 %5, label %6, label %7
6: ; preds = %0
br label %24
7: ; preds = %0
%8 = call i64 (...) @luaI_collectgarbage()
store i64 %8, i64* %1
%9 = load i64, i64* @lua_pack.block
%10 = mul i64 %9, 2
%11 = uitofp i64 %10 to double
%12 = load i64, i64* %1
%13 = uitofp i64 %12 to float
%14 = load i64, i64* @lua_pack.nentity
%15 = uitofp i64 %14 to float
%16 = fdiv float %13, %15
%17 = fpext float %16 to double
%18 = fsub double 1.000000e+00, %17
%19 = fmul double %11, %18
%20 = fptoui double %19 to i64
store i64 %20, i64* @lua_pack.block
%21 = load i64, i64* %1
%22 = load i64, i64* @lua_pack.nentity
%23 = sub i64 %22, %21
store i64 %23, i64* @lua_pack.nentity
br label %24
24: ; preds = %7, %6
ret void
}

LLVM IR (-O2):
@lua_pack.block = internal unnamed_addr global i64 50
@lua_pack.nentity = internal unnamed_addr global i64 0
define void @lua_pack() {
%1 = load i64, i64* @lua_pack.nentity
%2 = add i64 %1, 1
store i64 %2, i64* @lua_pack.nentity
%3 = load i64, i64* @lua_pack.block
%4 = icmp ult i64 %1, %3
br i1 %4, label %19, label %5
5: ; preds = %0
%6 = tail call i64 (...) @luaI_collectgarbage()
%7 = load i64, i64* @lua_pack.block
%8 = shl i64 %7, 1
%9 = uitofp i64 %8 to double
%10 = uitofp i64 %6 to float
%11 = load i64, i64* @lua_pack.nentity
%12 = uitofp i64 %11 to float
%13 = fdiv float %10, %12
%14 = fpext float %13 to double
%15 = fsub double 1.000000e+00, %14
%16 = fmul double %15, %9
%17 = fptoui double %16 to i64
store i64 %17, i64* @lua_pack.block
%18 = sub i64 %11, %6
store i64 %18, i64* @lua_pack.nentity
br label %19
19: ; preds = %0, %5
ret void
}