; LLVM IR from caryll/otfcc :: lib/vf (region)

; 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.vq_Region = type { i16, [0 x %struct.vq_AxisSpan] }
%struct.vq_AxisSpan = type { double, double, double }
%struct.VV = type { i64, i64, ptr }

; 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

; Function Attrs: nounwind uwtable
define dso_local double @vqRegionGetWeight(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store double 1.000000e+00, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !11
  br label %7

7:                                                ; preds = %36, %2
  %8 = load i64, ptr %6, align 8, !tbaa !11
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.vq_Region, ptr %9, i32 0, i32 0
  %11 = load i16, ptr %10, align 8, !tbaa !13
  %12 = zext i16 %11 to i64
  %13 = icmp ult i64 %8, %12
  br i1 %13, label %14, label %19

14:                                               ; preds = %7
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.VV, ptr %15, i32 0, i32 0
  %17 = load i64, ptr %16, align 8, !tbaa !15
  %18 = icmp ne i64 %17, 0
  br label %19

19:                                               ; preds = %14, %7
  %20 = phi i1 [ false, %7 ], [ %18, %14 ]
  br i1 %20, label %22, label %21

21:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %39

22:                                               ; preds = %19
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.vq_Region, ptr %23, i32 0, i32 1
  %25 = load i64, ptr %6, align 8, !tbaa !11
  %26 = getelementptr inbounds [0 x %struct.vq_AxisSpan], ptr %24, i64 0, i64 %25
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.VV, ptr %27, i32 0, i32 2
  %29 = load ptr, ptr %28, align 8, !tbaa !17
  %30 = load i64, ptr %6, align 8, !tbaa !11
  %31 = getelementptr inbounds double, ptr %29, i64 %30
  %32 = load double, ptr %31, align 8, !tbaa !9
  %33 = call double @weightAxisRegion(ptr noundef %26, double noundef %32)
  %34 = load double, ptr %5, align 8, !tbaa !9
  %35 = fmul double %34, %33
  store double %35, ptr %5, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %22
  %37 = load i64, ptr %6, align 8, !tbaa !11
  %38 = add i64 %37, 1
  store i64 %38, ptr %6, align 8, !tbaa !11
  br label %7, !llvm.loop !18

39:                                               ; preds = %21
  %40 = load double, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret double %40
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 }

!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, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!16, !12, i64 0}
!16 = !{!"", !12, i64 0, !12, i64 8, !6, i64 16}
!17 = !{!16, !6, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"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.vq_AxisSpan = type { double, double, double }

; Function Attrs: nounwind uwtable
define dso_local double @vqRegionGetWeight(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = load i16, ptr %0, align 8, !tbaa !5
  %.not14 = icmp eq i16 %3, 0
  br i1 %.not14, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = getelementptr inbounds i8, ptr %1, i64 16
  br label %6

6:                                                ; preds = %.lr.ph, %8
  %.011 = phi i64 [ 0, %.lr.ph ], [ %15, %8 ]
  %.0910 = phi double [ 1.000000e+00, %.lr.ph ], [ %14, %8 ]
  %7 = load i64, ptr %1, align 8, !tbaa !9
  %.not = icmp eq i64 %7, 0
  br i1 %.not, label %.critedge, label %8

.critedge:                                        ; preds = %6, %8, %2
  %.09.lcssa = phi double [ 1.000000e+00, %2 ], [ %14, %8 ], [ %.0910, %6 ]
  ret double %.09.lcssa

8:                                                ; preds = %6
  %9 = getelementptr inbounds [0 x %struct.vq_AxisSpan], ptr %4, i64 0, i64 %.011
  %10 = load ptr, ptr %5, align 8, !tbaa !13
  %11 = getelementptr inbounds double, ptr %10, i64 %.011
  %12 = load double, ptr %11, align 8, !tbaa !14
  %13 = tail call double @weightAxisRegion(ptr noundef nonnull %9, double noundef %12)
  %14 = fmul double %.0910, %13
  %15 = add nuw nsw i64 %.011, 1
  %16 = load i16, ptr %0, align 8, !tbaa !5
  %17 = zext i16 %16 to i64
  %18 = icmp ult i64 %15, %17
  br i1 %18, label %6, label %.critedge, !llvm.loop !16
}

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

attributes #0 = { 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 #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" }

!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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 8, !12, i64 16}
!11 = !{!"long", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!10, !12, i64 16}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass