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

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

; Function Attrs: nounwind uwtable
define dso_local void @calc_bfvalues_derivatives(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  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.molecular_grid_desc, ptr %9, i32 0, i32 76
  %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.molecular_grid_desc, ptr %12, i32 0, i32 8
  %14 = load i64, ptr %13, align 8, !tbaa !13
  store i64 %14, ptr %4, align 8, !tbaa !14
  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 !15
  store i64 %17, ptr %5, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !14
  br label %18

18:                                               ; preds = %56, %1
  %19 = load i64, ptr %6, align 8, !tbaa !14
  %20 = load i64, ptr %5, align 8, !tbaa !14
  %21 = icmp ult i64 %19, %20
  br i1 %21, label %23, label %22

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

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.scf_context, ptr %24, i32 0, i32 4
  %26 = load ptr, ptr %25, align 8, !tbaa !17
  %27 = load i64, ptr %6, align 8, !tbaa !14
  %28 = getelementptr inbounds %struct.basis_func, ptr %26, i64 %27
  store ptr %28, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %29 = call ptr @x_malloc(i64 noundef 40)
  store ptr %29, ptr %8, align 8, !tbaa !5
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.task_func_bfvalues_derivatives_arg, ptr %31, i32 0, i32 0
  store ptr %30, ptr %32, align 8, !tbaa !18
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.task_func_bfvalues_derivatives_arg, ptr %34, i32 0, i32 1
  store ptr %33, ptr %35, align 8, !tbaa !20
  %36 = load i64, ptr %4, align 8, !tbaa !14
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.task_func_bfvalues_derivatives_arg, ptr %37, i32 0, i32 2
  store i64 %36, ptr %38, align 8, !tbaa !21
  %39 = load i64, ptr %5, align 8, !tbaa !14
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.task_func_bfvalues_derivatives_arg, ptr %40, i32 0, i32 3
  store i64 %39, ptr %41, align 8, !tbaa !22
  %42 = load i64, ptr %6, align 8, !tbaa !14
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.task_func_bfvalues_derivatives_arg, ptr %43, i32 0, i32 4
  store i64 %42, ptr %44, align 8, !tbaa !23
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.scf_context, ptr %45, i32 0, i32 36
  %47 = load ptr, ptr %46, align 8, !tbaa !24
  %48 = load i64, ptr %6, align 8, !tbaa !14
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.scf_context, ptr %49, i32 0, i32 36
  %51 = load ptr, ptr %50, align 8, !tbaa !24
  %52 = getelementptr inbounds %struct.threadpool_context, ptr %51, i32 0, i32 0
  %53 = load i64, ptr %52, align 8, !tbaa !25
  %54 = urem i64 %48, %53
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  call void @threadpool_add_task(ptr noundef %47, i64 noundef %54, ptr noundef @task_func_bfvalues_derivatives, ptr noundef %55)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %56

56:                                               ; preds = %23
  %57 = load i64, ptr %6, align 8, !tbaa !14
  %58 = add i64 %57, 1
  store i64 %58, ptr %6, align 8, !tbaa !14
  br label %18, !llvm.loop !27

59:                                               ; preds = %22
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.scf_context, ptr %60, i32 0, i32 36
  %62 = load ptr, ptr %61, align 8, !tbaa !24
  call void @threadpool_wait_job_done(ptr noundef %62)
  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
}

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

declare ptr @x_malloc(i64 noundef) #2

declare void @threadpool_add_task(ptr noundef, i64 noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @task_func_bfvalues_derivatives(ptr noundef) #0

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

declare void @threadpool_wait_job_done(ptr noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }

!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 608}
!10 = !{!"molecular_grid_desc", !6, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !6, i64 48, !6, i64 56, !11, 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, !12, i64 224, !12, i64 232, !12, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !11, 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, !11, i64 560, !11, i64 568, !6, i64 576, !6, i64 584, !6, i64 592, !6, i64 600, !6, i64 608}
!11 = !{!"long", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!10, !11, i64 64}
!14 = !{!11, !11, i64 0}
!15 = !{!16, !11, i64 8}
!16 = !{!"scf_context", !6, i64 0, !11, i64 8, !11, i64 16, !11, 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, !12, i64 192, !11, i64 200, !12, i64 208, !12, i64 216, !12, i64 224, !11, i64 232, !12, i64 240, !12, i64 248, !11, i64 256, !12, i64 264, !11, i64 272, !11, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !11, i64 312, !11, i64 320, !11, 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, !12, i64 400, !6, i64 408, !6, i64 416, !6, i64 424, !6, i64 432, !11, i64 440}
!17 = !{!16, !6, i64 32}
!18 = !{!19, !6, i64 0}
!19 = !{!"task_func_bfvalues_derivatives_arg", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!20 = !{!19, !6, i64 8}
!21 = !{!19, !11, i64 16}
!22 = !{!19, !11, i64 24}
!23 = !{!19, !11, i64 32}
!24 = !{!16, !6, i64 288}
!25 = !{!26, !11, i64 0}
!26 = !{!"threadpool_context", !11, i64 0, !6, i64 8, !7, i64 16}
!27 = distinct !{!27, !28}
!28 = !{!"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.basis_func = type { i64, i64, i64, i64, ptr, ptr, ptr, double, double, double, double }

; Function Attrs: nounwind uwtable
define dso_local void @calc_bfvalues_derivatives(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 608
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 64
  %5 = load i64, ptr %4, align 8, !tbaa !12
  %6 = getelementptr inbounds i8, ptr %3, i64 8
  %7 = load i64, ptr %6, align 8, !tbaa !13
  %.not = icmp eq i64 %7, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %8 = getelementptr inbounds i8, ptr %3, i64 32
  %9 = getelementptr inbounds i8, ptr %3, i64 288
  br label %12

._crit_edge:                                      ; preds = %12, %1
  %10 = getelementptr inbounds i8, ptr %3, i64 288
  %11 = load ptr, ptr %10, align 8, !tbaa !15
  tail call void @threadpool_wait_job_done(ptr noundef %11) #2
  ret void

12:                                               ; preds = %.lr.ph, %12
  %.023 = phi i64 [ 0, %.lr.ph ], [ %23, %12 ]
  %13 = load ptr, ptr %8, align 8, !tbaa !16
  %14 = getelementptr inbounds %struct.basis_func, ptr %13, i64 %.023
  %15 = tail call ptr @x_malloc(i64 noundef 40) #2
  store ptr %0, ptr %15, align 8, !tbaa !17
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  store ptr %14, ptr %16, align 8, !tbaa !19
  %17 = getelementptr inbounds i8, ptr %15, i64 16
  store i64 %5, ptr %17, align 8, !tbaa !20
  %18 = getelementptr inbounds i8, ptr %15, i64 24
  store i64 %7, ptr %18, align 8, !tbaa !21
  %19 = getelementptr inbounds i8, ptr %15, i64 32
  store i64 %.023, ptr %19, align 8, !tbaa !22
  %20 = load ptr, ptr %9, align 8, !tbaa !15
  %21 = load i64, ptr %20, align 8, !tbaa !23
  %22 = urem i64 %.023, %21
  tail call void @threadpool_add_task(ptr noundef nonnull %20, i64 noundef %22, ptr noundef nonnull @task_func_bfvalues_derivatives, ptr noundef nonnull %15) #2
  %23 = add nuw i64 %.023, 1
  %exitcond.not = icmp eq i64 %23, %7
  br i1 %exitcond.not, label %._crit_edge, label %12, !llvm.loop !25
}

declare ptr @x_malloc(i64 noundef) local_unnamed_addr #1

declare void @threadpool_add_task(ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @task_func_bfvalues_derivatives(ptr noundef) #0

declare void @threadpool_wait_job_done(ptr noundef) local_unnamed_addr #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 = { "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 }

!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 608}
!6 = !{!"molecular_grid_desc", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !7, i64 48, !7, i64 56, !10, 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, !11, i64 224, !11, i64 232, !11, i64 240, !7, i64 248, !7, i64 256, !7, i64 264, !7, i64 272, !10, 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, !10, i64 560, !10, i64 568, !7, i64 576, !7, i64 584, !7, i64 592, !7, i64 600, !7, i64 608}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"double", !8, i64 0}
!12 = !{!6, !10, i64 64}
!13 = !{!14, !10, i64 8}
!14 = !{!"scf_context", !7, i64 0, !10, i64 8, !10, i64 16, !10, 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, !11, i64 192, !10, i64 200, !11, i64 208, !11, i64 216, !11, i64 224, !10, i64 232, !11, i64 240, !11, i64 248, !10, i64 256, !11, i64 264, !10, i64 272, !10, i64 280, !7, i64 288, !7, i64 296, !7, i64 304, !10, i64 312, !10, i64 320, !10, 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, !11, i64 400, !7, i64 408, !7, i64 416, !7, i64 424, !7, i64 432, !10, i64 440}
!15 = !{!14, !7, i64 288}
!16 = !{!14, !7, i64 32}
!17 = !{!18, !7, i64 0}
!18 = !{!"task_func_bfvalues_derivatives_arg", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!19 = !{!18, !7, i64 8}
!20 = !{!18, !10, i64 16}
!21 = !{!18, !10, i64 24}
!22 = !{!18, !10, i64 32}
!23 = !{!24, !10, i64 0}
!24 = !{!"threadpool_context", !10, i64 0, !7, i64 8, !8, i64 16}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}


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