; LLVM IR from xxks-kkk/algo :: stack/3-stack-1-array (threeStacks)

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

; Function Attrs: nounwind uwtable
define dso_local ptr @initializeThreeStacks(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7) #0 {
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca ptr, align 8
  %18 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store i32 %1, ptr %10, align 4, !tbaa !9
  store ptr %2, ptr %11, align 8, !tbaa !5
  store i32 %3, ptr %12, align 4, !tbaa !9
  store ptr %4, ptr %13, align 8, !tbaa !5
  store i32 %5, ptr %14, align 4, !tbaa !9
  store i32 %6, ptr %15, align 4, !tbaa !9
  store i32 %7, ptr %16, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #2
  %19 = load i32, ptr %10, align 4, !tbaa !9
  %20 = load i32, ptr %14, align 4, !tbaa !9
  %21 = add nsw i32 %19, %20
  %22 = load i32, ptr %12, align 4, !tbaa !9
  %23 = add nsw i32 %21, %22
  %24 = load i32, ptr %15, align 4, !tbaa !9
  %25 = add nsw i32 %23, %24
  %26 = load i32, ptr %16, align 4, !tbaa !9
  %27 = add nsw i32 %25, %26
  %28 = call ptr @createThreeStacks(i32 noundef %27)
  store ptr %28, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #2
  store i32 0, ptr %18, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %40, %8
  %30 = load i32, ptr %18, align 4, !tbaa !9
  %31 = load i32, ptr %10, align 4, !tbaa !9
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %33, label %43

33:                                               ; preds = %29
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = load i32, ptr %18, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i32, ptr %34, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !9
  %39 = load ptr, ptr %17, align 8, !tbaa !5
  call void @push(i32 noundef %38, i32 noundef 1, ptr noundef %39)
  br label %40

40:                                               ; preds = %33
  %41 = load i32, ptr %18, align 4, !tbaa !9
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %18, align 4, !tbaa !9
  br label %29, !llvm.loop !11

43:                                               ; preds = %29
  store i32 0, ptr %18, align 4, !tbaa !9
  br label %44

44:                                               ; preds = %55, %43
  %45 = load i32, ptr %18, align 4, !tbaa !9
  %46 = load i32, ptr %14, align 4, !tbaa !9
  %47 = icmp slt i32 %45, %46
  br i1 %47, label %48, label %58

48:                                               ; preds = %44
  %49 = load ptr, ptr %13, align 8, !tbaa !5
  %50 = load i32, ptr %18, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i32, ptr %49, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = load ptr, ptr %17, align 8, !tbaa !5
  call void @push(i32 noundef %53, i32 noundef 0, ptr noundef %54)
  br label %55

55:                                               ; preds = %48
  %56 = load i32, ptr %18, align 4, !tbaa !9
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %18, align 4, !tbaa !9
  br label %44, !llvm.loop !13

58:                                               ; preds = %44
  store i32 0, ptr %18, align 4, !tbaa !9
  br label %59

59:                                               ; preds = %70, %58
  %60 = load i32, ptr %18, align 4, !tbaa !9
  %61 = load i32, ptr %12, align 4, !tbaa !9
  %62 = icmp slt i32 %60, %61
  br i1 %62, label %63, label %73

63:                                               ; preds = %59
  %64 = load ptr, ptr %11, align 8, !tbaa !5
  %65 = load i32, ptr %18, align 4, !tbaa !9
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds i32, ptr %64, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !9
  %69 = load ptr, ptr %17, align 8, !tbaa !5
  call void @push(i32 noundef %68, i32 noundef 2, ptr noundef %69)
  br label %70

70:                                               ; preds = %63
  %71 = load i32, ptr %18, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %18, align 4, !tbaa !9
  br label %59, !llvm.loop !14

73:                                               ; preds = %59
  %74 = load ptr, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #2
  ret ptr %74
}

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 = { 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: nounwind uwtable
declare dso_local ptr @createThreeStacks(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @push(i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @initializeThreeStacks(ptr nocapture noundef readonly %0, i32 noundef %1, ptr nocapture noundef readonly %2, i32 noundef %3, ptr nocapture noundef readonly %4, i32 noundef %5, i32 noundef %6, i32 noundef %7) local_unnamed_addr #0 {
  %9 = add i32 %3, %1
  %10 = add i32 %9, %5
  %11 = add nsw i32 %10, %6
  %12 = add nsw i32 %11, %7
  %13 = tail call ptr @createThreeStacks(i32 noundef %12)
  %14 = icmp sgt i32 %1, 0
  br i1 %14, label %.lr.ph.preheader, label %.preheader23

.lr.ph.preheader:                                 ; preds = %8
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %.lr.ph

.preheader23:                                     ; preds = %.lr.ph, %8
  %15 = icmp sgt i32 %5, 0
  br i1 %15, label %.lr.ph26.preheader, label %.preheader

.lr.ph26.preheader:                               ; preds = %.preheader23
  %wide.trip.count33 = zext nneg i32 %5 to i64
  br label %.lr.ph26

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %16 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  %17 = load i32, ptr %16, align 4, !tbaa !5
  tail call void @push(i32 noundef %17, i32 noundef 1, ptr noundef %13)
  %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 %.preheader23, label %.lr.ph, !llvm.loop !9

.preheader:                                       ; preds = %.lr.ph26, %.preheader23
  %18 = icmp sgt i32 %3, 0
  br i1 %18, label %.lr.ph28.preheader, label %._crit_edge

.lr.ph28.preheader:                               ; preds = %.preheader
  %wide.trip.count38 = zext nneg i32 %3 to i64
  br label %.lr.ph28

.lr.ph26:                                         ; preds = %.lr.ph26.preheader, %.lr.ph26
  %indvars.iv30 = phi i64 [ 0, %.lr.ph26.preheader ], [ %indvars.iv.next31, %.lr.ph26 ]
  %19 = getelementptr inbounds i32, ptr %4, i64 %indvars.iv30
  %20 = load i32, ptr %19, align 4, !tbaa !5
  tail call void @push(i32 noundef %20, i32 noundef 0, ptr noundef %13)
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %exitcond34.not = icmp eq i64 %indvars.iv.next31, %wide.trip.count33
  br i1 %exitcond34.not, label %.preheader, label %.lr.ph26, !llvm.loop !11

.lr.ph28:                                         ; preds = %.lr.ph28.preheader, %.lr.ph28
  %indvars.iv35 = phi i64 [ 0, %.lr.ph28.preheader ], [ %indvars.iv.next36, %.lr.ph28 ]
  %21 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv35
  %22 = load i32, ptr %21, align 4, !tbaa !5
  tail call void @push(i32 noundef %22, i32 noundef 2, ptr noundef %13)
  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
  %exitcond39.not = icmp eq i64 %indvars.iv.next36, %wide.trip.count38
  br i1 %exitcond39.not, label %._crit_edge, label %.lr.ph28, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph28, %.preheader
  ret ptr %13
}

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

!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}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; Effective O3 passes: GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass