; LLVM IR from hans-ob1/neural_cam_ros :: src/detector (blas)

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

; 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 @softmax(ptr noundef %0, i32 noundef %1, float noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca float, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca float, align 4
  %11 = alloca float, align 4
  %12 = alloca float, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store float %2, ptr %7, align 4, !tbaa !11
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store float 0.000000e+00, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store float 0xC7EFFFFFE0000000, ptr %11, align 4, !tbaa !11
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %32, %4
  %14 = load i32, ptr %9, align 4, !tbaa !9
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %17, label %35

17:                                               ; preds = %13
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds float, ptr %18, i64 %20
  %22 = load float, ptr %21, align 4, !tbaa !11
  %23 = load float, ptr %11, align 4, !tbaa !11
  %24 = fcmp ogt float %22, %23
  br i1 %24, label %25, label %31

25:                                               ; preds = %17
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds float, ptr %26, i64 %28
  %30 = load float, ptr %29, align 4, !tbaa !11
  store float %30, ptr %11, align 4, !tbaa !11
  br label %31

31:                                               ; preds = %25, %17
  br label %32

32:                                               ; preds = %31
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %9, align 4, !tbaa !9
  br label %13, !llvm.loop !13

35:                                               ; preds = %13
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %63, %35
  %37 = load i32, ptr %9, align 4, !tbaa !9
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %40, label %66

40:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load i32, ptr %9, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds float, ptr %41, i64 %43
  %45 = load float, ptr %44, align 4, !tbaa !11
  %46 = load float, ptr %7, align 4, !tbaa !11
  %47 = fdiv float %45, %46
  %48 = load float, ptr %11, align 4, !tbaa !11
  %49 = load float, ptr %7, align 4, !tbaa !11
  %50 = fdiv float %48, %49
  %51 = fsub float %47, %50
  %52 = fpext float %51 to double
  %53 = call double @exp(double noundef %52) #3
  %54 = fptrunc double %53 to float
  store float %54, ptr %12, align 4, !tbaa !11
  %55 = load float, ptr %12, align 4, !tbaa !11
  %56 = load float, ptr %10, align 4, !tbaa !11
  %57 = fadd float %56, %55
  store float %57, ptr %10, align 4, !tbaa !11
  %58 = load float, ptr %12, align 4, !tbaa !11
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = load i32, ptr %9, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds float, ptr %59, i64 %61
  store float %58, ptr %62, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %63

63:                                               ; preds = %40
  %64 = load i32, ptr %9, align 4, !tbaa !9
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %9, align 4, !tbaa !9
  br label %36, !llvm.loop !15

66:                                               ; preds = %36
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %67

67:                                               ; preds = %79, %66
  %68 = load i32, ptr %9, align 4, !tbaa !9
  %69 = load i32, ptr %6, align 4, !tbaa !9
  %70 = icmp slt i32 %68, %69
  br i1 %70, label %71, label %82

71:                                               ; preds = %67
  %72 = load float, ptr %10, align 4, !tbaa !11
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = load i32, ptr %9, align 4, !tbaa !9
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds float, ptr %73, i64 %75
  %77 = load float, ptr %76, align 4, !tbaa !11
  %78 = fdiv float %77, %72
  store float %78, ptr %76, align 4, !tbaa !11
  br label %79

79:                                               ; preds = %71
  %80 = load i32, ptr %9, align 4, !tbaa !9
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %9, align 4, !tbaa !9
  br label %67, !llvm.loop !16

82:                                               ; preds = %67
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret void
}

; Function Attrs: nounwind
declare double @exp(double noundef) #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 = { 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 #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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


; 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: nofree nounwind memory(write, argmem: readwrite) uwtable
define dso_local void @softmax(ptr nocapture noundef readonly %0, i32 noundef %1, float noundef %2, ptr nocapture noundef %3) local_unnamed_addr #0 {
  %5 = icmp sgt i32 %1, 0
  br i1 %5, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %4
  %wide.trip.count = zext nneg i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %6 = icmp ult i32 %1, 4
  br i1 %6, label %.preheader31.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483644
  br label %.lr.ph

