; LLVM IR from caryll/otfcc :: lib/table (fvar)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.__caryll_vectorinterface_VQ = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.VQ = type { double, %struct.vq_SegList }
%struct.vq_SegList = type { i64, i64, ptr }
%struct.vq_Segment = type { i32, %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { double, i8, ptr }

@iVQ = external constant %struct.__caryll_vectorinterface_VQ, align 8

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare ptr @json_array_new(i64 noundef) #1

declare ptr @json_array_push(ptr noundef, ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @preserialize(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @json_new_VQSegment(ptr noundef, ptr noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @json_new_position(double noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @json_new_VQ(ptr noundef byval(%struct.VQ) align 8 %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.VQ, ptr %0, i32 0, i32 1
  %8 = getelementptr inbounds %struct.vq_SegList, ptr %7, i32 0, i32 0
  %9 = load i64, ptr %8, align 8, !tbaa !9
  %10 = icmp ne i64 %9, 0
  br i1 %10, label %16, label %11

11:                                               ; preds = %2
  %12 = load ptr, ptr getelementptr inbounds (%struct.__caryll_vectorinterface_VQ, ptr @iVQ, i32 0, i32 22), align 8, !tbaa !14
  %13 = call double %12(ptr noundef byval(%struct.VQ) align 8 %0)
  %14 = call ptr @json_new_position(double noundef %13)
  %15 = call ptr @preserialize(ptr noundef %14)
  store ptr %15, ptr %3, align 8
  br label %50

16:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %17 = getelementptr inbounds %struct.VQ, ptr %0, i32 0, i32 1
  %18 = getelementptr inbounds %struct.vq_SegList, ptr %17, i32 0, i32 0
  %19 = load i64, ptr %18, align 8, !tbaa !9
  %20 = add i64 %19, 1
  %21 = call ptr @json_array_new(i64 noundef %20)
  store ptr %21, ptr %5, align 8, !tbaa !5
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.VQ, ptr %0, i32 0, i32 0
  %24 = load double, ptr %23, align 8, !tbaa !16
  %25 = call ptr @json_new_position(double noundef %24)
  %26 = call ptr @json_array_push(ptr noundef %22, ptr noundef %25)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 0, ptr %6, align 8, !tbaa !17
  br label %27

27:                                               ; preds = %44, %16
  %28 = load i64, ptr %6, align 8, !tbaa !17
  %29 = getelementptr inbounds %struct.VQ, ptr %0, i32 0, i32 1
  %30 = getelementptr inbounds %struct.vq_SegList, ptr %29, i32 0, i32 0
  %31 = load i64, ptr %30, align 8, !tbaa !9
  %32 = icmp ult i64 %28, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %47

34:                                               ; preds = %27
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.VQ, ptr %0, i32 0, i32 1
  %37 = getelementptr inbounds %struct.vq_SegList, ptr %36, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !18
  %39 = load i64, ptr %6, align 8, !tbaa !17
  %40 = getelementptr inbounds %struct.vq_Segment, ptr %38, i64 %39
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = call ptr @json_new_VQSegment(ptr noundef %40, ptr noundef %41)
  %43 = call ptr @json_array_push(ptr noundef %35, ptr noundef %42)
  br label %44

44:                                               ; preds = %34
  %45 = load i64, ptr %6, align 8, !tbaa !17
  %46 = add i64 %45, 1
  store i64 %46, ptr %6, align 8, !tbaa !17
  br label %27, !llvm.loop !19

47:                                               ; preds = %33
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = call ptr @preserialize(ptr noundef %48)
  store ptr %49, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %50

50:                                               ; preds = %47, %11
  %51 = load ptr, ptr %3, align 8
  ret ptr %51
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { inlinehint nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !13, i64 8}
!10 = !{!"", !11, i64 0, !12, i64 8}
!11 = !{!"double", !7, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 8, !6, i64 16}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !6, i64 176}
!15 = !{!"__caryll_vectorinterface_VQ", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216}
!16 = !{!10, !11, i64 0}
!17 = !{!13, !13, i64 0}
!18 = !{!10, !6, i64 24}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.__caryll_vectorinterface_VQ = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.VQ = type { double, %struct.vq_SegList }
%struct.vq_SegList = type { i64, i64, ptr }
%struct.vq_Segment = type { i32, %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { double, i8, ptr }

@iVQ = external local_unnamed_addr constant %struct.__caryll_vectorinterface_VQ, align 8

declare ptr @json_array_new(i64 noundef) local_unnamed_addr #0

declare ptr @json_array_push(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @preserialize(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @json_new_VQSegment(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @json_new_position(double noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @json_new_VQ(ptr noundef byval(%struct.VQ) align 8 %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %5, label %.lr.ph

5:                                                ; preds = %2
  %6 = load ptr, ptr getelementptr inbounds (i8, ptr @iVQ, i64 176), align 8, !tbaa !13
  %7 = tail call double %6(ptr noundef nonnull byval(%struct.VQ) align 8 %0) #3
  %8 = tail call ptr @json_new_position(double noundef %7)
  br label %._crit_edge

.lr.ph:                                           ; preds = %2
  %9 = add i64 %4, 1
  %10 = tail call ptr @json_array_new(i64 noundef %9) #3
  %11 = load double, ptr %0, align 8, !tbaa !15
  %12 = tail call ptr @json_new_position(double noundef %11)
  %13 = tail call ptr @json_array_push(ptr noundef %10, ptr noundef %12) #3
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  %.pre = load ptr, ptr %14, align 8, !tbaa !16
  br label %15

15:                                               ; preds = %.lr.ph, %15
  %.09 = phi i64 [ 0, %.lr.ph ], [ %19, %15 ]
  %16 = getelementptr inbounds %struct.vq_Segment, ptr %.pre, i64 %.09
  %17 = tail call ptr @json_new_VQSegment(ptr noundef %16, ptr noundef %1)
  %18 = tail call ptr @json_array_push(ptr noundef %10, ptr noundef %17) #3
  %19 = add nuw i64 %.09, 1
  %20 = icmp ult i64 %19, %4
  br i1 %20, label %15, label %._crit_edge, !llvm.loop !17

._crit_edge:                                      ; preds = %15, %5
  %.sink = phi ptr [ %8, %5 ], [ %10, %15 ]
  %21 = tail call ptr @preserialize(ptr noundef %.sink)
  ret ptr %21
}

attributes #0 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { inlinehint nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !11, i64 8}
!6 = !{!"", !7, i64 0, !10, i64 8}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !11, i64 8, !12, i64 16}
!11 = !{!"long", !8, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!14, !12, i64 176}
!14 = !{!"__caryll_vectorinterface_VQ", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104, !12, i64 112, !12, i64 120, !12, i64 128, !12, i64 136, !12, i64 144, !12, i64 152, !12, i64 160, !12, i64 168, !12, i64 176, !12, i64 184, !12, i64 192, !12, i64 200, !12, i64 208, !12, i64 216}
!15 = !{!6, !7, i64 0}
!16 = !{!6, !12, i64 24}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass