#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__ realloc(double *, int);
void push(double *stack, int *pos, double num, int *stacksize) {
  if ((*pos) + 1 >= *stacksize) {
    *stacksize += 10;
    stack = (double *)realloc(stack, sizeof(double) * *stacksize);
  }
  (*pos)++;
  stack[*pos] = num;
}


x86 assembly (clang, -O0):
<push>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jl     1163 <push+0x53>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0xa,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq (%rax),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1030 <realloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
movsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
movsd  %xmm0,(%rax,%rcx,8)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<push>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    (%rsi),%eax
add    $0x1,%eax
mov    (%rdx),%ecx
cmp    %ecx,%eax
jl     1148 <push+0x38>
lea    0xa(%rcx),%eax
mov    %eax,(%rdx)
lea    0x50(,%rcx,8),%esi
movsd  %xmm0,0x8(%rsp)
call   1030 <realloc@plt>
movsd  0x8(%rsp),%xmm0
mov    %rax,%rdi
mov    (%rbx),%eax
add    $0x1,%eax
mov    %eax,(%rbx)
cltq
movsd  %xmm0,(%rdi,%rax,8)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @push(double* %0, i32* %1, double %2, i32* %3) {
%5 = alloca double*
%6 = alloca i32*
%7 = alloca double
%8 = alloca i32*
store double* %0, double** %5
store i32* %1, i32** %6
store double %2, double* %7
store i32* %3, i32** %8
%9 = load i32*, i32** %6
%10 = load i32, i32* %9
%11 = add nsw i32 %10, 1
%12 = load i32*, i32** %8
%13 = load i32, i32* %12
%14 = icmp sge i32 %11, %13
br i1 %14, label %15, label %27
15: ; preds = %4
%16 = load i32*, i32** %8
%17 = load i32, i32* %16
%18 = add nsw i32 %17, 10
store i32 %18, i32* %16
%19 = load double*, double** %5
%20 = load i32*, i32** %8
%21 = load i32, i32* %20
%22 = sext i32 %21 to i64
%23 = mul i64 8, %22
%24 = trunc i64 %23 to i32
%25 = call i64 @realloc(double* %19, i32 %24)
%26 = inttoptr i64 %25 to double*
store double* %26, double** %5
br label %27
27: ; preds = %15, %4
%28 = load i32*, i32** %6
%29 = load i32, i32* %28
%30 = add nsw i32 %29, 1
store i32 %30, i32* %28
%31 = load double, double* %7
%32 = load double*, double** %5
%33 = load i32*, i32** %6
%34 = load i32, i32* %33
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %32, i64 %35
store double %31, double* %36
ret void
}

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