; LLVM IR from smv1999/CompetitiveProgrammingQuestionBank :: General Questions/inner_reduce_pattern.ll (Z12innerPatterni)

; 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: mustprogress uwtable
declare dso_local void @_Z5printPA100_ii(ptr noundef, i32 noundef) #0

; 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 memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z12innerPatterni(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca [100 x [100 x i32]], align 16
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = mul nsw i32 2, %10
  %12 = sub nsw i32 %11, 1
  store i32 %12, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = sub nsw i32 %13, 1
  store i32 %14, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 40000, ptr %6) #2
  br label %15

15:                                               ; preds = %64, %1
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %71

18:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %19 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %19, ptr %7, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %61, %18
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = icmp sle i32 %21, %22
  br i1 %23, label %25, label %24

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

25:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %26 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %26, ptr %9, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %57, %25
  %28 = load i32, ptr %9, align 4, !tbaa !5
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = icmp sle i32 %28, %29
  br i1 %30, label %32, label %31

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

32:                                               ; preds = %27
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = icmp eq i32 %33, %34
  br i1 %35, label %48, label %36

36:                                               ; preds = %32
  %37 = load i32, ptr %7, align 4, !tbaa !5
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = icmp eq i32 %37, %38
  br i1 %39, label %48, label %40

40:                                               ; preds = %36
  %41 = load i32, ptr %9, align 4, !tbaa !5
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = icmp eq i32 %41, %42
  br i1 %43, label %48, label %44

44:                                               ; preds = %40
  %45 = load i32, ptr %9, align 4, !tbaa !5
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = icmp eq i32 %45, %46
  br i1 %47, label %48, label %56

48:                                               ; preds = %44, %40, %36, %32
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = load i32, ptr %7, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [100 x [100 x i32]], ptr %6, i64 0, i64 %51
  %53 = load i32, ptr %9, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [100 x i32], ptr %52, i64 0, i64 %54
  store i32 %49, ptr %55, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %48, %44
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %9, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %9, align 4, !tbaa !5
  br label %27, !llvm.loop !9

60:                                               ; preds = %31
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %7, align 4, !tbaa !5
  br label %20, !llvm.loop !11

64:                                               ; preds = %24
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %4, align 4, !tbaa !5
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = add nsw i32 %67, -1
  store i32 %68, ptr %5, align 4, !tbaa !5
  %69 = load i32, ptr %2, align 4, !tbaa !5
  %70 = add nsw i32 %69, -1
  store i32 %70, ptr %2, align 4, !tbaa !5
  br label %15, !llvm.loop !12

71:                                               ; preds = %15
  %72 = getelementptr inbounds [100 x [100 x i32]], ptr %6, i64 0, i64 0
  %73 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z5printPA100_ii(ptr noundef %72, i32 noundef %73)
  call void @llvm.lifetime.end.p0(i64 40000, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

attributes #0 = { mustprogress 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; 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 uwtable
declare dso_local void @_Z5printPA100_ii(ptr noundef, i32 noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z12innerPatterni(i32 noundef %0) local_unnamed_addr #0 {
  %2 = alloca [100 x [100 x i32]], align 16
  %3 = shl i32 %0, 1
  call void @llvm.lifetime.start.p0(i64 40000, ptr nonnull %2) #3
  %.not40 = icmp eq i32 %0, 0
  br i1 %.not40, label %._crit_edge44, label %.preheader34.preheader

.preheader34.preheader:                           ; preds = %1
  %4 = add i32 %3, -2
  %5 = sext i32 %4 to i64
  br label %.preheader34

.preheader34:                                     ; preds = %.preheader34.preheader, %._crit_edge39.split
  %indvars.iv56 = phi i64 [ %5, %.preheader34.preheader ], [ %indvars.iv.next57, %._crit_edge39.split ]
  %indvars.iv = phi i64 [ 0, %.preheader34.preheader ], [ %indvars.iv.next, %._crit_edge39.split ]
  %.02941 = phi i32 [ %0, %.preheader34.preheader ], [ %17, %._crit_edge39.split ]
  %smax = tail call i64 @llvm.smax.i64(i64 %indvars.iv56, i64 %indvars.iv)
  %reass.sub = sub nsw i64 %smax, %indvars.iv
  %6 = add i64 %reass.sub, 1
  %.not3037 = icmp sgt i64 %indvars.iv, %indvars.iv56
  br i1 %.not3037, label %._crit_edge39.split, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.preheader34
  %7 = and i64 %indvars.iv56, 4294967295
  %.not31.not.peel = icmp slt i64 %indvars.iv, %indvars.iv56
  %min.iters.check = icmp ult i64 %6, 8
  %n.vec = and i64 %6, -8
  %ind.end = add i64 %indvars.iv, %n.vec
  %broadcast.splatinsert = insertelement <4 x i32> poison, i32 %.02941, i64 0
  %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> poison, <4 x i32> zeroinitializer
  %cmp.n = icmp eq i64 %6, %n.vec
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %._crit_edge
  %indvars.iv53 = phi i64 [ %indvars.iv, %.preheader.preheader ], [ %indvars.iv.next54, %._crit_edge ]
  %8 = icmp eq i64 %indvars.iv53, %indvars.iv
  %9 = icmp eq i64 %indvars.iv53, %7
  %or.cond = or i1 %8, %9
  %or.cond.fr = freeze i1 %or.cond
  br i1 %or.cond.fr, label %.lr.ph.split.us.preheader, label %13

.lr.ph.split.us.preheader:                        ; preds = %.preheader
  br i1 %min.iters.check, label %.lr.ph.split.us.preheader63, label %vector.body

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

vector.body:                                      ; preds = %.lr.ph.split.us.preheader, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %.lr.ph.split.us.preheader ]
  %offset.idx = add i64 %indvars.iv, %index
  %10 = getelementptr inbounds [100 x [100 x i32]], ptr %2, i64 0, i64 %indvars.iv53, i64 %offset.idx
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  store <4 x i32> %broadcast.splat, ptr %10, align 4, !tbaa !5
  store <4 x i32> %broadcast.splat, ptr %11, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %12 = icmp eq i64 %index.next, %n.vec
  br i1 %12, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.split.us.preheader63

13:                                               ; preds = %.preheader
  %14 = getelementptr inbounds [100 x [100 x i32]], ptr %2, i64 0, i64 %indvars.iv53, i64 %indvars.iv
  store i32 %.02941, ptr %14, align 4, !tbaa !5
  br i1 %.not31.not.peel, label %.lr.ph.split.peel.next, label %._crit_edge

.lr.ph.split.peel.next:                           ; preds = %13
  %15 = getelementptr inbounds [100 x [100 x i32]], ptr %2, i64 0, i64 %indvars.iv53, i64 %7
  br label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph.split.us.preheader63, %.lr.ph.split.us
  %indvars.iv50 = phi i64 [ %indvars.iv.next51, %.lr.ph.split.us ], [ %indvars.iv50.ph, %.lr.ph.split.us.preheader63 ]
  %16 = getelementptr inbounds [100 x [100 x i32]], ptr %2, i64 0, i64 %indvars.iv53, i64 %indvars.iv50
  store i32 %.02941, ptr %16, align 4, !tbaa !5
  %indvars.iv.next51 = add nuw nsw i64 %indvars.iv50, 1
  %.not31.us.not = icmp slt i64 %indvars.iv50, %indvars.iv56
  br i1 %.not31.us.not, label %.lr.ph.split.us, label %._crit_edge, !llvm.loop !13

._crit_edge39.split:                              ; preds = %._crit_edge, %.preheader34
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %indvars.iv.next57 = add nsw i64 %indvars.iv56, -1
  %17 = add nsw i32 %.02941, -1
  %.not = icmp eq i32 %17, 0
  br i1 %.not, label %._crit_edge44, label %.preheader34, !llvm.loop !14

._crit_edge:                                      ; preds = %20, %.lr.ph.split.us, %middle.block, %13
  %indvars.iv.next54 = add nuw nsw i64 %indvars.iv53, 1
  %.not30.not = icmp slt i64 %indvars.iv53, %indvars.iv56
  br i1 %.not30.not, label %.preheader, label %._crit_edge39.split, !llvm.loop !15

.lr.ph.split:                                     ; preds = %.lr.ph.split.peel.next, %20
  %indvars.iv46.in = phi i64 [ %indvars.iv, %.lr.ph.split.peel.next ], [ %indvars.iv46, %20 ]
  %indvars.iv46 = add nuw nsw i64 %indvars.iv46.in, 1
  %18 = icmp eq i64 %indvars.iv46, %7
  br i1 %18, label %19, label %20

19:                                               ; preds = %.lr.ph.split
  store i32 %.02941, ptr %15, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %.lr.ph.split, %19
  %.not31.not = icmp slt i64 %indvars.iv46, %indvars.iv56
  br i1 %.not31.not, label %.lr.ph.split, label %._crit_edge, !llvm.loop !16

._crit_edge44:                                    ; preds = %._crit_edge39.split, %1
  %21 = add nsw i32 %3, -1
  call void @_Z5printPA100_ii(ptr noundef nonnull %2, i32 noundef %21)
  call void @llvm.lifetime.end.p0(i64 40000, ptr nonnull %2) #3
  ret void
}

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

attributes #0 = { mustprogress 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 memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple 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, !12, !11}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10, !17}
!17 = !{!"llvm.loop.peeled.count", i32 1}


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