; LLVM IR from LithoSimulator/K-Litho :: K-Litho-TCC/source.ll (Z12createDipoleRSt6vectorIfSaIfEEiR6Dipole)

; 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.Dipole = type { float, float, i8 }

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

; Function Attrs: nounwind
declare double @sqrt(double noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIfSaIfEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #3

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z12createDipoleRSt6vectorIfSaIfEEiR6Dipole(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, ptr noundef nonnull align 4 dereferenceable(12) %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca [2 x [2 x i32]], align 16
  %15 = alloca i8, align 1
  %16 = alloca i32, align 4
  %17 = alloca double, align 8
  %18 = alloca double, align 8
  %19 = alloca double, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.Dipole, ptr %20, i32 0, i32 1
  %22 = load float, ptr %21, align 4, !tbaa !11
  %23 = load i32, ptr %5, align 4, !tbaa !9
  %24 = sub nsw i32 %23, 1
  %25 = sdiv i32 %24, 2
  %26 = sitofp i32 %25 to float
  %27 = fmul float %22, %26
  %28 = fptosi float %27 to i32
  store i32 %28, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.Dipole, ptr %29, i32 0, i32 0
  %31 = load float, ptr %30, align 4, !tbaa !15
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = sub nsw i32 %32, 1
  %34 = sdiv i32 %33, 2
  %35 = sitofp i32 %34 to float
  %36 = fmul float %31, %35
  %37 = fptosi float %36 to i32
  store i32 %37, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = sdiv i32 %38, 2
  store i32 %39, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = sdiv i32 %40, 2
  store i32 %41, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %160, %3
  %43 = load i32, ptr %11, align 4, !tbaa !9
  %44 = load i32, ptr %5, align 4, !tbaa !9
  %45 = icmp slt i32 %43, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %42
  store i32 2, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %163

47:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %156, %47
  %49 = load i32, ptr %13, align 4, !tbaa !9
  %50 = load i32, ptr %5, align 4, !tbaa !9
  %51 = icmp slt i32 %49, %50
  br i1 %51, label %53, label %52

52:                                               ; preds = %48
  store i32 5, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %159

53:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 16, ptr %14) #4
  %54 = load i32, ptr %9, align 4, !tbaa !9
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.Dipole, ptr %55, i32 0, i32 2
  %57 = load i8, ptr %56, align 4, !tbaa !16, !range !17, !noundef !18
  %58 = trunc i8 %57 to i1
  br i1 %58, label %59, label %61

59:                                               ; preds = %53
  %60 = load i32, ptr %7, align 4, !tbaa !9
  br label %62

61:                                               ; preds = %53
  br label %62

62:                                               ; preds = %61, %59
  %63 = phi i32 [ %60, %59 ], [ 0, %61 ]
  %64 = add nsw i32 %54, %63
  store i32 %64, ptr %14, align 4, !tbaa !9
  %65 = getelementptr inbounds i32, ptr %14, i64 1
  %66 = load i32, ptr %10, align 4, !tbaa !9
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.Dipole, ptr %67, i32 0, i32 2
  %69 = load i8, ptr %68, align 4, !tbaa !16, !range !17, !noundef !18
  %70 = trunc i8 %69 to i1
  br i1 %70, label %71, label %72

71:                                               ; preds = %62
  br label %74

72:                                               ; preds = %62
  %73 = load i32, ptr %7, align 4, !tbaa !9
  br label %74

74:                                               ; preds = %72, %71
  %75 = phi i32 [ 0, %71 ], [ %73, %72 ]
  %76 = add nsw i32 %66, %75
  store i32 %76, ptr %65, align 4, !tbaa !9
  %77 = getelementptr inbounds [2 x i32], ptr %14, i64 1
  %78 = load i32, ptr %9, align 4, !tbaa !9
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.Dipole, ptr %79, i32 0, i32 2
  %81 = load i8, ptr %80, align 4, !tbaa !16, !range !17, !noundef !18
  %82 = trunc i8 %81 to i1
  br i1 %82, label %83, label %85

83:                                               ; preds = %74
  %84 = load i32, ptr %7, align 4, !tbaa !9
  br label %86

85:                                               ; preds = %74
  br label %86

86:                                               ; preds = %85, %83
  %87 = phi i32 [ %84, %83 ], [ 0, %85 ]
  %88 = sub nsw i32 %78, %87
  store i32 %88, ptr %77, align 4, !tbaa !9
  %89 = getelementptr inbounds i32, ptr %77, i64 1
  %90 = load i32, ptr %10, align 4, !tbaa !9
  %91 = load ptr, ptr %6, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.Dipole, ptr %91, i32 0, i32 2
  %93 = load i8, ptr %92, align 4, !tbaa !16, !range !17, !noundef !18
  %94 = trunc i8 %93 to i1
  br i1 %94, label %95, label %96

95:                                               ; preds = %86
  br label %98

96:                                               ; preds = %86
  %97 = load i32, ptr %7, align 4, !tbaa !9
  br label %98

98:                                               ; preds = %96, %95
  %99 = phi i32 [ 0, %95 ], [ %97, %96 ]
  %100 = sub nsw i32 %90, %99
  store i32 %100, ptr %89, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %15) #4
  store i8 0, ptr %15, align 1, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  store i32 0, ptr %16, align 4, !tbaa !9
  br label %101

101:                                              ; preds = %138, %98
  %102 = load i32, ptr %16, align 4, !tbaa !9
  %103 = icmp slt i32 %102, 2
  br i1 %103, label %105, label %104

104:                                              ; preds = %101
  store i32 8, ptr %12, align 4
  br label %141

105:                                              ; preds = %101
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %106 = load i32, ptr %13, align 4, !tbaa !9
  %107 = load i32, ptr %16, align 4, !tbaa !9
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds [2 x [2 x i32]], ptr %14, i64 0, i64 %108
  %110 = getelementptr inbounds [2 x i32], ptr %109, i64 0, i64 0
  %111 = load i32, ptr %110, align 8, !tbaa !9
  %112 = sub nsw i32 %106, %111
  %113 = sitofp i32 %112 to double
  store double %113, ptr %17, align 8, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %114 = load i32, ptr %11, align 4, !tbaa !9
  %115 = load i32, ptr %16, align 4, !tbaa !9
  %116 = sext i32 %115 to i64
  %117 = getelementptr inbounds [2 x [2 x i32]], ptr %14, i64 0, i64 %116
  %118 = getelementptr inbounds [2 x i32], ptr %117, i64 0, i64 1
  %119 = load i32, ptr %118, align 4, !tbaa !9
  %120 = sub nsw i32 %114, %119
  %121 = sitofp i32 %120 to double
  store double %121, ptr %18, align 8, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  %122 = load double, ptr %17, align 8, !tbaa !20
  %123 = load double, ptr %17, align 8, !tbaa !20
  %124 = load double, ptr %18, align 8, !tbaa !20
  %125 = load double, ptr %18, align 8, !tbaa !20
  %126 = fmul double %124, %125
  %127 = call double @llvm.fmuladd.f64(double %122, double %123, double %126)
  %128 = call double @sqrt(double noundef %127) #4
  store double %128, ptr %19, align 8, !tbaa !20
  %129 = load double, ptr %19, align 8, !tbaa !20
  %130 = load i32, ptr %8, align 4, !tbaa !9
  %131 = sitofp i32 %130 to double
  %132 = fcmp ole double %129, %131
  br i1 %132, label %133, label %134

133:                                              ; preds = %105
  store i8 1, ptr %15, align 1, !tbaa !19
  store i32 8, ptr %12, align 4
  br label %135

134:                                              ; preds = %105
  store i32 0, ptr %12, align 4
  br label %135

135:                                              ; preds = %134, %133
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  %136 = load i32, ptr %12, align 4
  switch i32 %136, label %141 [
    i32 0, label %137
  ]

137:                                              ; preds = %135
  br label %138

138:                                              ; preds = %137
  %139 = load i32, ptr %16, align 4, !tbaa !9
  %140 = add nsw i32 %139, 1
  store i32 %140, ptr %16, align 4, !tbaa !9
  br label %101, !llvm.loop !22

141:                                              ; preds = %135, %104
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  br label %142

142:                                              ; preds = %141
  %143 = load i8, ptr %15, align 1, !tbaa !19, !range !17, !noundef !18
  %144 = trunc i8 %143 to i1
  %145 = zext i1 %144 to i64
  %146 = select i1 %144, double 1.000000e+00, double 0.000000e+00
  %147 = fptrunc double %146 to float
  %148 = load ptr, ptr %4, align 8, !tbaa !5
  %149 = load i32, ptr %11, align 4, !tbaa !9
  %150 = load i32, ptr %5, align 4, !tbaa !9
  %151 = mul nsw i32 %149, %150
  %152 = load i32, ptr %13, align 4, !tbaa !9
  %153 = add nsw i32 %151, %152
  %154 = sext i32 %153 to i64
  %155 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIfSaIfEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %148, i64 noundef %154) #4
  store float %147, ptr %155, align 4, !tbaa !24
  call void @llvm.lifetime.end.p0(i64 1, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %14) #4
  br label %156

156:                                              ; preds = %142
  %157 = load i32, ptr %13, align 4, !tbaa !9
  %158 = add nsw i32 %157, 1
  store i32 %158, ptr %13, align 4, !tbaa !9
  br label %48, !llvm.loop !25

159:                                              ; preds = %52
  br label %160

160:                                              ; preds = %159
  %161 = load i32, ptr %11, align 4, !tbaa !9
  %162 = add nsw i32 %161, 1
  store i32 %162, ptr %11, align 4, !tbaa !9
  br label %42, !llvm.loop !26

163:                                              ; preds = %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!12, !13, i64 4}
!12 = !{!"_ZTS6Dipole", !13, i64 0, !13, i64 4, !14, i64 8}
!13 = !{!"float", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!12, !13, i64 0}
!16 = !{!12, !14, i64 8}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!14, !14, i64 0}
!20 = !{!21, !21, i64 0}
!21 = !{!"double", !7, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!13, !13, i64 0}
!25 = distinct !{!25, !23}
!26 = distinct !{!26, !23}


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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIfSaIfEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z12createDipoleRSt6vectorIfSaIfEEiR6Dipole(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, ptr nocapture noundef nonnull readonly align 4 dereferenceable(12) %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %2, i64 4
  %5 = load float, ptr %4, align 4, !tbaa !5
  %6 = add nsw i32 %1, -1
  %7 = sdiv i32 %6, 2
  %8 = sitofp i32 %7 to float
  %9 = fmul float %5, %8
  %10 = fptosi float %9 to i32
  %11 = sdiv i32 %1, 2
  %12 = icmp sgt i32 %1, 0
  br i1 %12, label %.preheader.lr.ph, label %._crit_edge49

.preheader.lr.ph:                                 ; preds = %3
  %13 = load float, ptr %2, align 4, !tbaa !11
  %14 = fmul float %13, %8
  %15 = fptosi float %14 to i32
  %16 = getelementptr inbounds i8, ptr %2, i64 8
  %17 = sitofp i32 %15 to double
  %18 = zext nneg i32 %1 to i64
  br label %.preheader.us

.preheader.us:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph
  %indvars.iv52 = phi i64 [ %indvars.iv.next53, %._crit_edge.us ], [ 0, %.preheader.lr.ph ]
  %19 = mul nuw nsw i64 %indvars.iv52, %18
  %20 = trunc nuw nsw i64 %indvars.iv52 to i32
  br label %21

21:                                               ; preds = %.preheader.us, %45
  %indvars.iv = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next, %45 ]
  %22 = load i8, ptr %16, align 4, !tbaa !12, !range !13, !noundef !14
  %23 = trunc nuw i8 %22 to i1
  %24 = select i1 %23, i32 %10, i32 0
  %25 = add nsw i32 %24, %11
  %26 = select i1 %23, i32 0, i32 %10
  %27 = add nsw i32 %26, %11
  %28 = trunc nuw nsw i64 %indvars.iv to i32
  %29 = sub nsw i32 %28, %25
  %30 = sitofp i32 %29 to double
  %31 = sub nsw i32 %20, %27
  %32 = sitofp i32 %31 to double
  %33 = fmul double %32, %32
  %34 = tail call double @llvm.fmuladd.f64(double %30, double %30, double %33)
  %sqrt.us = tail call double @llvm.sqrt.f64(double %34)
  %35 = fcmp ugt double %sqrt.us, %17
  br i1 %35, label %36, label %45

36:                                               ; preds = %21
  %.neg57 = sub i32 %26, %11
  %.neg = sub i32 %24, %11
  %37 = add i32 %.neg, %28
  %38 = sitofp i32 %37 to double
  %39 = add i32 %.neg57, %20
  %40 = sitofp i32 %39 to double
  %41 = fmul double %40, %40
  %42 = tail call double @llvm.fmuladd.f64(double %38, double %38, double %41)
  %sqrt.us.1 = tail call double @llvm.sqrt.f64(double %42)
  %43 = fcmp ugt double %sqrt.us.1, %17
  br i1 %43, label %44, label %45

44:                                               ; preds = %36
  br label %45

45:                                               ; preds = %44, %36, %21
  %46 = phi float [ 1.000000e+00, %21 ], [ 1.000000e+00, %36 ], [ 0.000000e+00, %44 ]
  %47 = add nuw nsw i64 %indvars.iv, %19
  %48 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIfSaIfEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %47) #3
  store float %46, ptr %48, align 4, !tbaa !15
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %18
  br i1 %exitcond.not, label %._crit_edge.us, label %21, !llvm.loop !16

._crit_edge.us:                                   ; preds = %45
  %indvars.iv.next53 = add nuw nsw i64 %indvars.iv52, 1
  %exitcond56.not = icmp eq i64 %indvars.iv.next53, %18
  br i1 %exitcond56.not, label %._crit_edge49, label %.preheader.us, !llvm.loop !18

._crit_edge49:                                    ; preds = %._crit_edge.us, %3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.sqrt.f64(double) #2

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 4}
!6 = !{!"_ZTS6Dipole", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !10, i64 8}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; Effective O3 passes: AggressiveInstCombinePass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass