; LLVM IR from mfem/mfem :: general/gecko.ll (ZNK5Gecko8Subgraph4costEj)

; 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"

%"class.Gecko::WeightedSum" = type { %"class.Gecko::WeightedValue" }
%"class.Gecko::WeightedValue" = type { float, float }
%"class.Gecko::Subgraph" = type { ptr, i32, ptr, %"class.Gecko::WeightedSum", [16 x i8], [16 x i8], [16 x ptr], ptr, [16 x i32], [16 x [16 x float]] }
%"class.Gecko::Subnode" = type { float, %"class.Gecko::WeightedSum" }

; Function Attrs: mustprogress uwtable
define dso_local <2 x float> @_ZNK5Gecko8Subgraph4costEj(ptr noundef nonnull align 8 dereferenceable(1288) %0, i32 noundef %1) #0 align 2 {
  %3 = alloca %"class.Gecko::WeightedSum", align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  %7 = alloca float, align 4
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  %10 = alloca float, align 4
  %11 = alloca float, align 4
  %12 = alloca %"class.Gecko::WeightedValue", align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %13 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #4
  %14 = getelementptr inbounds %"class.Gecko::Subgraph", ptr %13, i32 0, i32 5
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds [16 x i8], ptr %14, i64 0, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !11
  store i8 %18, ptr %6, align 1, !tbaa !11
  %19 = getelementptr inbounds %"class.Gecko::Subgraph", ptr %13, i32 0, i32 6
  %20 = load i8, ptr %6, align 1, !tbaa !11
  %21 = zext i8 %20 to i64
  %22 = getelementptr inbounds [16 x ptr], ptr %19, i64 0, i64 %21
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  %24 = getelementptr inbounds %"class.Gecko::Subnode", ptr %23, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %3, ptr align 4 %24, i64 8, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %25 = getelementptr inbounds %"class.Gecko::Subgraph", ptr %13, i32 0, i32 6
  %26 = load i8, ptr %6, align 1, !tbaa !11
  %27 = zext i8 %26 to i64
  %28 = getelementptr inbounds [16 x ptr], ptr %25, i64 0, i64 %27
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = getelementptr inbounds %"class.Gecko::Subnode", ptr %29, i32 0, i32 0
  %31 = load float, ptr %30, align 4, !tbaa !12
  store float %31, ptr %7, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %32 = getelementptr inbounds %"class.Gecko::Subgraph", ptr %13, i32 0, i32 8
  %33 = load i8, ptr %6, align 1, !tbaa !11
  %34 = zext i8 %33 to i64
  %35 = getelementptr inbounds [16 x i32], ptr %32, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !9
  store i32 %36, ptr %8, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %80, %2
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = add i32 %38, 1
  store i32 %39, ptr %5, align 4, !tbaa !9
  %40 = getelementptr inbounds %"class.Gecko::Subgraph", ptr %13, i32 0, i32 1
  %41 = load i32, ptr %40, align 8, !tbaa !18
  %42 = icmp ult i32 %39, %41
  br i1 %42, label %43, label %81

43:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #4
  %44 = getelementptr inbounds %"class.Gecko::Subgraph", ptr %13, i32 0, i32 5
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds [16 x i8], ptr %44, i64 0, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !11
  store i8 %48, ptr %9, align 1, !tbaa !11
  %49 = load i32, ptr %8, align 4, !tbaa !9
  %50 = load i8, ptr %9, align 1, !tbaa !11
  %51 = zext i8 %50 to i32
  %52 = shl i32 1, %51
  %53 = and i32 %49, %52
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %55, label %80

55:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %56 = getelementptr inbounds %"class.Gecko::Subgraph", ptr %13, i32 0, i32 6
  %57 = load i8, ptr %9, align 1, !tbaa !11
  %58 = zext i8 %57 to i64
  %59 = getelementptr inbounds [16 x ptr], ptr %56, i64 0, i64 %58
  %60 = load ptr, ptr %59, align 8, !tbaa !5
  %61 = getelementptr inbounds %"class.Gecko::Subnode", ptr %60, i32 0, i32 0
  %62 = load float, ptr %61, align 4, !tbaa !12
  %63 = load float, ptr %7, align 4, !tbaa !17
  %64 = fsub float %62, %63
  store float %64, ptr %10, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %65 = getelementptr inbounds %"class.Gecko::Subgraph", ptr %13, i32 0, i32 9
  %66 = load i8, ptr %6, align 1, !tbaa !11
  %67 = zext i8 %66 to i64
  %68 = getelementptr inbounds [16 x [16 x float]], ptr %65, i64 0, i64 %67
  %69 = load i8, ptr %9, align 1, !tbaa !11
  %70 = zext i8 %69 to i64
  %71 = getelementptr inbounds [16 x float], ptr %68, i64 0, i64 %70
  %72 = load float, ptr %71, align 4, !tbaa !17
  store float %72, ptr %11, align 4, !tbaa !17
  %73 = getelementptr inbounds %"class.Gecko::Subgraph", ptr %13, i32 0, i32 2
  %74 = load ptr, ptr %73, align 8, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %75 = load float, ptr %10, align 4, !tbaa !17
  %76 = load float, ptr %11, align 4, !tbaa !17
  call void @_ZN5Gecko13WeightedValueC2Eff(ptr noundef nonnull align 4 dereferenceable(8) %12, float noundef %75, float noundef %76)
  %77 = load ptr, ptr %74, align 8, !tbaa !21
  %78 = getelementptr inbounds ptr, ptr %77, i64 4
  %79 = load ptr, ptr %78, align 8
  call void %79(ptr noundef nonnull align 8 dereferenceable(8) %74, ptr noundef nonnull align 4 dereferenceable(8) %3, ptr noundef nonnull align 4 dereferenceable(8) %12)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %80

80:                                               ; preds = %55, %43
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #4
  br label %37, !llvm.loop !23

81:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #4
  %82 = getelementptr inbounds %"class.Gecko::WeightedSum", ptr %3, i32 0, i32 0
  %83 = load <2 x float>, ptr %82, align 4
  ret <2 x float> %83
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5Gecko13WeightedValueC2Eff(ptr noundef nonnull align 4 dereferenceable(8), float noundef, float noundef) unnamed_addr #3 align 2

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

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="64" "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !14, i64 0}
!13 = !{!"_ZTSN5Gecko7SubnodeE", !14, i64 0, !15, i64 4}
!14 = !{!"float", !7, i64 0}
!15 = !{!"_ZTSN5Gecko11WeightedSumE", !16, i64 0}
!16 = !{!"_ZTSN5Gecko13WeightedValueE", !14, i64 0, !14, i64 4}
!17 = !{!14, !14, i64 0}
!18 = !{!19, !10, i64 8}
!19 = !{!"_ZTSN5Gecko8SubgraphE", !6, i64 0, !10, i64 8, !6, i64 16, !15, i64 24, !7, i64 32, !7, i64 48, !7, i64 64, !6, i64 192, !7, i64 200, !7, i64 264}
!20 = !{!19, !6, i64 16}
!21 = !{!22, !22, i64 0}
!22 = !{!"vtable pointer", !8, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"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"

%"class.Gecko::WeightedSum" = type { %"class.Gecko::WeightedValue" }
%"class.Gecko::WeightedValue" = type { float, float }

; Function Attrs: mustprogress uwtable
define dso_local <2 x float> @_ZNK5Gecko8Subgraph4costEj(ptr nocapture noundef nonnull readonly align 8 dereferenceable(1288) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = alloca %"class.Gecko::WeightedSum", align 8
  %4 = alloca %"class.Gecko::WeightedValue", align 4
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  %6 = zext i32 %1 to i64
  %7 = getelementptr inbounds [16 x i8], ptr %5, i64 0, i64 %6
  %8 = load i8, ptr %7, align 1, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 64
  %10 = zext i8 %8 to i64
  %11 = getelementptr inbounds [16 x ptr], ptr %9, i64 0, i64 %10
  %12 = load ptr, ptr %11, align 8, !tbaa !8
  %13 = getelementptr inbounds i8, ptr %12, i64 4
  %14 = load i64, ptr %13, align 4
  store i64 %14, ptr %3, align 8
  %15 = load float, ptr %12, align 4, !tbaa !10
  %16 = getelementptr inbounds i8, ptr %0, i64 200
  %17 = getelementptr inbounds [16 x i32], ptr %16, i64 0, i64 %10
  %18 = load i32, ptr %17, align 4, !tbaa !15
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  %20 = add i32 %1, 1
  %21 = load i32, ptr %19, align 8, !tbaa !17
  %22 = icmp ult i32 %20, %21
  %23 = bitcast i64 %14 to <2 x float>
  br i1 %22, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2
  %24 = getelementptr inbounds i8, ptr %0, i64 264
  %25 = getelementptr inbounds i8, ptr %0, i64 16
  %26 = zext i32 %20 to i64
  br label %27

27:                                               ; preds = %.lr.ph, %46
  %28 = phi i32 [ %21, %.lr.ph ], [ %47, %46 ]
  %indvars.iv = phi i64 [ %26, %.lr.ph ], [ %indvars.iv.next, %46 ]
  %29 = getelementptr inbounds [16 x i8], ptr %5, i64 0, i64 %indvars.iv
  %30 = load i8, ptr %29, align 1, !tbaa !5
  %31 = zext nneg i8 %30 to i32
  %32 = shl nuw i32 1, %31
  %33 = and i32 %32, %18
  %.not = icmp eq i32 %33, 0
  br i1 %.not, label %46, label %34

34:                                               ; preds = %27
  %35 = zext i8 %30 to i64
  %36 = getelementptr inbounds [16 x ptr], ptr %9, i64 0, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !8
  %38 = load float, ptr %37, align 4, !tbaa !10
  %39 = fsub float %38, %15
  %40 = getelementptr inbounds [16 x [16 x float]], ptr %24, i64 0, i64 %10, i64 %35
  %41 = load float, ptr %40, align 4, !tbaa !19
  %42 = load ptr, ptr %25, align 8, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  call void @_ZN5Gecko13WeightedValueC2Eff(ptr noundef nonnull align 4 dereferenceable(8) %4, float noundef %39, float noundef %41)
  %43 = load ptr, ptr %42, align 8, !tbaa !21
  %44 = getelementptr inbounds i8, ptr %43, i64 32
  %45 = load ptr, ptr %44, align 8
  call void %45(ptr noundef nonnull align 8 dereferenceable(8) %42, ptr noundef nonnull align 4 dereferenceable(8) %3, ptr noundef nonnull align 4 dereferenceable(8) %4)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  %.pre = load i32, ptr %19, align 8, !tbaa !17
  br label %46

46:                                               ; preds = %34, %27
  %47 = phi i32 [ %.pre, %34 ], [ %28, %27 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %48 = zext i32 %47 to i64
  %49 = icmp ult i64 %indvars.iv.next, %48
  br i1 %49, label %27, label %._crit_edge.loopexit, !llvm.loop !23

._crit_edge.loopexit:                             ; preds = %46
  %.pre16 = load <2 x float>, ptr %3, align 8
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %2
  %50 = phi <2 x float> [ %.pre16, %._crit_edge.loopexit ], [ %23, %2 ]
  ret <2 x float> %50
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5Gecko13WeightedValueC2Eff(ptr noundef nonnull align 4 dereferenceable(8), float noundef, float noundef) unnamed_addr #2 align 2

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

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="64" "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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !12, i64 0}
!11 = !{!"_ZTSN5Gecko7SubnodeE", !12, i64 0, !13, i64 4}
!12 = !{!"float", !6, i64 0}
!13 = !{!"_ZTSN5Gecko11WeightedSumE", !14, i64 0}
!14 = !{!"_ZTSN5Gecko13WeightedValueE", !12, i64 0, !12, i64 4}
!15 = !{!16, !16, i64 0}
!16 = !{!"int", !6, i64 0}
!17 = !{!18, !16, i64 8}
!18 = !{!"_ZTSN5Gecko8SubgraphE", !9, i64 0, !16, i64 8, !9, i64 16, !13, i64 24, !6, i64 32, !6, i64 48, !6, i64 64, !9, i64 192, !6, i64 200, !6, i64 264}
!19 = !{!12, !12, i64 0}
!20 = !{!18, !9, i64 16}
!21 = !{!22, !22, i64 0}
!22 = !{!"vtable pointer", !7, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass