; LLVM IR from AlgoGenesis/C :: Searching Algorithms/N-arySearch (Program)

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

20:                                               ; preds = %122, %4
  %21 = load i32, ptr %10, align 4, !tbaa !9
  %22 = load i32, ptr %11, align 4, !tbaa !9
  %23 = icmp sle i32 %21, %22
  br i1 %23, label %24, label %123

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %25 = load i32, ptr %11, align 4, !tbaa !9
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = sub nsw i32 %25, %26
  %28 = add nsw i32 %27, 1
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = sdiv i32 %28, %29
  store i32 %30, ptr %12, align 4, !tbaa !9
  %31 = load i32, ptr %9, align 4, !tbaa !9
  %32 = add nsw i32 %31, 1
  %33 = zext i32 %32 to i64
  %34 = call ptr @llvm.stacksave.p0()
  store ptr %34, ptr %13, align 8
  %35 = alloca i32, i64 %33, align 16
  store i64 %33, ptr %14, align 8
  %36 = load i32, ptr %10, align 4, !tbaa !9
  %37 = getelementptr inbounds i32, ptr %35, i64 0
  store i32 %36, ptr %37, align 16, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  store i32 1, ptr %15, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %52, %24
  %39 = load i32, ptr %15, align 4, !tbaa !9
  %40 = load i32, ptr %9, align 4, !tbaa !9
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  br label %55

43:                                               ; preds = %38
  %44 = load i32, ptr %10, align 4, !tbaa !9
  %45 = load i32, ptr %15, align 4, !tbaa !9
  %46 = load i32, ptr %12, align 4, !tbaa !9
  %47 = mul nsw i32 %45, %46
  %48 = add nsw i32 %44, %47
  %49 = load i32, ptr %15, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds i32, ptr %35, i64 %50
  store i32 %48, ptr %51, align 4, !tbaa !9
  br label %52

52:                                               ; preds = %43
  %53 = load i32, ptr %15, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %15, align 4, !tbaa !9
  br label %38, !llvm.loop !11

55:                                               ; preds = %42
  %56 = load i32, ptr %11, align 4, !tbaa !9
  %57 = add nsw i32 %56, 1
  %58 = load i32, ptr %9, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i32, ptr %35, i64 %59
  store i32 %57, ptr %60, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  store i32 0, ptr %16, align 4, !tbaa !9
  br label %61

61:                                               ; preds = %113, %55
  %62 = load i32, ptr %16, align 4, !tbaa !9
  %63 = load i32, ptr %9, align 4, !tbaa !9
  %64 = icmp slt i32 %62, %63
  br i1 %64, label %66, label %65

65:                                               ; preds = %61
  store i32 7, ptr %17, align 4
  br label %116

66:                                               ; preds = %61
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = load i32, ptr %16, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds i32, ptr %35, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !9
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds i32, ptr %67, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !9
  %75 = load i32, ptr %8, align 4, !tbaa !9
  %76 = icmp eq i32 %74, %75
  br i1 %76, label %77, label %82

77:                                               ; preds = %66
  %78 = load i32, ptr %16, align 4, !tbaa !9
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds i32, ptr %35, i64 %79
  %81 = load i32, ptr %80, align 4, !tbaa !9
  store i32 %81, ptr %5, align 4
  store i32 1, ptr %17, align 4
  br label %116

82:                                               ; preds = %66
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = load i32, ptr %16, align 4, !tbaa !9
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds i32, ptr %35, i64 %85
  %87 = load i32, ptr %86, align 4, !tbaa !9
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds i32, ptr %83, i64 %88
  %90 = load i32, ptr %89, align 4, !tbaa !9
  %91 = load i32, ptr %8, align 4, !tbaa !9
  %92 = icmp sgt i32 %90, %91
  br i1 %92, label %93, label %99

93:                                               ; preds = %82
  %94 = load i32, ptr %16, align 4, !tbaa !9
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds i32, ptr %35, i64 %95
  %97 = load i32, ptr %96, align 4, !tbaa !9
  %98 = sub nsw i32 %97, 1
  store i32 %98, ptr %11, align 4, !tbaa !9
  store i32 7, ptr %17, align 4
  br label %116

99:                                               ; preds = %82
  %100 = load i32, ptr %16, align 4, !tbaa !9
  %101 = load i32, ptr %9, align 4, !tbaa !9
  %102 = sub nsw i32 %101, 1
  %103 = icmp eq i32 %100, %102
  br i1 %103, label %104, label %110

104:                                              ; preds = %99
  %105 = load i32, ptr %16, align 4, !tbaa !9
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds i32, ptr %35, i64 %106
  %108 = load i32, ptr %107, align 4, !tbaa !9
  %109 = add nsw i32 %108, 1
  store i32 %109, ptr %10, align 4, !tbaa !9
  br label %110

110:                                              ; preds = %104, %99
  br label %111

111:                                              ; preds = %110
  br label %112

112:                                              ; preds = %111
  br label %113

113:                                              ; preds = %112
  %114 = load i32, ptr %16, align 4, !tbaa !9
  %115 = add nsw i32 %114, 1
  store i32 %115, ptr %16, align 4, !tbaa !9
  br label %61, !llvm.loop !13

116:                                              ; preds = %93, %77, %65
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  %117 = load i32, ptr %17, align 4
  switch i32 %117, label %119 [
    i32 7, label %118
  ]

118:                                              ; preds = %116
  store i32 0, ptr %17, align 4
  br label %119

119:                                              ; preds = %118, %116
  %120 = load ptr, ptr %13, align 8
  call void @llvm.stackrestore.p0(ptr %120)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  %121 = load i32, ptr %17, align 4
  switch i32 %121, label %124 [
    i32 0, label %122
  ]

122:                                              ; preds = %119
  br label %20, !llvm.loop !14

123:                                              ; preds = %20
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %17, align 4
  br label %124

124:                                              ; preds = %123, %119
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %125 = load i32, ptr %5, align 4
  ret i32 %125
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #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 = { nocallback nofree nosync nounwind willreturn }
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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


; 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 norecurse nosync nounwind uwtable
define dso_local i32 @nArySearch(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %.not60 = icmp slt i32 %1, 1
  br i1 %.not60, label %.loopexit49, label %.lr.ph64

.lr.ph64:                                         ; preds = %4
  %5 = add nsw i32 %3, 1
  %6 = zext i32 %5 to i64
  %7 = icmp sgt i32 %3, 1
  %8 = sext i32 %3 to i64
  %9 = icmp sgt i32 %3, 0
  br i1 %9, label %.lr.ph64.split.us.preheader, label %.loopexit

.lr.ph64.split.us.preheader:                      ; preds = %.lr.ph64
  %10 = add nsw i32 %3, -1
  %11 = add nsw i32 %1, -1
  %12 = zext nneg i32 %10 to i64
  %.pre = zext nneg i32 %3 to i64
  %wide.trip.count = zext nneg i32 %3 to i64
  %13 = add nsw i64 %wide.trip.count, -1
  %min.iters.check = icmp ult i32 %3, 9
  %n.vec = and i64 %13, -8
  %ind.end = or disjoint i64 %n.vec, 1
  %cmp.n = icmp eq i64 %13, %n.vec
  br label %.lr.ph64.split.us

.lr.ph64.split.us:                                ; preds = %.lr.ph64.split.us.preheader, %..loopexit_crit_edge.us
  %.03862.us = phi i32 [ %.13952.us, %..loopexit_crit_edge.us ], [ 0, %.lr.ph64.split.us.preheader ]
  %.04161.us = phi i32 [ %.142.us, %..loopexit_crit_edge.us ], [ %11, %.lr.ph64.split.us.preheader ]
  %14 = add nsw i32 %.04161.us, 1
  %15 = tail call ptr @llvm.stacksave.p0()
  %16 = alloca i32, i64 %6, align 16
  store i32 %.03862.us, ptr %16, align 16, !tbaa !5
  br i1 %7, label %.lr.ph.us.preheader, label %.lr.ph59.us

.lr.ph.us.preheader:                              ; preds = %.lr.ph64.split.us
  %17 = sub i32 %14, %.03862.us
  %18 = sdiv i32 %17, %3
  br i1 %min.iters.check, label %.lr.ph.us.preheader98, label %vector.ph

.lr.ph.us.preheader98:                            ; preds = %middle.block, %.lr.ph.us.preheader
  %indvars.iv.ph = phi i64 [ 1, %.lr.ph.us.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph.us

vector.ph:                                        ; preds = %.lr.ph.us.preheader
  %broadcast.splatinsert = insertelement <4 x i32> poison, i32 %18, i64 0
  %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> poison, <4 x i32> zeroinitializer
  %broadcast.splatinsert96 = insertelement <4 x i32> poison, i32 %.03862.us, i64 0
  %broadcast.splat97 = shufflevector <4 x i32> %broadcast.splatinsert96, <4 x i32> 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 ]
  %vec.ind = phi <4 x i32> [ <i32 1, i32 2, i32 3, i32 4>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %step.add = add <4 x i32> %vec.ind, <i32 4, i32 4, i32 4, i32 4>
  %offset.idx = or disjoint i64 %index, 1
  %19 = getelementptr inbounds i32, ptr %16, i64 %offset.idx
  %20 = mul <4 x i32> %broadcast.splat, %vec.ind
  %21 = mul <4 x i32> %broadcast.splat, %step.add
  %22 = add <4 x i32> %20, %broadcast.splat97
  %23 = add <4 x i32> %21, %broadcast.splat97
  %24 = getelementptr inbounds i8, ptr %19, i64 16
  store <4 x i32> %22, ptr %19, align 4, !tbaa !5
  store <4 x i32> %23, ptr %24, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %vec.ind.next = add <4 x i32> %vec.ind, <i32 8, i32 8, i32 8, i32 8>
  %25 = icmp eq i64 %index.next, %n.vec
  br i1 %25, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %.lr.ph59.us, label %.lr.ph.us.preheader98

.lr.ph59.us:                                      ; preds = %.lr.ph.us, %middle.block, %.lr.ph64.split.us
  %wide.trip.count81.pre-phi = phi i64 [ %.pre, %.lr.ph64.split.us ], [ %wide.trip.count, %middle.block ], [ %wide.trip.count, %.lr.ph.us ]
  %26 = getelementptr inbounds i32, ptr %16, i64 %8
  store i32 %14, ptr %26, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %.lr.ph59.us, %36
  %indvars.iv78 = phi i64 [ 0, %.lr.ph59.us ], [ %indvars.iv.next79, %36 ]
  %.13956.us = phi i32 [ %.03862.us, %.lr.ph59.us ], [ %spec.select.us, %36 ]
  %28 = getelementptr inbounds i32, ptr %16, i64 %indvars.iv78
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i32, ptr %0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = icmp eq i32 %32, %2
  br i1 %33, label %.thread, label %34

34:                                               ; preds = %27
  %35 = icmp sgt i32 %32, %2
  br i1 %35, label %39, label %36

36:                                               ; preds = %34
  %37 = icmp eq i64 %indvars.iv78, %12
  %38 = add nsw i32 %29, 1
  %spec.select.us = select i1 %37, i32 %38, i32 %.13956.us
  %indvars.iv.next79 = add nuw nsw i64 %indvars.iv78, 1
  %exitcond82.not = icmp eq i64 %indvars.iv.next79, %wide.trip.count81.pre-phi
  br i1 %exitcond82.not, label %..loopexit_crit_edge.us, label %27, !llvm.loop !13

39:                                               ; preds = %34
  %40 = add nsw i32 %29, -1
  br label %..loopexit_crit_edge.us

..loopexit_crit_edge.us:                          ; preds = %36, %39
  %.13952.us = phi i32 [ %.13956.us, %39 ], [ %spec.select.us, %36 ]
  %.142.us = phi i32 [ %40, %39 ], [ %.04161.us, %36 ]
  tail call void @llvm.stackrestore.p0(ptr %15)
  %.not.us = icmp sgt i32 %.13952.us, %.142.us
  br i1 %.not.us, label %.loopexit49, label %.lr.ph64.split.us, !llvm.loop !14

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader98, %.lr.ph.us
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph.us ], [ %indvars.iv.ph, %.lr.ph.us.preheader98 ]
  %41 = getelementptr inbounds i32, ptr %16, i64 %indvars.iv
  %42 = trunc i64 %indvars.iv to i32
  %43 = mul i32 %18, %42
  %44 = add i32 %43, %.03862.us
  store i32 %44, ptr %41, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.lr.ph59.us, label %.lr.ph.us, !llvm.loop !15

.loopexit:                                        ; preds = %.lr.ph64, %.loopexit
  br label %.loopexit

.thread:                                          ; preds = %27
  tail call void @llvm.stackrestore.p0(ptr %15)
  br label %.loopexit49

.loopexit49:                                      ; preds = %..loopexit_crit_edge.us, %4, %.thread
  %.2 = phi i32 [ %29, %.thread ], [ -1, %4 ], [ -1, %..loopexit_crit_edge.us ]
  ret i32 %.2
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #1

attributes #0 = { nofree norecurse nosync 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 = { mustprogress nocallback nofree nosync nounwind willreturn }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10, !12, !11}


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