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

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

@pyscf_grid_lvl5_forces_on_nuclei = external dso_local global [6 x [9 x double]], align 16
@CC_METHODS = external dso_local global [6 x ptr], align 16
@sanity_test_threshold = external dso_local global double, align 8
@.str.8 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [93 x i8], align 1

; 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.fabs.f64(double) #1

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @check_forces(ptr noundef %0, i64 noundef %1) #3 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca i64, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %13 = load i64, ptr %5, align 8, !tbaa !9
  %14 = icmp ult i64 %13, 1
  br i1 %14, label %18, label %15

15:                                               ; preds = %2
  %16 = load i64, ptr %5, align 8, !tbaa !9
  %17 = icmp ugt i64 %16, 6
  br i1 %17, label %18, label %19

18:                                               ; preds = %15, %2
  store i64 0, ptr %3, align 8
  br label %67

19:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %20 = load i64, ptr %5, align 8, !tbaa !9
  %21 = sub i64 %20, 1
  store i64 %21, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store double 0.000000e+00, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store double 0.000000e+00, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store double 0.000000e+00, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %50, %19
  %23 = load i64, ptr %10, align 8, !tbaa !9
  %24 = icmp ult i64 %23, 9
  br i1 %24, label %26, label %25

25:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %53

26:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %27 = load i64, ptr %6, align 8, !tbaa !9
  %28 = getelementptr inbounds [6 x [9 x double]], ptr @pyscf_grid_lvl5_forces_on_nuclei, i64 0, i64 %27
  %29 = load i64, ptr %10, align 8, !tbaa !9
  %30 = getelementptr inbounds [9 x double], ptr %28, i64 0, i64 %29
  %31 = load double, ptr %30, align 8, !tbaa !11
  store double %31, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load i64, ptr %10, align 8, !tbaa !9
  %34 = getelementptr inbounds double, ptr %32, i64 %33
  %35 = load double, ptr %34, align 8, !tbaa !11
  %36 = load double, ptr %11, align 8, !tbaa !11
  %37 = fsub double %35, %36
  %38 = call double @llvm.fabs.f64(double %37)
  store double %38, ptr %12, align 8, !tbaa !11
  %39 = load double, ptr %12, align 8, !tbaa !11
  %40 = load double, ptr %7, align 8, !tbaa !11
  %41 = fcmp ogt double %39, %40
  br i1 %41, label %42, label %49

42:                                               ; preds = %26
  %43 = load double, ptr %12, align 8, !tbaa !11
  store double %43, ptr %7, align 8, !tbaa !11
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = load i64, ptr %10, align 8, !tbaa !9
  %46 = getelementptr inbounds double, ptr %44, i64 %45
  %47 = load double, ptr %46, align 8, !tbaa !11
  store double %47, ptr %8, align 8, !tbaa !11
  %48 = load double, ptr %11, align 8, !tbaa !11
  store double %48, ptr %9, align 8, !tbaa !11
  br label %49

49:                                               ; preds = %42, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %50

50:                                               ; preds = %49
  %51 = load i64, ptr %10, align 8, !tbaa !9
  %52 = add i64 %51, 1
  store i64 %52, ptr %10, align 8, !tbaa !9
  br label %22, !llvm.loop !13

53:                                               ; preds = %25
  %54 = load i64, ptr %6, align 8, !tbaa !9
  %55 = getelementptr inbounds [6 x ptr], ptr @CC_METHODS, i64 0, i64 %54
  %56 = load ptr, ptr %55, align 8, !tbaa !5
  %57 = load double, ptr %8, align 8, !tbaa !11
  %58 = load double, ptr %9, align 8, !tbaa !11
  %59 = load double, ptr %7, align 8, !tbaa !11
  %60 = load double, ptr @sanity_test_threshold, align 8, !tbaa !11
  %61 = load double, ptr %7, align 8, !tbaa !11
  %62 = load double, ptr @sanity_test_threshold, align 8, !tbaa !11
  %63 = fcmp olt double %61, %62
  %64 = zext i1 %63 to i64
  %65 = select i1 %63, ptr @.str.8, ptr @.str.9
  %66 = call i32 (ptr, ...) @printf(ptr noundef @.str.11, ptr noundef %56, double noundef %57, double noundef %58, double noundef %59, double noundef %60, ptr noundef %65)
  store i64 1, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %67

67:                                               ; preds = %53, %18
  %68 = load i64, ptr %3, align 8
  ret i64 %68
}

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

@pyscf_grid_lvl5_forces_on_nuclei = external dso_local local_unnamed_addr global [6 x [9 x double]], align 16
@CC_METHODS = external dso_local local_unnamed_addr global [6 x ptr], align 16
@sanity_test_threshold = external dso_local local_unnamed_addr global double, align 8
@.str.8 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [93 x i8], align 1

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nofree nounwind uwtable
define dso_local range(i64 0, 2) i64 @check_forces(ptr nocapture noundef readonly %0, i64 noundef %1) local_unnamed_addr #2 {
  %3 = add i64 %1, -7
  %or.cond = icmp ult i64 %3, -6
  br i1 %or.cond, label %74, label %4

4:                                                ; preds = %2
  %5 = add nsw i64 %1, -1
  %6 = getelementptr inbounds [6 x [9 x double]], ptr @pyscf_grid_lvl5_forces_on_nuclei, i64 0, i64 %5, i64 0
  %7 = load double, ptr %6, align 8, !tbaa !5
  %8 = load double, ptr %0, align 8, !tbaa !5
  %9 = fsub double %8, %7
  %10 = tail call double @llvm.fabs.f64(double %9)
  %11 = fcmp one double %9, 0.000000e+00
  %.127 = select i1 %11, double %8, double 0.000000e+00
  %.125 = select i1 %11, double %7, double 0.000000e+00
  %.1 = select i1 %11, double %10, double 0.000000e+00
  %12 = getelementptr inbounds [6 x [9 x double]], ptr @pyscf_grid_lvl5_forces_on_nuclei, i64 0, i64 %5, i64 1
  %13 = load double, ptr %12, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = load double, ptr %14, align 8, !tbaa !5
  %16 = fsub double %15, %13
  %17 = tail call double @llvm.fabs.f64(double %16)
  %18 = fcmp ogt double %17, %.1
  %.127.1 = select i1 %18, double %15, double %.127
  %.125.1 = select i1 %18, double %13, double %.125
  %.1.1 = select i1 %18, double %17, double %.1
  %19 = getelementptr inbounds [6 x [9 x double]], ptr @pyscf_grid_lvl5_forces_on_nuclei, i64 0, i64 %5, i64 2
  %20 = load double, ptr %19, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %0, i64 16
  %22 = load double, ptr %21, align 8, !tbaa !5
  %23 = fsub double %22, %20
  %24 = tail call double @llvm.fabs.f64(double %23)
  %25 = fcmp ogt double %24, %.1.1
  %.127.2 = select i1 %25, double %22, double %.127.1
  %.125.2 = select i1 %25, double %20, double %.125.1
  %.1.2 = select i1 %25, double %24, double %.1.1
  %26 = getelementptr inbounds [6 x [9 x double]], ptr @pyscf_grid_lvl5_forces_on_nuclei, i64 0, i64 %5, i64 3
  %27 = load double, ptr %26, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %0, i64 24
  %29 = load double, ptr %28, align 8, !tbaa !5
  %30 = fsub double %29, %27
  %31 = tail call double @llvm.fabs.f64(double %30)
  %32 = fcmp ogt double %31, %.1.2
  %.127.3 = select i1 %32, double %29, double %.127.2
  %.125.3 = select i1 %32, double %27, double %.125.2
  %.1.3 = select i1 %32, double %31, double %.1.2
  %33 = getelementptr inbounds [6 x [9 x double]], ptr @pyscf_grid_lvl5_forces_on_nuclei, i64 0, i64 %5, i64 4
  %34 = load double, ptr %33, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %0, i64 32
  %36 = load double, ptr %35, align 8, !tbaa !5
  %37 = fsub double %36, %34
  %38 = tail call double @llvm.fabs.f64(double %37)
  %39 = fcmp ogt double %38, %.1.3
  %.127.4 = select i1 %39, double %36, double %.127.3
  %.125.4 = select i1 %39, double %34, double %.125.3
  %.1.4 = select i1 %39, double %38, double %.1.3
  %40 = getelementptr inbounds [6 x [9 x double]], ptr @pyscf_grid_lvl5_forces_on_nuclei, i64 0, i64 %5, i64 5
  %41 = load double, ptr %40, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %0, i64 40
  %43 = load double, ptr %42, align 8, !tbaa !5
  %44 = fsub double %43, %41
  %45 = tail call double @llvm.fabs.f64(double %44)
  %46 = fcmp ogt double %45, %.1.4
  %.127.5 = select i1 %46, double %43, double %.127.4
  %.125.5 = select i1 %46, double %41, double %.125.4
  %.1.5 = select i1 %46, double %45, double %.1.4
  %47 = getelementptr inbounds [6 x [9 x double]], ptr @pyscf_grid_lvl5_forces_on_nuclei, i64 0, i64 %5, i64 6
  %48 = load double, ptr %47, align 8, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %0, i64 48
  %50 = load double, ptr %49, align 8, !tbaa !5
  %51 = fsub double %50, %48
  %52 = tail call double @llvm.fabs.f64(double %51)
  %53 = fcmp ogt double %52, %.1.5
  %.127.6 = select i1 %53, double %50, double %.127.5
  %.125.6 = select i1 %53, double %48, double %.125.5
  %.1.6 = select i1 %53, double %52, double %.1.5
  %54 = getelementptr inbounds [6 x [9 x double]], ptr @pyscf_grid_lvl5_forces_on_nuclei, i64 0, i64 %5, i64 7
  %55 = load double, ptr %54, align 8, !tbaa !5
  %56 = getelementptr inbounds i8, ptr %0, i64 56
  %57 = load double, ptr %56, align 8, !tbaa !5
  %58 = fsub double %57, %55
  %59 = tail call double @llvm.fabs.f64(double %58)
  %60 = fcmp ogt double %59, %.1.6
  %.127.7 = select i1 %60, double %57, double %.127.6
  %.125.7 = select i1 %60, double %55, double %.125.6
  %.1.7 = select i1 %60, double %59, double %.1.6
  %61 = getelementptr inbounds [6 x [9 x double]], ptr @pyscf_grid_lvl5_forces_on_nuclei, i64 0, i64 %5, i64 8
  %62 = load double, ptr %61, align 8, !tbaa !5
  %63 = getelementptr inbounds i8, ptr %0, i64 64
  %64 = load double, ptr %63, align 8, !tbaa !5
  %65 = fsub double %64, %62
  %66 = tail call double @llvm.fabs.f64(double %65)
  %67 = fcmp ogt double %66, %.1.7
  %.127.8 = select i1 %67, double %64, double %.127.7
  %.125.8 = select i1 %67, double %62, double %.125.7
  %.1.8 = select i1 %67, double %66, double %.1.7
  %68 = getelementptr inbounds [6 x ptr], ptr @CC_METHODS, i64 0, i64 %5
  %69 = load ptr, ptr %68, align 8, !tbaa !9
  %70 = load double, ptr @sanity_test_threshold, align 8, !tbaa !5
  %71 = fcmp olt double %.1.8, %70
  %72 = select i1 %71, ptr @.str.8, ptr @.str.9
  %73 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11, ptr noundef %69, double noundef %.127.8, double noundef %.125.8, double noundef %.1.8, double noundef %70, ptr noundef nonnull %72)
  br label %74

74:                                               ; preds = %2, %4
  %.0 = phi i64 [ 1, %4 ], [ 0, %2 ]
  ret i64 %.0
}

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

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass