#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__ RKMem_Realloc_Func(float *, int, int, int);
scalar_t__ malloc(int);
void pirates_addfloat(float float_, float **float_array_ptr,
                      int *num_of_floats) {
  float *float_array = (*float_array_ptr);
  (*num_of_floats)++;
  if (float_array == NULL) {
    float_array = (float *)malloc(sizeof(float) * ((*num_of_floats)));
  } else {
    float_array = (float *)RKMem_Realloc_Func(
        float_array, sizeof(float) * ((*num_of_floats)),
        sizeof(float) * ((*num_of_floats) - 1), 1);
  }
  float_array[((*num_of_floats) - 1)] = float_;
  (*float_array_ptr) = float_array;
}


x86 assembly (clang, -O0):
<pirates_addfloat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
cmpq   $0x0,-0x20(%rbp)
jne    1171 <pirates_addfloat+0x51>
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
jmp    11a1 <pirates_addfloat+0x81>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
sub    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edx
mov    $0x1,%ecx
call   1040 <RKMem_Realloc_Func@plt>
mov    %rax,-0x20(%rbp)
movss  -0x4(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pirates_addfloat>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
movss  %xmm0,0x4(%rsp)
mov    (%rdi),%rdi
mov    (%rsi),%edx
lea    0x1(%rdx),%eax
mov    %eax,(%rsi)
lea    0x4(,%rdx,4),%esi
test   %rdi,%rdi
je     1155 <pirates_addfloat+0x35>
shl    $0x2,%edx
mov    $0x1,%ecx
call   1040 <RKMem_Realloc_Func@plt>
jmp    115c <pirates_addfloat+0x3c>
mov    %esi,%edi
call   1030 <malloc@plt>
movslq (%rbx),%rcx
movss  0x4(%rsp),%xmm0
movss  %xmm0,-0x4(%rax,%rcx,4)
mov    %rax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @pirates_addfloat(float %0, float** %1, i32* %2) {
%4 = alloca float
%5 = alloca float**
%6 = alloca i32*
%7 = alloca float*
store float %0, float* %4
store float** %1, float*** %5
store i32* %2, i32** %6
%8 = load float**, float*** %5
%9 = load float*, float** %8
store float* %9, float** %7
%10 = load i32*, i32** %6
%11 = load i32, i32* %10
%12 = add nsw i32 %11, 1
store i32 %12, i32* %10
%13 = load float*, float** %7
%14 = icmp eq float* %13, null
br i1 %14, label %15, label %23
15: ; preds = %3
%16 = load i32*, i32** %6
%17 = load i32, i32* %16
%18 = sext i32 %17 to i64
%19 = mul i64 4, %18
%20 = trunc i64 %19 to i32
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to float*
store float* %22, float** %7
br label %38
23: ; preds = %3
%24 = load float*, float** %7
%25 = load i32*, i32** %6
%26 = load i32, i32* %25
%27 = sext i32 %26 to i64
%28 = mul i64 4, %27
%29 = trunc i64 %28 to i32
%30 = load i32*, i32** %6
%31 = load i32, i32* %30
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = mul i64 4, %33
%35 = trunc i64 %34 to i32
%36 = call i64 @RKMem_Realloc_Func(float* %24, i32 %29, i32 %35, i32 1)
%37 = inttoptr i64 %36 to float*
store float* %37, float** %7
br label %38
38: ; preds = %23, %15
%39 = load float, float* %4
%40 = load float*, float** %7
%41 = load i32*, i32** %6
%42 = load i32, i32* %41
%43 = sub nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds float, float* %40, i64 %44
store float %39, float* %45
%46 = load float*, float** %7
%47 = load float**, float*** %5
store float* %46, float** %47
ret void
}

LLVM IR (-O2):
define void @pirates_addfloat(float %0, float** nocapture %1, i32* nocapture %2) {
%4 = load float*, float** %1
%5 = load i32, i32* %2
%6 = add nsw i32 %5, 1
store i32 %6, i32* %2
%7 = icmp eq float* %4, null
%8 = shl i32 %6, 2
br i1 %7, label %9, label %11
9: ; preds = %3
%10 = tail call i64 @malloc(i32 %8)
br label %14
11: ; preds = %3
%12 = shl i32 %5, 2
%13 = tail call i64 @RKMem_Realloc_Func(float* %4, i32 %8, i32 %12, i32 1)
br label %14
14: ; preds = %11, %9
%15 = phi i64 [ %10, %9 ], [ %13, %11 ]
%16 = inttoptr i64 %15 to float*
%17 = load i32, i32* %2
%18 = add nsw i32 %17, -1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds float, float* %16, i64 %19
store float %0, float* %20
store float* %16, float** %1
ret void
}