.preheader31.unr-lcssa:                           ; preds = %.lr.ph, %.lr.ph.preheader
  %.127.lcssa.ph = phi float [ poison, %.lr.ph.preheader ], [ %.127.3, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %.02632.unr = phi float [ 0xC7EFFFFFE0000000, %.lr.ph.preheader ], [ %.127.3, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader31, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.preheader31.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %.preheader31.unr-lcssa ]
  %.02632.epil = phi float [ %.127.epil, %.lr.ph.epil ], [ %.02632.unr, %.preheader31.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %.preheader31.unr-lcssa ]
  %7 = getelementptr inbounds float, ptr %0, i64 %indvars.iv.epil
  %8 = load float, ptr %7, align 4, !tbaa !5
  %9 = fcmp ogt float %8, %.02632.epil
  %.127.epil = select i1 %9, float %8, float %.02632.epil
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.preheader31, label %.lr.ph.epil, !llvm.loop !9

.preheader31:                                     ; preds = %.lr.ph.epil, %.preheader31.unr-lcssa
  %.127.lcssa = phi float [ %.127.lcssa.ph, %.preheader31.unr-lcssa ], [ %.127.epil, %.lr.ph.epil ]
  br i1 %5, label %.lr.ph36, label %._crit_edge

.lr.ph36:                                         ; preds = %.preheader31
  %10 = fdiv float %.127.lcssa, %2
  %wide.trip.count44 = zext nneg i32 %1 to i64
  br label %26

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %.02632 = phi float [ 0xC7EFFFFFE0000000, %.lr.ph.preheader.new ], [ %.127.3, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %11 = getelementptr inbounds float, ptr %0, i64 %indvars.iv
  %12 = load float, ptr %11, align 4, !tbaa !5
  %13 = fcmp ogt float %12, %.02632
  %.127 = select i1 %13, float %12, float %.02632
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %14 = getelementptr inbounds float, ptr %0, i64 %indvars.iv.next
  %15 = load float, ptr %14, align 4, !tbaa !5
  %16 = fcmp ogt float %15, %.127
  %.127.1 = select i1 %16, float %15, float %.127
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %17 = getelementptr inbounds float, ptr %0, i64 %indvars.iv.next.1
  %18 = load float, ptr %17, align 4, !tbaa !5
  %19 = fcmp ogt float %18, %.127.1
  %.127.2 = select i1 %19, float %18, float %.127.1
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %20 = getelementptr inbounds float, ptr %0, i64 %indvars.iv.next.2
  %21 = load float, ptr %20, align 4, !tbaa !5
  %22 = fcmp ogt float %21, %.127.2
  %.127.3 = select i1 %22, float %21, float %.127.2
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.preheader31.unr-lcssa, label %.lr.ph, !llvm.loop !11

.preheader:                                       ; preds = %26
  br i1 %5, label %.lr.ph39.preheader, label %._crit_edge

.lr.ph39.preheader:                               ; preds = %.preheader
  %wide.trip.count49 = zext nneg i32 %1 to i64
  %min.iters.check = icmp ult i32 %1, 4
  br i1 %min.iters.check, label %.lr.ph39.preheader53, label %vector.ph

.lr.ph39.preheader53:                             ; preds = %middle.block, %.lr.ph39.preheader
  %indvars.iv46.ph = phi i64 [ 0, %.lr.ph39.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph39

vector.ph:                                        ; preds = %.lr.ph39.preheader
  %n.vec = and i64 %wide.trip.count, 2147483644
  %broadcast.splatinsert = insertelement <4 x float> poison, float %34, i64 0
  %broadcast.splat = shufflevector <4 x float> %broadcast.splatinsert, <4 x float> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %23 = getelementptr inbounds float, ptr %3, i64 %index
  %wide.load = load <4 x float>, ptr %23, align 4, !tbaa !5
  %24 = fdiv <4 x float> %wide.load, %broadcast.splat
  store <4 x float> %24, ptr %23, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %25 = icmp eq i64 %index.next, %n.vec
  br i1 %25, label %middle.block, label %vector.body, !llvm.loop !13

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph39.preheader53

26:                                               ; preds = %.lr.ph36, %26
  %indvars.iv41 = phi i64 [ 0, %.lr.ph36 ], [ %indvars.iv.next42, %26 ]
  %.02834 = phi float [ 0.000000e+00, %.lr.ph36 ], [ %34, %26 ]
  %27 = getelementptr inbounds float, ptr %0, i64 %indvars.iv41
  %28 = load float, ptr %27, align 4, !tbaa !5
  %29 = fdiv float %28, %2
  %30 = fsub float %29, %10
  %31 = fpext float %30 to double
  %32 = tail call double @exp(double noundef %31) #2
  %33 = fptrunc double %32 to float
  %34 = fadd float %.02834, %33
  %35 = getelementptr inbounds float, ptr %3, i64 %indvars.iv41
  store float %33, ptr %35, align 4, !tbaa !5
  %indvars.iv.next42 = add nuw nsw i64 %indvars.iv41, 1
  %exitcond45.not = icmp eq i64 %indvars.iv.next42, %wide.trip.count44
  br i1 %exitcond45.not, label %.preheader, label %26, !llvm.loop !16

.lr.ph39:                                         ; preds = %.lr.ph39.preheader53, %.lr.ph39
  %indvars.iv46 = phi i64 [ %indvars.iv.next47, %.lr.ph39 ], [ %indvars.iv46.ph, %.lr.ph39.preheader53 ]
  %36 = getelementptr inbounds float, ptr %3, i64 %indvars.iv46
  %37 = load float, ptr %36, align 4, !tbaa !5
  %38 = fdiv float %37, %34
  store float %38, ptr %36, align 4, !tbaa !5
  %indvars.iv.next47 = add nuw nsw i64 %indvars.iv46, 1
  %exitcond50.not = icmp eq i64 %indvars.iv.next47, %wide.trip.count49
  br i1 %exitcond50.not, label %._crit_edge, label %.lr.ph39, !llvm.loop !17

._crit_edge:                                      ; preds = %.lr.ph39, %middle.block, %4, %.preheader31, %.preheader
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @exp(double noundef) local_unnamed_addr #1

attributes #0 = { nofree nounwind memory(write, argmem: readwrite) 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 nofree nounwind willreturn memory(write) "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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.unroll.disable"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12, !14, !15}
!14 = !{!"llvm.loop.isvectorized", i32 1}
!15 = !{!"llvm.loop.unroll.runtime.disable"}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !12, !15, !14}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass