; 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_lvl3_energy_11e_results = external dso_local global [6 x double], align 16
@pyscf_grid_lvl4_energy_11e_results = external dso_local global [6 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.7 = external hidden unnamed_addr constant [90 x i8], align 1
@.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.10 = external hidden unnamed_addr constant [90 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: nounwind uwtable
define dso_local i64 @check_total_energy(double noundef %0, i64 noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca double, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca double, align 8
  store double %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %8 = load i64, ptr %5, align 8, !tbaa !9
  %9 = icmp ult i64 %8, 1
  br i1 %9, label %13, label %10

10:                                               ; preds = %2
  %11 = load i64, ptr %5, align 8, !tbaa !9
  %12 = icmp ugt i64 %11, 6
  br i1 %12, label %13, label %14

13:                                               ; preds = %10, %2
  store i64 0, ptr %3, align 8
  br label %59

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %15 = load i64, ptr %5, align 8, !tbaa !9
  %16 = sub i64 %15, 1
  store i64 %16, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %17 = load double, ptr %4, align 8, !tbaa !5
  %18 = load i64, ptr %6, align 8, !tbaa !9
  %19 = getelementptr inbounds [6 x double], ptr @pyscf_grid_lvl3_energy_11e_results, i64 0, i64 %18
  %20 = load double, ptr %19, align 8, !tbaa !5
  %21 = fsub double %17, %20
  %22 = call double @llvm.fabs.f64(double %21)
  store double %22, ptr %7, align 8, !tbaa !5
  %23 = load i64, ptr %6, align 8, !tbaa !9
  %24 = getelementptr inbounds [6 x ptr], ptr @CC_METHODS, i64 0, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = load double, ptr %4, align 8, !tbaa !5
  %27 = load i64, ptr %6, align 8, !tbaa !9
  %28 = getelementptr inbounds [6 x double], ptr @pyscf_grid_lvl3_energy_11e_results, i64 0, i64 %27
  %29 = load double, ptr %28, align 8, !tbaa !5
  %30 = load double, ptr %7, align 8, !tbaa !5
  %31 = load double, ptr @sanity_test_threshold, align 8, !tbaa !5
  %32 = load double, ptr %7, align 8, !tbaa !5
  %33 = load double, ptr @sanity_test_threshold, align 8, !tbaa !5
  %34 = fcmp olt double %32, %33
  %35 = zext i1 %34 to i64
  %36 = select i1 %34, ptr @.str.8, ptr @.str.9
  %37 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, ptr noundef %25, double noundef %26, double noundef %29, double noundef %30, double noundef %31, ptr noundef %36)
  %38 = load double, ptr %4, align 8, !tbaa !5
  %39 = load i64, ptr %6, align 8, !tbaa !9
  %40 = getelementptr inbounds [6 x double], ptr @pyscf_grid_lvl4_energy_11e_results, i64 0, i64 %39
  %41 = load double, ptr %40, align 8, !tbaa !5
  %42 = fsub double %38, %41
  %43 = call double @llvm.fabs.f64(double %42)
  store double %43, ptr %7, align 8, !tbaa !5
  %44 = load i64, ptr %6, align 8, !tbaa !9
  %45 = getelementptr inbounds [6 x ptr], ptr @CC_METHODS, i64 0, i64 %44
  %46 = load ptr, ptr %45, align 8, !tbaa !11
  %47 = load double, ptr %4, align 8, !tbaa !5
  %48 = load i64, ptr %6, align 8, !tbaa !9
  %49 = getelementptr inbounds [6 x double], ptr @pyscf_grid_lvl4_energy_11e_results, i64 0, i64 %48
  %50 = load double, ptr %49, align 8, !tbaa !5
  %51 = load double, ptr %7, align 8, !tbaa !5
  %52 = load double, ptr @sanity_test_threshold, align 8, !tbaa !5
  %53 = load double, ptr %7, align 8, !tbaa !5
  %54 = load double, ptr @sanity_test_threshold, align 8, !tbaa !5
  %55 = fcmp olt double %53, %54
  %56 = zext i1 %55 to i64
  %57 = select i1 %55, ptr @.str.8, ptr @.str.9
  %58 = call i32 (ptr, ...) @printf(ptr noundef @.str.10, ptr noundef %46, double noundef %47, double noundef %50, double noundef %51, double noundef %52, ptr noundef %57)
  store i64 1, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %59

59:                                               ; preds = %14, %13
  %60 = load i64, ptr %3, align 8
  ret i64 %60
}

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { "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 = !{!"double", !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 = !{!"any pointer", !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"

@pyscf_grid_lvl3_energy_11e_results = external dso_local local_unnamed_addr global [6 x double], align 16
@pyscf_grid_lvl4_energy_11e_results = external dso_local local_unnamed_addr global [6 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.7 = external hidden unnamed_addr constant [90 x i8], align 1
@.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.10 = external hidden unnamed_addr constant [90 x i8], align 1

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

4:                                                ; preds = %2
  %5 = add nsw i64 %1, -1
  %6 = getelementptr inbounds [6 x double], ptr @pyscf_grid_lvl3_energy_11e_results, i64 0, i64 %5
  %7 = load double, ptr %6, align 8, !tbaa !5
  %8 = fsub double %0, %7
  %9 = tail call double @llvm.fabs.f64(double %8)
  %10 = getelementptr inbounds [6 x ptr], ptr @CC_METHODS, i64 0, i64 %5
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = load double, ptr @sanity_test_threshold, align 8, !tbaa !5
  %13 = fcmp olt double %9, %12
  %14 = select i1 %13, ptr @.str.8, ptr @.str.9
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef %11, double noundef %0, double noundef %7, double noundef %9, double noundef %12, ptr noundef nonnull %14)
  %16 = getelementptr inbounds [6 x double], ptr @pyscf_grid_lvl4_energy_11e_results, i64 0, i64 %5
  %17 = load double, ptr %16, align 8, !tbaa !5
  %18 = fsub double %0, %17
  %19 = tail call double @llvm.fabs.f64(double %18)
  %20 = load ptr, ptr %10, align 8, !tbaa !9
  %21 = load double, ptr @sanity_test_threshold, align 8, !tbaa !5
  %22 = fcmp olt double %19, %21
  %23 = select i1 %22, ptr @.str.8, ptr @.str.9
  %24 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10, ptr noundef %20, double noundef %0, double noundef %17, double noundef %19, double noundef %21, ptr noundef nonnull %23)
  br label %25

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

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

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

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

!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,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass