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

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

@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [88 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

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

; 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 void @dft_total_energy(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca [32 x i8], align 16
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.dft_context, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %11, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.dft_context, ptr %12, i32 0, i32 1
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  store ptr %14, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.scf_context, ptr %15, i32 0, i32 1
  %17 = load i64, ptr %16, align 8, !tbaa !13
  store i64 %17, ptr %5, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.scf_context, ptr %18, i32 0, i32 22
  %20 = load ptr, ptr %19, align 8, !tbaa !17
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.scf_context, ptr %21, i32 0, i32 6
  %23 = load ptr, ptr %22, align 8, !tbaa !18
  %24 = load i64, ptr %5, align 8, !tbaa !16
  %25 = load i64, ptr %5, align 8, !tbaa !16
  %26 = call double @einsum_mn_nm(ptr noundef %20, ptr noundef %23, i64 noundef %24, i64 noundef %25)
  store double %26, ptr %6, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.scf_context, ptr %27, i32 0, i32 22
  %29 = load ptr, ptr %28, align 8, !tbaa !17
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.molecular_grid_desc, ptr %30, i32 0, i32 26
  %32 = load ptr, ptr %31, align 8, !tbaa !20
  %33 = load i64, ptr %5, align 8, !tbaa !16
  %34 = load i64, ptr %5, align 8, !tbaa !16
  %35 = call double @einsum_mn_nm(ptr noundef %29, ptr noundef %32, i64 noundef %33, i64 noundef %34)
  %36 = fmul double %35, 5.000000e-01
  store double %36, ptr %7, align 8, !tbaa !19
  %37 = load double, ptr %6, align 8, !tbaa !19
  %38 = load double, ptr %7, align 8, !tbaa !19
  %39 = fadd double %37, %38
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.scf_context, ptr %40, i32 0, i32 33
  %42 = load double, ptr %41, align 8, !tbaa !22
  %43 = fadd double %39, %42
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.molecular_grid_desc, ptr %44, i32 0, i32 29
  %46 = load double, ptr %45, align 8, !tbaa !23
  %47 = fadd double %43, %46
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.dft_context, ptr %48, i32 0, i32 2
  store double %47, ptr %49, align 8, !tbaa !24
  br label %50

50:                                               ; preds = %1
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.scf_context, ptr %51, i32 0, i32 55
  %53 = load i64, ptr %52, align 8, !tbaa !25
  %54 = icmp ne i64 %53, 0
  br i1 %54, label %74, label %55

55:                                               ; preds = %50
  call void @llvm.lifetime.start.p0(i64 32, ptr %8) #3
  %56 = getelementptr inbounds [32 x i8], ptr %8, i64 0, i64 0
  call void @current_time_str(ptr noundef %56, i64 noundef 32)
  %57 = getelementptr inbounds [32 x i8], ptr %8, i64 0, i64 0
  %58 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, ptr noundef %57)
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.dft_context, ptr %59, i32 0, i32 2
  %61 = load double, ptr %60, align 8, !tbaa !24
  %62 = load double, ptr %6, align 8, !tbaa !19
  %63 = load double, ptr %7, align 8, !tbaa !19
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.molecular_grid_desc, ptr %64, i32 0, i32 28
  %66 = load double, ptr %65, align 8, !tbaa !26
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.molecular_grid_desc, ptr %67, i32 0, i32 29
  %69 = load double, ptr %68, align 8, !tbaa !23
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.scf_context, ptr %70, i32 0, i32 33
  %72 = load double, ptr %71, align 8, !tbaa !22
  %73 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, double noundef %61, double noundef %62, double noundef %63, double noundef %66, double noundef %69, double noundef %72)
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #3
  br label %74

74:                                               ; preds = %55, %50
  br label %75

75:                                               ; preds = %74
  br label %76

76:                                               ; preds = %75
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

declare double @einsum_mn_nm(ptr noundef, ptr noundef, i64 noundef, i64 noundef) #1

declare void @current_time_str(ptr noundef, i64 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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, !6, i64 0}
!10 = !{!"dft_context", !6, i64 0, !6, i64 8, !11, i64 16}
!11 = !{!"double", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!14, !15, i64 8}
!14 = !{!"scf_context", !6, i64 0, !15, i64 8, !15, i64 16, !15, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !11, i64 192, !15, i64 200, !11, i64 208, !11, i64 216, !11, i64 224, !15, i64 232, !11, i64 240, !11, i64 248, !15, i64 256, !11, i64 264, !15, i64 272, !15, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !15, i64 312, !15, i64 320, !15, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !6, i64 392, !11, i64 400, !6, i64 408, !6, i64 416, !6, i64 424, !6, i64 432, !15, i64 440}
!15 = !{!"long", !7, i64 0}
!16 = !{!15, !15, i64 0}
!17 = !{!14, !6, i64 176}
!18 = !{!14, !6, i64 48}
!19 = !{!11, !11, i64 0}
!20 = !{!21, !6, i64 208}
!21 = !{!"molecular_grid_desc", !6, i64 0, !15, i64 8, !15, i64 16, !15, i64 24, !15, i64 32, !15, i64 40, !6, i64 48, !6, i64 56, !15, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !11, i64 224, !11, i64 232, !11, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !15, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !6, i64 392, !6, i64 400, !6, i64 408, !6, i64 416, !6, i64 424, !6, i64 432, !6, i64 440, !6, i64 448, !6, i64 456, !6, i64 464, !6, i64 472, !6, i64 480, !6, i64 488, !6, i64 496, !6, i64 504, !6, i64 512, !6, i64 520, !6, i64 528, !6, i64 536, !6, i64 544, !6, i64 552, !15, i64 560, !15, i64 568, !6, i64 576, !6, i64 584, !6, i64 592, !6, i64 600, !6, i64 608}
!22 = !{!14, !11, i64 264}
!23 = !{!21, !11, i64 232}
!24 = !{!10, !11, i64 16}
!25 = !{!14, !15, i64 440}
!26 = !{!21, !11, i64 224}


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

@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [88 x i8], align 1

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

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

; Function Attrs: mustprogress 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 void @dft_total_energy(ptr nocapture noundef %0) local_unnamed_addr #2 {
  %2 = alloca [32 x i8], align 16
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !11
  %6 = getelementptr inbounds i8, ptr %3, i64 8
  %7 = load i64, ptr %6, align 8, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %3, i64 176
  %9 = load ptr, ptr %8, align 8, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %3, i64 48
  %11 = load ptr, ptr %10, align 8, !tbaa !16
  %12 = tail call double @einsum_mn_nm(ptr noundef %9, ptr noundef %11, i64 noundef %7, i64 noundef %7) #4
  %13 = load ptr, ptr %8, align 8, !tbaa !15
  %14 = getelementptr inbounds i8, ptr %5, i64 208
  %15 = load ptr, ptr %14, align 8, !tbaa !17
  %16 = tail call double @einsum_mn_nm(ptr noundef %13, ptr noundef %15, i64 noundef %7, i64 noundef %7) #4
  %17 = fmul double %16, 5.000000e-01
  %18 = fadd double %12, %17
  %19 = getelementptr inbounds i8, ptr %3, i64 264
  %20 = load double, ptr %19, align 8, !tbaa !19
  %21 = fadd double %20, %18
  %22 = getelementptr inbounds i8, ptr %5, i64 232
  %23 = load double, ptr %22, align 8, !tbaa !20
  %24 = fadd double %23, %21
  %25 = getelementptr inbounds i8, ptr %0, i64 16
  store double %24, ptr %25, align 8, !tbaa !21
  %26 = getelementptr inbounds i8, ptr %3, i64 440
  %27 = load i64, ptr %26, align 8, !tbaa !22
  %.not = icmp eq i64 %27, 0
  br i1 %.not, label %28, label %36

28:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #4
  call void @current_time_str(ptr noundef nonnull %2, i64 noundef 32) #4
  %29 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, ptr noundef nonnull %2)
  %30 = load double, ptr %25, align 8, !tbaa !21
  %31 = getelementptr inbounds i8, ptr %5, i64 224
  %32 = load double, ptr %31, align 8, !tbaa !23
  %33 = load double, ptr %22, align 8, !tbaa !20
  %34 = load double, ptr %19, align 8, !tbaa !19
  %35 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, double noundef %30, double noundef %12, double noundef %17, double noundef %32, double noundef %33, double noundef %34)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #4
  br label %36

36:                                               ; preds = %28, %1
  ret void
}

declare double @einsum_mn_nm(ptr noundef, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #3

declare void @current_time_str(ptr noundef, i64 noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { "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, !7, i64 0}
!6 = !{!"dft_context", !7, i64 0, !7, i64 8, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!13, !14, i64 8}
!13 = !{!"scf_context", !7, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !7, i64 120, !7, i64 128, !7, i64 136, !7, i64 144, !7, i64 152, !7, i64 160, !7, i64 168, !7, i64 176, !7, i64 184, !10, i64 192, !14, i64 200, !10, i64 208, !10, i64 216, !10, i64 224, !14, i64 232, !10, i64 240, !10, i64 248, !14, i64 256, !10, i64 264, !14, i64 272, !14, i64 280, !7, i64 288, !7, i64 296, !7, i64 304, !14, i64 312, !14, i64 320, !14, i64 328, !7, i64 336, !7, i64 344, !7, i64 352, !7, i64 360, !7, i64 368, !7, i64 376, !7, i64 384, !7, i64 392, !10, i64 400, !7, i64 408, !7, i64 416, !7, i64 424, !7, i64 432, !14, i64 440}
!14 = !{!"long", !8, i64 0}
!15 = !{!13, !7, i64 176}
!16 = !{!13, !7, i64 48}
!17 = !{!18, !7, i64 208}
!18 = !{!"molecular_grid_desc", !7, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !14, i64 40, !7, i64 48, !7, i64 56, !14, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !7, i64 120, !7, i64 128, !7, i64 136, !7, i64 144, !7, i64 152, !7, i64 160, !7, i64 168, !7, i64 176, !7, i64 184, !7, i64 192, !7, i64 200, !7, i64 208, !7, i64 216, !10, i64 224, !10, i64 232, !10, i64 240, !7, i64 248, !7, i64 256, !7, i64 264, !7, i64 272, !14, i64 280, !7, i64 288, !7, i64 296, !7, i64 304, !7, i64 312, !7, i64 320, !7, i64 328, !7, i64 336, !7, i64 344, !7, i64 352, !7, i64 360, !7, i64 368, !7, i64 376, !7, i64 384, !7, i64 392, !7, i64 400, !7, i64 408, !7, i64 416, !7, i64 424, !7, i64 432, !7, i64 440, !7, i64 448, !7, i64 456, !7, i64 464, !7, i64 472, !7, i64 480, !7, i64 488, !7, i64 496, !7, i64 504, !7, i64 512, !7, i64 520, !7, i64 528, !7, i64 536, !7, i64 544, !7, i64 552, !14, i64 560, !14, i64 568, !7, i64 576, !7, i64 584, !7, i64 592, !7, i64 600, !7, i64 608}
!19 = !{!13, !10, i64 264}
!20 = !{!18, !10, i64 232}
!21 = !{!6, !10, i64 16}
!22 = !{!13, !14, i64 440}
!23 = !{!18, !10, i64 224}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass