; 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: nounwind uwtable
define dso_local void @enforce_temperature(ptr noundef %0, double noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %7 = load double, ptr %4, align 8, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = call double @calc_temperature(ptr noundef %8)
  %10 = fdiv double %7, %9
  %11 = call double @sqrt(double noundef %10) #3
  store double %11, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !11
  br label %12

12:                                               ; preds = %47, %2
  %13 = load i64, ptr %6, align 8, !tbaa !11
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.molecule, ptr %14, i32 0, i32 0
  %16 = load i64, ptr %15, align 8, !tbaa !13
  %17 = icmp ult i64 %13, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %50

19:                                               ; preds = %12
  %20 = load double, ptr %5, align 8, !tbaa !9
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.molecule, ptr %21, i32 0, i32 5
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = load i64, ptr %6, align 8, !tbaa !11
  %25 = getelementptr inbounds %struct.vec3d, ptr %23, i64 %24
  %26 = getelementptr inbounds %struct.vec3d, ptr %25, i32 0, i32 0
  %27 = load double, ptr %26, align 8, !tbaa !16
  %28 = fmul double %27, %20
  store double %28, ptr %26, align 8, !tbaa !16
  %29 = load double, ptr %5, align 8, !tbaa !9
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.molecule, ptr %30, i32 0, i32 5
  %32 = load ptr, ptr %31, align 8, !tbaa !15
  %33 = load i64, ptr %6, align 8, !tbaa !11
  %34 = getelementptr inbounds %struct.vec3d, ptr %32, i64 %33
  %35 = getelementptr inbounds %struct.vec3d, ptr %34, i32 0, i32 1
  %36 = load double, ptr %35, align 8, !tbaa !18
  %37 = fmul double %36, %29
  store double %37, ptr %35, align 8, !tbaa !18
  %38 = load double, ptr %5, align 8, !tbaa !9
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.molecule, ptr %39, i32 0, i32 5
  %41 = load ptr, ptr %40, align 8, !tbaa !15
  %42 = load i64, ptr %6, align 8, !tbaa !11
  %43 = getelementptr inbounds %struct.vec3d, ptr %41, i64 %42
  %44 = getelementptr inbounds %struct.vec3d, ptr %43, i32 0, i32 2
  %45 = load double, ptr %44, align 8, !tbaa !19
  %46 = fmul double %45, %38
  store double %46, ptr %44, align 8, !tbaa !19
  br label %47

47:                                               ; preds = %19
  %48 = load i64, ptr %6, align 8, !tbaa !11
  %49 = add i64 %48, 1
  store i64 %49, ptr %6, align 8, !tbaa !11
  br label %12, !llvm.loop !20

50:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

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

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

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

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

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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: nounwind uwtable
define dso_local void @enforce_temperature(ptr noundef %0, double noundef %1) local_unnamed_addr #0 {
  %3 = tail call double @calc_temperature(ptr noundef %0)
  %4 = fdiv double %1, %3
  %5 = tail call double @sqrt(double noundef %4) #3
  %6 = load i64, ptr %0, align 8, !tbaa !5
  %.not = icmp eq i64 %6, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

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

scalar.ph.preheader:                              ; preds = %middle.block, %vector.scevcheck, %.lr.ph
  %.013.ph = phi i64 [ 0, %vector.scevcheck ], [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  %.neg = or disjoint i64 %.013.ph, 1
  %xtraiter = and i64 %6, 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
  %9 = getelementptr inbounds %struct.vec3d, ptr %8, i64 %.013.ph
  %10 = load <2 x double>, ptr %9, align 8, !tbaa !12
  %11 = insertelement <2 x double> poison, double %5, i64 0
  %12 = shufflevector <2 x double> %11, <2 x double> poison, <2 x i32> zeroinitializer
  %13 = fmul <2 x double> %12, %10
  store <2 x double> %13, ptr %9, align 8, !tbaa !12
  %14 = getelementptr inbounds %struct.vec3d, ptr %8, i64 %.013.ph, i32 2
  %15 = load double, ptr %14, align 8, !tbaa !14
  %16 = fmul double %5, %15
  store double %16, ptr %14, align 8, !tbaa !14
  %17 = or disjoint i64 %.013.ph, 1
  br label %scalar.ph.prol.loopexit

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %.013.unr = phi i64 [ %.013.ph, %scalar.ph.preheader ], [ %17, %scalar.ph.prol ]
  %18 = icmp eq i64 %6, %.neg
  br i1 %18, label %._crit_edge, label %scalar.ph.preheader.new

scalar.ph.preheader.new:                          ; preds = %scalar.ph.prol.loopexit
  %19 = insertelement <2 x double> poison, double %5, i64 0
  %20 = shufflevector <2 x double> %19, <2 x double> poison, <2 x i32> zeroinitializer
  %21 = insertelement <2 x double> poison, double %5, i64 0
  %22 = shufflevector <2 x double> %21, <2 x double> poison, <2 x i32> zeroinitializer
  br label %scalar.ph

vector.scevcheck:                                 ; preds = %.lr.ph
  %23 = add i64 %6, -1
  %mul = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %23, i64 24)
  %mul.result = extractvalue { i64, i1 } %mul, 0
  %mul.overflow = extractvalue { i64, i1 } %mul, 1
  %24 = getelementptr i8, ptr %8, i64 %mul.result
  %25 = icmp ult ptr %24, %8
  %26 = or i1 %25, %mul.overflow
  %scevgep = getelementptr i8, ptr %8, i64 8
  %mul14 = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %23, i64 24)
  %mul.result15 = extractvalue { i64, i1 } %mul14, 0
  %mul.overflow16 = extractvalue { i64, i1 } %mul14, 1
  %27 = getelementptr i8, ptr %scevgep, i64 %mul.result15
  %28 = icmp ult ptr %27, %scevgep
  %29 = or i1 %28, %mul.overflow16
  %scevgep17 = getelementptr i8, ptr %8, i64 16
  %mul18 = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %23, i64 24)
  %mul.result19 = extractvalue { i64, i1 } %mul18, 0
  %mul.overflow20 = extractvalue { i64, i1 } %mul18, 1
  %30 = getelementptr i8, ptr %scevgep17, i64 %mul.result19
  %31 = icmp ult ptr %30, %scevgep17
  %32 = or i1 %31, %mul.overflow20
  %33 = or i1 %26, %29
  %34 = or i1 %33, %32
  br i1 %34, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.scevcheck
  %n.vec = and i64 %6, -2
  %broadcast.splatinsert = insertelement <2 x double> poison, double %5, 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 ]
  %35 = or disjoint i64 %index, 1
  %36 = getelementptr inbounds %struct.vec3d, ptr %8, i64 %index
  %37 = getelementptr inbounds %struct.vec3d, ptr %8, i64 %35
  %38 = load double, ptr %36, align 8, !tbaa !16
  %39 = load double, ptr %37, align 8, !tbaa !16
  %40 = insertelement <2 x double> poison, double %38, i64 0
  %41 = insertelement <2 x double> %40, double %39, i64 1
  %42 = fmul <2 x double> %broadcast.splat, %41
  %43 = getelementptr inbounds %struct.vec3d, ptr %8, i64 %index, i32 1
  %44 = getelementptr inbounds %struct.vec3d, ptr %8, i64 %35, i32 1
  %45 = load double, ptr %43, align 8, !tbaa !17
  %46 = load double, ptr %44, align 8, !tbaa !17
  %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 %8, i64 %index, i32 2
  %51 = getelementptr inbounds %struct.vec3d, ptr %8, i64 %35, i32 2
  %52 = load double, ptr %50, align 8, !tbaa !14
  %53 = load double, ptr %51, align 8, !tbaa !14
  %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 i8, ptr %50, i64 -16
  %58 = shufflevector <2 x double> %42, <2 x double> %49, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
  %59 = shufflevector <2 x double> %56, <2 x double> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
  %interleaved.vec = shufflevector <4 x double> %58, <4 x double> %59, <6 x i32> <i32 0, i32 2, i32 4, i32 1, i32 3, i32 5>
  store <6 x double> %interleaved.vec, ptr %57, align 8, !tbaa !12
  %index.next = add nuw i64 %index, 2
  %60 = icmp eq i64 %index.next, %n.vec
  br i1 %60, label %middle.block, label %vector.body, !llvm.loop !18

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

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

scalar.ph:                                        ; preds = %scalar.ph, %scalar.ph.preheader.new
  %.013 = phi i64 [ %.013.unr, %scalar.ph.preheader.new ], [ %74, %scalar.ph ]
  %61 = getelementptr inbounds %struct.vec3d, ptr %8, i64 %.013
  %62 = load <2 x double>, ptr %61, align 8, !tbaa !12
  %63 = fmul <2 x double> %20, %62
  store <2 x double> %63, ptr %61, align 8, !tbaa !12
  %64 = getelementptr inbounds %struct.vec3d, ptr %8, i64 %.013, i32 2
  %65 = load double, ptr %64, align 8, !tbaa !14
  %66 = fmul double %5, %65
  store double %66, ptr %64, align 8, !tbaa !14
  %67 = add nuw i64 %.013, 1
  %68 = getelementptr inbounds %struct.vec3d, ptr %8, i64 %67
  %69 = load <2 x double>, ptr %68, align 8, !tbaa !12
  %70 = fmul <2 x double> %22, %69
  store <2 x double> %70, ptr %68, align 8, !tbaa !12
  %71 = getelementptr inbounds %struct.vec3d, ptr %8, i64 %67, i32 2
  %72 = load double, ptr %71, align 8, !tbaa !14
  %73 = fmul double %5, %72
  store double %73, ptr %71, align 8, !tbaa !14
  %74 = add nuw i64 %.013, 2
  %exitcond.not.1 = icmp eq i64 %74, %6
  br i1 %exitcond.not.1, label %._crit_edge, label %scalar.ph, !llvm.loop !22
}

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

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

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

attributes #0 = { 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 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 #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 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