; LLVM IR from microsoft/LightAIMD :: src (thermostat)

; 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.molecule = type { i64, i64, ptr, ptr, ptr, ptr, ptr, ptr, i64, ptr }
%struct.vec3d = type { double, double, double }

; 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: nounwind uwtable
declare dso_local double @calc_temperature(ptr noundef) #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: nounwind uwtable
define dso_local void @thermostat_berendsen_nvt(ptr noundef %0, double noundef %1, double noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  store double %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = call double @calc_temperature(ptr noundef %10)
  store double %11, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %12 = load double, ptr %5, align 8, !tbaa !9
  %13 = load double, ptr %7, align 8, !tbaa !9
  %14 = fdiv double %12, %13
  %15 = fsub double %14, 1.000000e+00
  %16 = load double, ptr %6, align 8, !tbaa !9
  %17 = call double @llvm.fmuladd.f64(double %15, double %16, double 1.000000e+00)
  %18 = call double @sqrt(double noundef %17) #4
  store double %18, ptr %8, align 8, !tbaa !9
  %19 = load double, ptr %8, align 8, !tbaa !9
  %20 = fcmp ogt double %19, 1.100000e+00
  br i1 %20, label %21, label %22

21:                                               ; preds = %3
  br label %24

22:                                               ; preds = %3
  %23 = load double, ptr %8, align 8, !tbaa !9
  br label %24

24:                                               ; preds = %22, %21
  %25 = phi double [ 1.100000e+00, %21 ], [ %23, %22 ]
  store double %25, ptr %8, align 8, !tbaa !9
  %26 = load double, ptr %8, align 8, !tbaa !9
  %27 = fcmp olt double %26, 9.000000e-01
  br i1 %27, label %28, label %29

28:                                               ; preds = %24
  br label %31

29:                                               ; preds = %24
  %30 = load double, ptr %8, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %29, %28
  %32 = phi double [ 9.000000e-01, %28 ], [ %30, %29 ]
  store double %32, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store i64 0, ptr %9, align 8, !tbaa !11
  br label %33

33:                                               ; preds = %68, %31
  %34 = load i64, ptr %9, align 8, !tbaa !11
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.molecule, ptr %35, i32 0, i32 0
  %37 = load i64, ptr %36, align 8, !tbaa !13
  %38 = icmp ult i64 %34, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %71

40:                                               ; preds = %33
  %41 = load double, ptr %8, align 8, !tbaa !9
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.molecule, ptr %42, i32 0, i32 5
  %44 = load ptr, ptr %43, align 8, !tbaa !15
  %45 = load i64, ptr %9, align 8, !tbaa !11
  %46 = getelementptr inbounds %struct.vec3d, ptr %44, i64 %45
  %47 = getelementptr inbounds %struct.vec3d, ptr %46, i32 0, i32 0
  %48 = load double, ptr %47, align 8, !tbaa !16
  %49 = fmul double %48, %41
  store double %49, ptr %47, align 8, !tbaa !16
  %50 = load double, ptr %8, align 8, !tbaa !9
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.molecule, ptr %51, i32 0, i32 5
  %53 = load ptr, ptr %52, align 8, !tbaa !15
  %54 = load i64, ptr %9, align 8, !tbaa !11
  %55 = getelementptr inbounds %struct.vec3d, ptr %53, i64 %54
  %56 = getelementptr inbounds %struct.vec3d, ptr %55, i32 0, i32 1
  %57 = load double, ptr %56, align 8, !tbaa !18
  %58 = fmul double %57, %50
  store double %58, ptr %56, align 8, !tbaa !18
  %59 = load double, ptr %8, align 8, !tbaa !9
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.molecule, ptr %60, i32 0, i32 5
  %62 = load ptr, ptr %61, align 8, !tbaa !15
  %63 = load i64, ptr %9, align 8, !tbaa !11
  %64 = getelementptr inbounds %struct.vec3d, ptr %62, i64 %63
  %65 = getelementptr inbounds %struct.vec3d, ptr %64, i32 0, i32 2
  %66 = load double, ptr %65, align 8, !tbaa !19
  %67 = fmul double %66, %59
  store double %67, ptr %65, align 8, !tbaa !19
  br label %68

68:                                               ; preds = %40
  %69 = load i64, ptr %9, align 8, !tbaa !11
  %70 = add i64 %69, 1
  store i64 %70, ptr %9, align 8, !tbaa !11
  br label %33, !llvm.loop !20

71:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  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 = { 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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"molecule", !12, i64 0, !12, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !12, i64 64, !6, i64 72}
!15 = !{!14, !6, i64 40}
!16 = !{!17, !10, i64 0}
!17 = !{!"vec3d", !10, i64 0, !10, i64 8, !10, i64 16}
!18 = !{!17, !10, i64 8}
!19 = !{!17, !10, i64 16}
!20 = distinct !{!20, !21}
!21 = !{!"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.vec3d = type { double, double, double }

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local double @calc_temperature(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local void @thermostat_berendsen_nvt(ptr noundef %0, double noundef %1, double noundef %2) local_unnamed_addr #1 {
  %4 = tail call double @calc_temperature(ptr noundef %0)
  %5 = fdiv double %1, %4
  %6 = fadd double %5, -1.000000e+00
  %7 = tail call double @llvm.fmuladd.f64(double %6, double %2, double 1.000000e+00)
  %8 = tail call double @sqrt(double noundef %7) #4
  %9 = fcmp ogt double %8, 1.100000e+00
  %10 = select i1 %9, double 1.100000e+00, double %8
  %11 = fcmp olt double %10, 9.000000e-01
  %12 = select i1 %11, double 9.000000e-01, double %10
  %13 = load i64, ptr %0, align 8, !tbaa !5
  %.not = icmp eq i64 %13, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %14 = getelementptr inbounds i8, ptr %0, i64 40
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %min.iters.check = icmp ult i64 %13, 36
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.scevcheck

scalar.ph.preheader:                              ; preds = %middle.block, %vector.scevcheck, %.lr.ph
  %.019.ph = phi i64 [ 0, %vector.scevcheck ], [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  %.neg = or disjoint i64 %.019.ph, 1
  %xtraiter = and i64 %13, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader
  %16 = getelementptr inbounds %struct.vec3d, ptr %15, i64 %.019.ph
  %17 = load <2 x double>, ptr %16, align 8, !tbaa !12
  %18 = insertelement <2 x double> poison, double %12, i64 0
  %19 = shufflevector <2 x double> %18, <2 x double> poison, <2 x i32> zeroinitializer
  %20 = fmul <2 x double> %19, %17
  store <2 x double> %20, ptr %16, align 8, !tbaa !12
  %21 = getelementptr inbounds %struct.vec3d, ptr %15, i64 %.019.ph, i32 2
  %22 = load double, ptr %21, align 8, !tbaa !14
  %23 = fmul double %12, %22
  store double %23, ptr %21, align 8, !tbaa !14
  %24 = or disjoint i64 %.019.ph, 1
  br label %scalar.ph.prol.loopexit

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %.019.unr = phi i64 [ %.019.ph, %scalar.ph.preheader ], [ %24, %scalar.ph.prol ]
  %25 = icmp eq i64 %13, %.neg
  br i1 %25, label %._crit_edge, label %scalar.ph.preheader.new

scalar.ph.preheader.new:                          ; preds = %scalar.ph.prol.loopexit
  %26 = insertelement <2 x double> poison, double %12, i64 0
  %27 = shufflevector <2 x double> %26, <2 x double> poison, <2 x i32> zeroinitializer
  %28 = insertelement <2 x double> poison, double %12, i64 0
  %29 = shufflevector <2 x double> %28, <2 x double> poison, <2 x i32> zeroinitializer
  br label %scalar.ph

vector.scevcheck:                                 ; preds = %.lr.ph
  %30 = add i64 %13, -1
  %mul = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %30, i64 24)
  %mul.result = extractvalue { i64, i1 } %mul, 0
  %mul.overflow = extractvalue { i64, i1 } %mul, 1
  %31 = getelementptr i8, ptr %15, i64 %mul.result
  %32 = icmp ult ptr %31, %15
  %33 = or i1 %32, %mul.overflow
  %scevgep = getelementptr i8, ptr %15, i64 8
  %mul20 = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %30, i64 24)
  %mul.result21 = extractvalue { i64, i1 } %mul20, 0
  %mul.overflow22 = extractvalue { i64, i1 } %mul20, 1
  %34 = getelementptr i8, ptr %scevgep, i64 %mul.result21
  %35 = icmp ult ptr %34, %scevgep
  %36 = or i1 %35, %mul.overflow22
  %scevgep23 = getelementptr i8, ptr %15, i64 16
  %mul24 = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %30, i64 24)
  %mul.result25 = extractvalue { i64, i1 } %mul24, 0
  %mul.overflow26 = extractvalue { i64, i1 } %mul24, 1
  %37 = getelementptr i8, ptr %scevgep23, i64 %mul.result25
  %38 = icmp ult ptr %37, %scevgep23
  %39 = or i1 %38, %mul.overflow26
  %40 = or i1 %33, %36
  %41 = or i1 %40, %39
  br i1 %41, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.scevcheck
  %n.vec = and i64 %13, -2
  %broadcast.splatinsert = insertelement <2 x double> poison, double %12, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %42 = or disjoint i64 %index, 1
  %43 = getelementptr inbounds %struct.vec3d, ptr %15, i64 %index
  %44 = getelementptr inbounds %struct.vec3d, ptr %15, i64 %42
  %45 = load double, ptr %43, align 8, !tbaa !16
  %46 = load double, ptr %44, align 8, !tbaa !16
  %47 = insertelement <2 x double> poison, double %45, i64 0
  %48 = insertelement <2 x double> %47, double %46, i64 1
  %49 = fmul <2 x double> %broadcast.splat, %48
  %50 = getelementptr inbounds %struct.vec3d, ptr %15, i64 %index, i32 1
  %51 = getelementptr inbounds %struct.vec3d, ptr %15, i64 %42, i32 1
  %52 = load double, ptr %50, align 8, !tbaa !17
  %53 = load double, ptr %51, align 8, !tbaa !17
  %54 = insertelement <2 x double> poison, double %52, i64 0
  %55 = insertelement <2 x double> %54, double %53, i64 1
  %56 = fmul <2 x double> %broadcast.splat, %55
  %57 = getelementptr inbounds %struct.vec3d, ptr %15, i64 %index, i32 2
  %58 = getelementptr inbounds %struct.vec3d, ptr %15, i64 %42, i32 2
  %59 = load double, ptr %57, align 8, !tbaa !14
  %60 = load double, ptr %58, align 8, !tbaa !14
  %61 = insertelement <2 x double> poison, double %59, i64 0
  %62 = insertelement <2 x double> %61, double %60, i64 1
  %63 = fmul <2 x double> %broadcast.splat, %62
  %64 = getelementptr inbounds i8, ptr %57, i64 -16
  %65 = shufflevector <2 x double> %49, <2 x double> %56, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
  %66 = shufflevector <2 x double> %63, <2 x double> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
  %interleaved.vec = shufflevector <4 x double> %65, <4 x double> %66, <6 x i32> <i32 0, i32 2, i32 4, i32 1, i32 3, i32 5>
  store <6 x double> %interleaved.vec, ptr %64, align 8, !tbaa !12
  %index.next = add nuw i64 %index, 2
  %67 = icmp eq i64 %index.next, %n.vec
  br i1 %67, label %middle.block, label %vector.body, !llvm.loop !18

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %13, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

._crit_edge:                                      ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block, %3
  ret void

scalar.ph:                                        ; preds = %scalar.ph, %scalar.ph.preheader.new
  %.019 = phi i64 [ %.019.unr, %scalar.ph.preheader.new ], [ %81, %scalar.ph ]
  %68 = getelementptr inbounds %struct.vec3d, ptr %15, i64 %.019
  %69 = load <2 x double>, ptr %68, align 8, !tbaa !12
  %70 = fmul <2 x double> %27, %69
  store <2 x double> %70, ptr %68, align 8, !tbaa !12
  %71 = getelementptr inbounds %struct.vec3d, ptr %15, i64 %.019, i32 2
  %72 = load double, ptr %71, align 8, !tbaa !14
  %73 = fmul double %12, %72
  store double %73, ptr %71, align 8, !tbaa !14
  %74 = add nuw i64 %.019, 1
  %75 = getelementptr inbounds %struct.vec3d, ptr %15, i64 %74
  %76 = load <2 x double>, ptr %75, align 8, !tbaa !12
  %77 = fmul <2 x double> %29, %76
  store <2 x double> %77, ptr %75, align 8, !tbaa !12
  %78 = getelementptr inbounds %struct.vec3d, ptr %15, i64 %74, i32 2
  %79 = load double, ptr %78, align 8, !tbaa !14
  %80 = fmul double %12, %79
  store double %80, ptr %78, align 8, !tbaa !14
  %81 = add nuw i64 %.019, 2
  %exitcond.not.1 = icmp eq i64 %81, %13
  br i1 %exitcond.not.1, label %._crit_edge, label %scalar.ph, !llvm.loop !22
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #3

attributes #0 = { mustprogress nofree nounwind willreturn memory(write) "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 = { 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 0}
!6 = !{!"molecule", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !7, i64 64, !10, i64 72}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 40}
!12 = !{!13, !13, i64 0}
!13 = !{!"double", !8, i64 0}
!14 = !{!15, !13, i64 16}
!15 = !{!"vec3d", !13, i64 0, !13, i64 8, !13, i64 16}
!16 = !{!15, !13, i64 0}
!17 = !{!15, !13, i64 8}
!18 = distinct !{!18, !19, !20, !21}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!"llvm.loop.isvectorized", i32 1}
!21 = !{!"llvm.loop.unroll.runtime.disable"}
!22 = distinct !{!22, !19, !20}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass