; LLVM IR from lichen-community-systems/signaletic :: libsignaletic/src (libsignaletic)

; 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: inlinehint nounwind uwtable
define dso_local i64 @sig_indexOfMax(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca float, align 4
  %9 = alloca i64, align 8
  %10 = alloca float, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !9
  %11 = load i64, ptr %5, align 8, !tbaa !9
  %12 = icmp ult i64 %11, 1
  br i1 %12, label %13, label %15

13:                                               ; preds = %2
  %14 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %14, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %41

15:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds float, ptr %16, i64 0
  %18 = load float, ptr %17, align 4, !tbaa !11
  store float %18, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  store i64 1, ptr %9, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %36, %15
  %20 = load i64, ptr %9, align 8, !tbaa !9
  %21 = load i64, ptr %5, align 8, !tbaa !9
  %22 = icmp ult i64 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %39

24:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load i64, ptr %9, align 8, !tbaa !9
  %27 = getelementptr inbounds float, ptr %25, i64 %26
  %28 = load float, ptr %27, align 4, !tbaa !11
  store float %28, ptr %10, align 4, !tbaa !11
  %29 = load float, ptr %10, align 4, !tbaa !11
  %30 = load float, ptr %8, align 4, !tbaa !11
  %31 = fcmp ogt float %29, %30
  br i1 %31, label %32, label %35

32:                                               ; preds = %24
  %33 = load i64, ptr %9, align 8, !tbaa !9
  store i64 %33, ptr %6, align 8, !tbaa !9
  %34 = load float, ptr %10, align 4, !tbaa !11
  store float %34, ptr %8, align 4, !tbaa !11
  br label %35

35:                                               ; preds = %32, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %36

36:                                               ; preds = %35
  %37 = load i64, ptr %9, align 8, !tbaa !9
  %38 = add i64 %37, 1
  store i64 %38, ptr %9, align 8, !tbaa !9
  br label %19, !llvm.loop !13

39:                                               ; preds = %23
  %40 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %40, ptr %3, align 8
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %41

41:                                               ; preds = %39, %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %42 = load i64, ptr %3, align 8
  ret i64 %42
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

; Function Attrs: inlinehint nofree norecurse nosync nounwind memory(argmem: read) uwtable
define dso_local i64 @sig_indexOfMax(ptr nocapture noundef readonly %0, i64 noundef %1) local_unnamed_addr #0 {
  %switch = icmp ult i64 %1, 2
  br i1 %switch, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %3 = load float, ptr %0, align 4, !tbaa !5
  %4 = add i64 %1, -1
  %xtraiter = and i64 %4, 1
  %5 = icmp eq i64 %1, 2
  br i1 %5, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %4, -2
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.01321 = phi i64 [ 1, %.lr.ph.preheader.new ], [ %13, %.lr.ph ]
  %.01420 = phi float [ %3, %.lr.ph.preheader.new ], [ %.1.1, %.lr.ph ]
  %.01519 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %.116.1, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %6 = getelementptr inbounds float, ptr %0, i64 %.01321
  %7 = load float, ptr %6, align 4, !tbaa !5
  %8 = fcmp ogt float %7, %.01420
  %.116 = select i1 %8, i64 %.01321, i64 %.01519
  %.1 = select i1 %8, float %7, float %.01420
  %9 = add nuw i64 %.01321, 1
  %10 = getelementptr inbounds float, ptr %0, i64 %9
  %11 = load float, ptr %10, align 4, !tbaa !5
  %12 = fcmp ogt float %11, %.1
  %.116.1 = select i1 %12, i64 %9, i64 %.116
  %.1.1 = select i1 %12, float %11, float %.1
  %13 = add nuw i64 %.01321, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !9

.loopexit.loopexit.unr-lcssa:                     ; preds = %.lr.ph, %.lr.ph.preheader
  %.116.lcssa.ph = phi i64 [ poison, %.lr.ph.preheader ], [ %.116.1, %.lr.ph ]
  %.01321.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %13, %.lr.ph ]
  %.01420.unr = phi float [ %3, %.lr.ph.preheader ], [ %.1.1, %.lr.ph ]
  %.01519.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %.116.1, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.loopexit.loopexit.unr-lcssa
  %14 = getelementptr inbounds float, ptr %0, i64 %.01321.unr
  %15 = load float, ptr %14, align 4, !tbaa !5
  %16 = fcmp ogt float %15, %.01420.unr
  %.116.epil = select i1 %16, i64 %.01321.unr, i64 %.01519.unr
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph.epil, %.loopexit.loopexit.unr-lcssa, %2
  %.0 = phi i64 [ 0, %2 ], [ %.116.lcssa.ph, %.loopexit.loopexit.unr-lcssa ], [ %.116.epil, %.lr.ph.epil ]
  ret i64 %.0
}

attributes #0 = { inlinehint 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, !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.mustprogress"}


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