; LLVM IR from thekyria/elabtsaot2 :: gui/powersystem_editor/powersystem_model (pwsschematicmodel)

; 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.elabtsaot::Branch" = type { i32, i8, i32, i32, double, double, double, double, double, double, double, double }
%"class.elabtsaot::PwsSchematicModelElement" = type { %"class.elabtsaot::PwsModelElement", float, float, float, float }
%"class.elabtsaot::PwsModelElement" = type { ptr, i32, i32 }

; 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: mustprogress uwtable
declare dso_local noundef ptr @_ZN9elabtsaot17PwsSchematicModel14elementByIndexEim(ptr noundef nonnull align 8 dereferenceable(112), i32 noundef, i64 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9elabtsaot17PwsSchematicModel16addBranchElementENS_6BranchEbPi(ptr noundef nonnull align 8 dereferenceable(112) %0, ptr noundef byval(%"class.elabtsaot::Branch") align 8 %1, i1 noundef zeroext %2, ptr noundef %3) unnamed_addr #1 align 2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  %15 = zext i1 %2 to i8
  store i8 %15, ptr %7, align 1, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  %16 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %17 = getelementptr inbounds %"class.elabtsaot::Branch", ptr %1, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !11
  %19 = load i8, ptr %7, align 1, !tbaa !9, !range !15, !noundef !16
  %20 = trunc i8 %19 to i1
  %21 = load ptr, ptr %16, align 8, !tbaa !17
  %22 = getelementptr inbounds ptr, ptr %21, i64 5
  %23 = load ptr, ptr %22, align 8
  %24 = call noundef i32 %23(ptr noundef nonnull align 8 dereferenceable(112) %16, i32 noundef 1, i32 noundef %18, i1 noundef zeroext %20, ptr noundef %9)
  store i32 %24, ptr %10, align 4, !tbaa !19
  %25 = load i32, ptr %10, align 4, !tbaa !19
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %4
  store i32 1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %94

28:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %29 = load i32, ptr %9, align 4, !tbaa !19
  %30 = sext i32 %29 to i64
  %31 = call noundef ptr @_ZN9elabtsaot17PwsSchematicModel14elementByIndexEim(ptr noundef nonnull align 8 dereferenceable(112) %16, i32 noundef 1, i64 noundef %30)
  store ptr %31, ptr %12, align 8, !tbaa !5
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %37

34:                                               ; preds = %28
  %35 = load i32, ptr %9, align 4, !tbaa !19
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %35, ptr %36, align 4, !tbaa !19
  br label %37

37:                                               ; preds = %34, %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %38 = getelementptr inbounds %"class.elabtsaot::Branch", ptr %1, i32 0, i32 2
  %39 = load i32, ptr %38, align 8, !tbaa !20
  %40 = call noundef ptr @_ZN9elabtsaot17PwsSchematicModel7elementEijPi(ptr noundef nonnull align 8 dereferenceable(112) %16, i32 noundef 0, i32 noundef %39, ptr noundef null)
  store ptr %40, ptr %13, align 8, !tbaa !5
  %41 = load ptr, ptr %13, align 8, !tbaa !5
  %42 = icmp eq ptr %41, null
  br i1 %42, label %43, label %44

43:                                               ; preds = %37
  store i32 2, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %93

44:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #2
  %45 = getelementptr inbounds %"class.elabtsaot::Branch", ptr %1, i32 0, i32 3
  %46 = load i32, ptr %45, align 4, !tbaa !21
  %47 = call noundef ptr @_ZN9elabtsaot17PwsSchematicModel7elementEijPi(ptr noundef nonnull align 8 dereferenceable(112) %16, i32 noundef 0, i32 noundef %46, ptr noundef null)
  store ptr %47, ptr %14, align 8, !tbaa !5
  %48 = load ptr, ptr %14, align 8, !tbaa !5
  %49 = icmp eq ptr %48, null
  br i1 %49, label %50, label %51

50:                                               ; preds = %44
  store i32 3, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %92

51:                                               ; preds = %44
  %52 = load ptr, ptr %13, align 8, !tbaa !5
  %53 = getelementptr inbounds %"class.elabtsaot::PwsSchematicModelElement", ptr %52, i32 0, i32 1
  %54 = load float, ptr %53, align 8, !tbaa !22
  %55 = load ptr, ptr %13, align 8, !tbaa !5
  %56 = getelementptr inbounds %"class.elabtsaot::PwsSchematicModelElement", ptr %55, i32 0, i32 3
  %57 = load float, ptr %56, align 8, !tbaa !26
  %58 = fadd float %54, %57
  %59 = fdiv float %58, 2.000000e+00
  %60 = load ptr, ptr %12, align 8, !tbaa !5
  %61 = getelementptr inbounds %"class.elabtsaot::PwsSchematicModelElement", ptr %60, i32 0, i32 1
  store float %59, ptr %61, align 8, !tbaa !22
  %62 = load ptr, ptr %13, align 8, !tbaa !5
  %63 = getelementptr inbounds %"class.elabtsaot::PwsSchematicModelElement", ptr %62, i32 0, i32 2
  %64 = load float, ptr %63, align 4, !tbaa !27
  %65 = load ptr, ptr %13, align 8, !tbaa !5
  %66 = getelementptr inbounds %"class.elabtsaot::PwsSchematicModelElement", ptr %65, i32 0, i32 4
  %67 = load float, ptr %66, align 4, !tbaa !28
  %68 = fadd float %64, %67
  %69 = fdiv float %68, 2.000000e+00
  %70 = load ptr, ptr %12, align 8, !tbaa !5
  %71 = getelementptr inbounds %"class.elabtsaot::PwsSchematicModelElement", ptr %70, i32 0, i32 2
  store float %69, ptr %71, align 4, !tbaa !27
  %72 = load ptr, ptr %14, align 8, !tbaa !5
  %73 = getelementptr inbounds %"class.elabtsaot::PwsSchematicModelElement", ptr %72, i32 0, i32 1
  %74 = load float, ptr %73, align 8, !tbaa !22
  %75 = load ptr, ptr %14, align 8, !tbaa !5
  %76 = getelementptr inbounds %"class.elabtsaot::PwsSchematicModelElement", ptr %75, i32 0, i32 3
  %77 = load float, ptr %76, align 8, !tbaa !26
  %78 = fadd float %74, %77
  %79 = fdiv float %78, 2.000000e+00
  %80 = load ptr, ptr %12, align 8, !tbaa !5
  %81 = getelementptr inbounds %"class.elabtsaot::PwsSchematicModelElement", ptr %80, i32 0, i32 3
  store float %79, ptr %81, align 8, !tbaa !26
  %82 = load ptr, ptr %14, align 8, !tbaa !5
  %83 = getelementptr inbounds %"class.elabtsaot::PwsSchematicModelElement", ptr %82, i32 0, i32 2
  %84 = load float, ptr %83, align 4, !tbaa !27
  %85 = load ptr, ptr %14, align 8, !tbaa !5
  %86 = getelementptr inbounds %"class.elabtsaot::PwsSchematicModelElement", ptr %85, i32 0, i32 4
  %87 = load float, ptr %86, align 4, !tbaa !28
  %88 = fadd float %84, %87
  %89 = fdiv float %88, 2.000000e+00
  %90 = load ptr, ptr %12, align 8, !tbaa !5
  %91 = getelementptr inbounds %"class.elabtsaot::PwsSchematicModelElement", ptr %90, i32 0, i32 4
  store float %89, ptr %91, align 4, !tbaa !28
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %92

92:                                               ; preds = %51, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  br label %93

93:                                               ; preds = %92, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %94

94:                                               ; preds = %93, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  %95 = load i32, ptr %5, align 4
  ret i32 %95
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN9elabtsaot17PwsSchematicModel7elementEijPi(ptr noundef nonnull align 8 dereferenceable(112), i32 noundef, i32 noundef, ptr noundef) #1 align 2

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

!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 = !{!"bool", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTSN9elabtsaot6BranchE", !13, i64 0, !10, i64 4, !13, i64 8, !13, i64 12, !14, i64 16, !14, i64 24, !14, i64 32, !14, i64 40, !14, i64 48, !14, i64 56, !14, i64 64, !14, i64 72}
!13 = !{!"int", !7, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!18, !18, i64 0}
!18 = !{!"vtable pointer", !8, i64 0}
!19 = !{!13, !13, i64 0}
!20 = !{!12, !13, i64 8}
!21 = !{!12, !13, i64 12}
!22 = !{!23, !25, i64 16}
!23 = !{!"_ZTSN9elabtsaot24PwsSchematicModelElementE", !24, i64 0, !25, i64 16, !25, i64 20, !25, i64 24, !25, i64 28}
!24 = !{!"_ZTSN9elabtsaot15PwsModelElementE", !13, i64 8, !13, i64 12}
!25 = !{!"float", !7, i64 0}
!26 = !{!23, !25, i64 24}
!27 = !{!23, !25, i64 20}
!28 = !{!23, !25, i64 28}


; 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.elabtsaot::Branch" = type { i32, i8, i32, i32, double, double, double, double, double, double, double, double }

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN9elabtsaot17PwsSchematicModel14elementByIndexEim(ptr noundef nonnull align 8 dereferenceable(112), i32 noundef, i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 4) i32 @_ZN9elabtsaot17PwsSchematicModel16addBranchElementENS_6BranchEbPi(ptr noundef nonnull align 8 dereferenceable(112) %0, ptr nocapture noundef readonly byval(%"class.elabtsaot::Branch") align 8 %1, i1 noundef zeroext %2, ptr noundef writeonly %3) unnamed_addr #1 align 2 {
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #2
  %6 = load i32, ptr %1, align 8, !tbaa !5
  %7 = load ptr, ptr %0, align 8, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %7, i64 40
  %9 = load ptr, ptr %8, align 8
  %10 = call noundef i32 %9(ptr noundef nonnull align 8 dereferenceable(112) %0, i32 noundef 1, i32 noundef %6, i1 noundef zeroext %2, ptr noundef nonnull %5)
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %11, label %42

11:                                               ; preds = %4
  %12 = load i32, ptr %5, align 4, !tbaa !14
  %13 = sext i32 %12 to i64
  %14 = call noundef ptr @_ZN9elabtsaot17PwsSchematicModel14elementByIndexEim(ptr noundef nonnull align 8 dereferenceable(112) %0, i32 noundef 1, i64 noundef %13)
  %.not22 = icmp eq ptr %3, null
  br i1 %.not22, label %17, label %15

15:                                               ; preds = %11
  %16 = load i32, ptr %5, align 4, !tbaa !14
  store i32 %16, ptr %3, align 4, !tbaa !14
  br label %17

17:                                               ; preds = %15, %11
  %18 = getelementptr inbounds i8, ptr %1, i64 8
  %19 = load i32, ptr %18, align 8, !tbaa !15
  %20 = call noundef ptr @_ZN9elabtsaot17PwsSchematicModel7elementEijPi(ptr noundef nonnull align 8 dereferenceable(112) %0, i32 noundef 0, i32 noundef %19, ptr noundef null)
  %21 = icmp eq ptr %20, null
  br i1 %21, label %42, label %22

22:                                               ; preds = %17
  %23 = getelementptr inbounds i8, ptr %1, i64 12
  %24 = load i32, ptr %23, align 4, !tbaa !16
  %25 = call noundef ptr @_ZN9elabtsaot17PwsSchematicModel7elementEijPi(ptr noundef nonnull align 8 dereferenceable(112) %0, i32 noundef 0, i32 noundef %24, ptr noundef null)
  %26 = icmp eq ptr %25, null
  br i1 %26, label %42, label %27

27:                                               ; preds = %22
  %28 = getelementptr inbounds i8, ptr %20, i64 16
  %29 = getelementptr inbounds i8, ptr %20, i64 24
  %30 = getelementptr inbounds i8, ptr %14, i64 16
  %31 = load <2 x float>, ptr %28, align 8, !tbaa !17
  %32 = load <2 x float>, ptr %29, align 8, !tbaa !17
  %33 = fadd <2 x float> %31, %32
  %34 = fmul <2 x float> %33, <float 5.000000e-01, float 5.000000e-01>
  store <2 x float> %34, ptr %30, align 8, !tbaa !17
  %35 = getelementptr inbounds i8, ptr %25, i64 16
  %36 = getelementptr inbounds i8, ptr %25, i64 24
  %37 = getelementptr inbounds i8, ptr %14, i64 24
  %38 = load <2 x float>, ptr %35, align 8, !tbaa !17
  %39 = load <2 x float>, ptr %36, align 8, !tbaa !17
  %40 = fadd <2 x float> %38, %39
  %41 = fmul <2 x float> %40, <float 5.000000e-01, float 5.000000e-01>
  store <2 x float> %41, ptr %37, align 8, !tbaa !17
  br label %42

42:                                               ; preds = %17, %22, %27, %4
  %.2 = phi i32 [ 1, %4 ], [ 2, %17 ], [ 0, %27 ], [ 3, %22 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #2
  ret i32 %.2
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN9elabtsaot17PwsSchematicModel7elementEijPi(ptr noundef nonnull align 8 dereferenceable(112), i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1 align 2

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

!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, !7, i64 0}
!6 = !{!"_ZTSN9elabtsaot6BranchE", !7, i64 0, !10, i64 4, !7, i64 8, !7, i64 12, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!"double", !8, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"vtable pointer", !9, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!6, !7, i64 8}
!16 = !{!6, !7, i64 12}
!17 = !{!18, !18, i64 0}
!18 = !{!"float", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass