; LLVM IR from henrywatkins/PARAMAGNET :: src/TransportCoeff.ll (Z7setbdiriPdS_)

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

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z7setbdiriPdS_(i32 noundef %0, ptr noundef %1, ptr noundef %2) #3 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca double, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %8 = load ptr, ptr %5, align 8, !tbaa !9
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = add nsw i32 %9, 8
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds double, ptr %8, i64 %11
  %13 = load double, ptr %12, align 8, !tbaa !11
  %14 = load ptr, ptr %5, align 8, !tbaa !9
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = add nsw i32 %15, 8
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds double, ptr %14, i64 %17
  %19 = load double, ptr %18, align 8, !tbaa !11
  %20 = load ptr, ptr %5, align 8, !tbaa !9
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = add nsw i32 %21, 9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds double, ptr %20, i64 %23
  %25 = load double, ptr %24, align 8, !tbaa !11
  %26 = load ptr, ptr %5, align 8, !tbaa !9
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = add nsw i32 %27, 9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds double, ptr %26, i64 %29
  %31 = load double, ptr %30, align 8, !tbaa !11
  %32 = fmul double %25, %31
  %33 = call double @llvm.fmuladd.f64(double %13, double %19, double %32)
  %34 = load ptr, ptr %5, align 8, !tbaa !9
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = add nsw i32 %35, 10
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds double, ptr %34, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !11
  %40 = load ptr, ptr %5, align 8, !tbaa !9
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = add nsw i32 %41, 10
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds double, ptr %40, i64 %43
  %45 = load double, ptr %44, align 8, !tbaa !11
  %46 = call double @llvm.fmuladd.f64(double %39, double %45, double %33)
  %47 = call double @sqrt(double noundef %46) #4
  store double %47, ptr %7, align 8, !tbaa !11
  %48 = load double, ptr %7, align 8, !tbaa !11
  %49 = fcmp olt double %48, 1.000000e-03
  br i1 %49, label %50, label %57

50:                                               ; preds = %3
  %51 = load ptr, ptr %6, align 8, !tbaa !9
  %52 = getelementptr inbounds double, ptr %51, i64 0
  store double 0.000000e+00, ptr %52, align 8, !tbaa !11
  %53 = load ptr, ptr %6, align 8, !tbaa !9
  %54 = getelementptr inbounds double, ptr %53, i64 1
  store double 0.000000e+00, ptr %54, align 8, !tbaa !11
  %55 = load ptr, ptr %6, align 8, !tbaa !9
  %56 = getelementptr inbounds double, ptr %55, i64 2
  store double 0.000000e+00, ptr %56, align 8, !tbaa !11
  br label %88

57:                                               ; preds = %3
  %58 = load ptr, ptr %5, align 8, !tbaa !9
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = add nsw i32 %59, 8
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds double, ptr %58, i64 %61
  %63 = load double, ptr %62, align 8, !tbaa !11
  %64 = load double, ptr %7, align 8, !tbaa !11
  %65 = fdiv double %63, %64
  %66 = load ptr, ptr %6, align 8, !tbaa !9
  %67 = getelementptr inbounds double, ptr %66, i64 0
  store double %65, ptr %67, align 8, !tbaa !11
  %68 = load ptr, ptr %5, align 8, !tbaa !9
  %69 = load i32, ptr %4, align 4, !tbaa !5
  %70 = add nsw i32 %69, 9
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds double, ptr %68, i64 %71
  %73 = load double, ptr %72, align 8, !tbaa !11
  %74 = load double, ptr %7, align 8, !tbaa !11
  %75 = fdiv double %73, %74
  %76 = load ptr, ptr %6, align 8, !tbaa !9
  %77 = getelementptr inbounds double, ptr %76, i64 1
  store double %75, ptr %77, align 8, !tbaa !11
  %78 = load ptr, ptr %5, align 8, !tbaa !9
  %79 = load i32, ptr %4, align 4, !tbaa !5
  %80 = add nsw i32 %79, 10
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds double, ptr %78, i64 %81
  %83 = load double, ptr %82, align 8, !tbaa !11
  %84 = load double, ptr %7, align 8, !tbaa !11
  %85 = fdiv double %83, %84
  %86 = load ptr, ptr %6, align 8, !tbaa !9
  %87 = getelementptr inbounds double, ptr %86, i64 2
  store double %85, ptr %87, align 8, !tbaa !11
  br label %88

88:                                               ; preds = %57, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}


; 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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @_Z7setbdiriPdS_(i32 noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #1 {
  %4 = sext i32 %0 to i64
  %5 = getelementptr double, ptr %1, i64 %4
  %6 = getelementptr i8, ptr %5, i64 64
  %7 = load double, ptr %6, align 8, !tbaa !5
  %8 = getelementptr i8, ptr %5, i64 72
  %9 = load double, ptr %8, align 8, !tbaa !5
  %10 = fmul double %9, %9
  %11 = tail call double @llvm.fmuladd.f64(double %7, double %7, double %10)
  %12 = getelementptr i8, ptr %5, i64 80
  %13 = load double, ptr %12, align 8, !tbaa !5
  %14 = tail call double @llvm.fmuladd.f64(double %13, double %13, double %11)
  %sqrt = tail call double @llvm.sqrt.f64(double %14)
  %15 = fcmp olt double %sqrt, 1.000000e-03
  br i1 %15, label %16, label %17

16:                                               ; preds = %3
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %2, i8 0, i64 16, i1 false)
  br label %24

17:                                               ; preds = %3
  %18 = fdiv double %7, %sqrt
  store double %18, ptr %2, align 8, !tbaa !5
  %19 = load double, ptr %8, align 8, !tbaa !5
  %20 = fdiv double %19, %sqrt
  %21 = getelementptr inbounds i8, ptr %2, i64 8
  store double %20, ptr %21, align 8, !tbaa !5
  %22 = load double, ptr %12, align 8, !tbaa !5
  %23 = fdiv double %22, %sqrt
  br label %24

24:                                               ; preds = %17, %16
  %.sink = phi double [ 0.000000e+00, %16 ], [ %23, %17 ]
  %25 = getelementptr inbounds i8, ptr %2, i64 16
  store double %.sink, ptr %25, align 8
  ret void
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

!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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass