; LLVM IR from ANL-CESAR/XSBench :: opencl (Simulation)

; 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.NuclideGridPoint = type { double, double, double, double, double, double }

; 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 @grid_search_nuclide(i64 noundef %0, double noundef %1, ptr noundef %2, i64 noundef %3, i64 noundef %4) #1 {
  %6 = alloca i64, align 8
  %7 = alloca double, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  store i64 %0, ptr %6, align 8, !tbaa !5
  store double %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !11
  store i64 %3, ptr %9, align 8, !tbaa !5
  store i64 %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %15 = load i64, ptr %9, align 8, !tbaa !5
  store i64 %15, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %16 = load i64, ptr %10, align 8, !tbaa !5
  store i64 %16, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #2
  %17 = load i64, ptr %12, align 8, !tbaa !5
  %18 = load i64, ptr %11, align 8, !tbaa !5
  %19 = sub nsw i64 %17, %18
  store i64 %19, ptr %14, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %39, %5
  %21 = load i64, ptr %14, align 8, !tbaa !5
  %22 = icmp sgt i64 %21, 1
  br i1 %22, label %23, label %43

23:                                               ; preds = %20
  %24 = load i64, ptr %11, align 8, !tbaa !5
  %25 = load i64, ptr %14, align 8, !tbaa !5
  %26 = sdiv i64 %25, 2
  %27 = add nsw i64 %24, %26
  store i64 %27, ptr %13, align 8, !tbaa !5
  %28 = load ptr, ptr %8, align 8, !tbaa !11
  %29 = load i64, ptr %13, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.NuclideGridPoint, ptr %28, i64 %29
  %31 = getelementptr inbounds %struct.NuclideGridPoint, ptr %30, i32 0, i32 0
  %32 = load double, ptr %31, align 8, !tbaa !13
  %33 = load double, ptr %7, align 8, !tbaa !9
  %34 = fcmp ogt double %32, %33
  br i1 %34, label %35, label %37

35:                                               ; preds = %23
  %36 = load i64, ptr %13, align 8, !tbaa !5
  store i64 %36, ptr %12, align 8, !tbaa !5
  br label %39

37:                                               ; preds = %23
  %38 = load i64, ptr %13, align 8, !tbaa !5
  store i64 %38, ptr %11, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %37, %35
  %40 = load i64, ptr %12, align 8, !tbaa !5
  %41 = load i64, ptr %11, align 8, !tbaa !5
  %42 = sub nsw i64 %40, %41
  store i64 %42, ptr %14, align 8, !tbaa !5
  br label %20, !llvm.loop !15

43:                                               ; preds = %20
  %44 = load i64, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  ret i64 %44
}

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 = { 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 = !{!"long", !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 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!15 = distinct !{!15, !16}
!16 = !{!"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.NuclideGridPoint = type { double, double, double, double, double, double }

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: read) uwtable
define dso_local i64 @grid_search_nuclide(i64 noundef %0, double noundef %1, ptr nocapture noundef readonly %2, i64 noundef %3, i64 noundef %4) local_unnamed_addr #0 {
  %6 = sub nsw i64 %4, %3
  %7 = icmp sgt i64 %6, 1
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5, %.lr.ph
  %.019 = phi i64 [ %13, %.lr.ph ], [ %6, %5 ]
  %.01418 = phi i64 [ %.014., %.lr.ph ], [ %3, %5 ]
  %.01517 = phi i64 [ %..015, %.lr.ph ], [ %4, %5 ]
  %8 = lshr i64 %.019, 1
  %9 = add nsw i64 %8, %.01418
  %10 = getelementptr inbounds %struct.NuclideGridPoint, ptr %2, i64 %9
  %11 = load double, ptr %10, align 8, !tbaa !5
  %12 = fcmp ogt double %11, %1
  %..015 = select i1 %12, i64 %9, i64 %.01517
  %.014. = select i1 %12, i64 %.01418, i64 %9
  %13 = sub nsw i64 %..015, %.014.
  %14 = icmp sgt i64 %13, 1
  br i1 %14, label %.lr.ph, label %._crit_edge, !llvm.loop !10

._crit_edge:                                      ; preds = %.lr.ph, %5
  %.014.lcssa = phi i64 [ %3, %5 ], [ %.014., %.lr.ph ]
  ret i64 %.014.lcssa
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: read) 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass