; LLVM IR from mesbahamin/star-sim :: src (sim)

; 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.SimBounds = type { float, float, float, float }

; 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 void @sim_bounding_box_update(ptr noundef %0, float noundef %1, float noundef %2, float noundef %3, float noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  %11 = alloca float, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store float %1, ptr %7, align 4, !tbaa !9
  store float %2, ptr %8, align 4, !tbaa !9
  store float %3, ptr %9, align 4, !tbaa !9
  store float %4, ptr %10, align 4, !tbaa !9
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %15, label %14

14:                                               ; preds = %5
  br label %41

15:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %16 = load float, ptr %9, align 4, !tbaa !9
  %17 = load float, ptr %7, align 4, !tbaa !9
  %18 = fsub float %16, %17
  %19 = load float, ptr %10, align 4, !tbaa !9
  %20 = load float, ptr %8, align 4, !tbaa !9
  %21 = fsub float %19, %20
  %22 = call float @llvm.maxnum.f32(float %18, float %21)
  store float %22, ptr %11, align 4, !tbaa !9
  %23 = load float, ptr %11, align 4, !tbaa !9
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.SimBounds, ptr %24, i32 0, i32 2
  store float %23, ptr %25, align 4, !tbaa !11
  %26 = load float, ptr %11, align 4, !tbaa !9
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.SimBounds, ptr %27, i32 0, i32 3
  store float %26, ptr %28, align 4, !tbaa !13
  %29 = load float, ptr %7, align 4, !tbaa !9
  %30 = load float, ptr %9, align 4, !tbaa !9
  %31 = fadd float %29, %30
  %32 = fdiv float %31, 2.000000e+00
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.SimBounds, ptr %33, i32 0, i32 0
  store float %32, ptr %34, align 4, !tbaa !14
  %35 = load float, ptr %8, align 4, !tbaa !9
  %36 = load float, ptr %10, align 4, !tbaa !9
  %37 = fadd float %35, %36
  %38 = fdiv float %37, 2.000000e+00
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.SimBounds, ptr %39, i32 0, i32 1
  store float %38, ptr %40, align 4, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %41

41:                                               ; preds = %15, %14
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.maxnum.f32(float, float) #2

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 = { 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 = !{!"float", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"SimBounds", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!13 = !{!12, !10, i64 12}
!14 = !{!12, !10, i64 0}
!15 = !{!12, !10, i64 4}


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) uwtable
define dso_local void @sim_bounding_box_update(ptr noundef writeonly %0, float noundef %1, float noundef %2, float noundef %3, float noundef %4) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %18, label %6

6:                                                ; preds = %5
  %7 = fsub float %3, %1
  %8 = fsub float %4, %2
  %9 = tail call float @llvm.maxnum.f32(float %7, float %8)
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  store float %9, ptr %10, align 4, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %0, i64 12
  store float %9, ptr %11, align 4, !tbaa !10
  %12 = insertelement <2 x float> poison, float %1, i64 0
  %13 = insertelement <2 x float> %12, float %2, i64 1
  %14 = insertelement <2 x float> poison, float %3, i64 0
  %15 = insertelement <2 x float> %14, float %4, i64 1
  %16 = fadd <2 x float> %13, %15
  %17 = fmul <2 x float> %16, <float 5.000000e-01, float 5.000000e-01>
  store <2 x float> %17, ptr %0, align 4, !tbaa !11
  br label %18

18:                                               ; preds = %5, %6
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.maxnum.f32(float, float) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) 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) }

!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 8}
!6 = !{!"SimBounds", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 12}
!11 = !{!7, !7, i64 0}


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