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

%struct.StackRecord = type { i32, i32, i32, i32, i32, ptr }

@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @isEmpty(i32 noundef, ptr 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 ptr @getArray(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @printThreeStacks(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = call ptr @getArray(ptr noundef %5)
  store ptr %6, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %121, %1
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.StackRecord, ptr %9, i32 0, i32 0
  %11 = load i32, ptr %10, align 8, !tbaa !11
  %12 = icmp slt i32 %8, %11
  br i1 %12, label %13, label %124

13:                                               ; preds = %7
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds i32, ptr %14, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %18)
  %20 = load i32, ptr %4, align 4, !tbaa !9
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.StackRecord, ptr %21, i32 0, i32 1
  %23 = load i32, ptr %22, align 4, !tbaa !13
  %24 = icmp eq i32 %20, %23
  br i1 %24, label %25, label %34

25:                                               ; preds = %13
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = add nsw i32 %26, 1
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.StackRecord, ptr %28, i32 0, i32 4
  %30 = load i32, ptr %29, align 8, !tbaa !14
  %31 = icmp ne i32 %27, %30
  br i1 %31, label %32, label %34

32:                                               ; preds = %25
  %33 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  br label %120

34:                                               ; preds = %25, %13
  %35 = load i32, ptr %4, align 4, !tbaa !9
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.StackRecord, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !13
  %39 = icmp eq i32 %35, %38
  br i1 %39, label %40, label %49

40:                                               ; preds = %34
  %41 = load i32, ptr %4, align 4, !tbaa !9
  %42 = add nsw i32 %41, 1
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.StackRecord, ptr %43, i32 0, i32 4
  %45 = load i32, ptr %44, align 8, !tbaa !14
  %46 = icmp eq i32 %42, %45
  br i1 %46, label %47, label %49

47:                                               ; preds = %40
  %48 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  br label %119

49:                                               ; preds = %40, %34
  %50 = load i32, ptr %4, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.StackRecord, ptr %52, i32 0, i32 4
  %54 = load i32, ptr %53, align 8, !tbaa !14
  %55 = icmp eq i32 %51, %54
  br i1 %55, label %56, label %58

56:                                               ; preds = %49
  %57 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  br label %118

58:                                               ; preds = %49
  %59 = load i32, ptr %4, align 4, !tbaa !9
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.StackRecord, ptr %60, i32 0, i32 3
  %62 = load i32, ptr %61, align 4, !tbaa !15
  %63 = icmp eq i32 %59, %62
  br i1 %63, label %64, label %77

64:                                               ; preds = %58
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  %66 = call i32 @isEmpty(i32 noundef 2, ptr noundef %65)
  %67 = icmp ne i32 %66, 0
  br i1 %67, label %77, label %68

68:                                               ; preds = %64
  %69 = load i32, ptr %4, align 4, !tbaa !9
  %70 = add nsw i32 %69, 1
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.StackRecord, ptr %71, i32 0, i32 2
  %73 = load i32, ptr %72, align 8, !tbaa !16
  %74 = icmp ne i32 %70, %73
  br i1 %74, label %75, label %77

75:                                               ; preds = %68
  %76 = call i32 (ptr, ...) @printf(ptr noundef @.str.7)
  br label %117

77:                                               ; preds = %68, %64, %58
  %78 = load i32, ptr %4, align 4, !tbaa !9
  %79 = load ptr, ptr %2, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.StackRecord, ptr %79, i32 0, i32 3
  %81 = load i32, ptr %80, align 4, !tbaa !15
  %82 = icmp eq i32 %78, %81
  br i1 %82, label %83, label %92

83:                                               ; preds = %77
  %84 = load i32, ptr %4, align 4, !tbaa !9
  %85 = add nsw i32 %84, 1
  %86 = load ptr, ptr %2, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.StackRecord, ptr %86, i32 0, i32 2
  %88 = load i32, ptr %87, align 8, !tbaa !16
  %89 = icmp eq i32 %85, %88
  br i1 %89, label %90, label %92

90:                                               ; preds = %83
  %91 = call i32 (ptr, ...) @printf(ptr noundef @.str.8)
  br label %116

92:                                               ; preds = %83, %77
  %93 = load i32, ptr %4, align 4, !tbaa !9
  %94 = add nsw i32 %93, 1
  %95 = load ptr, ptr %2, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.StackRecord, ptr %95, i32 0, i32 2
  %97 = load i32, ptr %96, align 8, !tbaa !16
  %98 = icmp eq i32 %94, %97
  br i1 %98, label %99, label %105

99:                                               ; preds = %92
  %100 = load ptr, ptr %2, align 8, !tbaa !5
  %101 = call i32 @isEmpty(i32 noundef 0, ptr noundef %100)
  %102 = icmp ne i32 %101, 0
  br i1 %102, label %105, label %103

103:                                              ; preds = %99
  %104 = call i32 (ptr, ...) @printf(ptr noundef @.str.9)
  br label %115

105:                                              ; preds = %99, %92
  %106 = load i32, ptr %4, align 4, !tbaa !9
  %107 = add nsw i32 %106, 1
  %108 = load ptr, ptr %2, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.StackRecord, ptr %108, i32 0, i32 0
  %110 = load i32, ptr %109, align 8, !tbaa !11
  %111 = icmp eq i32 %107, %110
  br i1 %111, label %112, label %114

112:                                              ; preds = %105
  %113 = call i32 (ptr, ...) @printf(ptr noundef @.str.10)
  br label %114

114:                                              ; preds = %112, %105
  br label %115

115:                                              ; preds = %114, %103
  br label %116

116:                                              ; preds = %115, %90
  br label %117

117:                                              ; preds = %116, %75
  br label %118

118:                                              ; preds = %117, %56
  br label %119

119:                                              ; preds = %118, %47
  br label %120

120:                                              ; preds = %119, %32
  br label %121

121:                                              ; preds = %120
  %122 = load i32, ptr %4, align 4, !tbaa !9
  %123 = add nsw i32 %122, 1
  store i32 %123, ptr %4, align 4, !tbaa !9
  br label %7, !llvm.loop !17

124:                                              ; preds = %7
  %125 = call i32 (ptr, ...) @printf(ptr noundef @.str.11)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

declare i32 @printf(ptr noundef, ...) #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 = { "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, !10, i64 0}
!12 = !{!"StackRecord", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !6, i64 24}
!13 = !{!12, !10, i64 4}
!14 = !{!12, !10, i64 16}
!15 = !{!12, !10, i64 12}
!16 = !{!12, !10, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"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"

@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [2 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @getArray(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @printThreeStacks(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call ptr @getArray(ptr noundef %0)
  %3 = load i32, ptr %0, align 8, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = getelementptr inbounds i8, ptr %0, i64 12
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  br label %9

9:                                                ; preds = %.lr.ph, %41
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %16, %41 ]
  %10 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv
  %11 = load i32, ptr %10, align 4, !tbaa !11
  %12 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %11)
  %13 = load i32, ptr %5, align 4, !tbaa !12
  %14 = zext i32 %13 to i64
  %15 = icmp eq i64 %indvars.iv, %14
  %.pre = load i32, ptr %6, align 8, !tbaa !13
  %16 = add nuw nsw i64 %indvars.iv, 1
  %17 = zext i32 %.pre to i64
  %.not = icmp eq i64 %16, %17
  br i1 %15, label %18, label %19

18:                                               ; preds = %9
  %.str.5..str.4 = select i1 %.not, ptr @.str.5, ptr @.str.4
  br label %.sink.split

19:                                               ; preds = %9
  br i1 %.not, label %.sink.split, label %20

20:                                               ; preds = %19
  %21 = load i32, ptr %7, align 4, !tbaa !14
  %22 = zext i32 %21 to i64
  %23 = icmp eq i64 %indvars.iv, %22
  br i1 %23, label %24, label %._crit_edge38

._crit_edge38:                                    ; preds = %20
  %.pre37.pre = load i32, ptr %8, align 8, !tbaa !15
  br label %27

24:                                               ; preds = %20
  %25 = tail call i32 @isEmpty(i32 noundef 2, ptr noundef nonnull %0)
  %.not30 = icmp ne i32 %25, 0
  %.pre37.pre39 = load i32, ptr %8, align 8, !tbaa !15
  %26 = zext i32 %.pre37.pre39 to i64
  %.not31 = icmp eq i64 %16, %26
  %or.cond = select i1 %.not30, i1 true, i1 %.not31
  br i1 %or.cond, label %27, label %.sink.split

27:                                               ; preds = %._crit_edge38, %24
  %.pre37 = phi i32 [ %.pre37.pre, %._crit_edge38 ], [ %.pre37.pre39, %24 ]
  %28 = load i32, ptr %7, align 4, !tbaa !14
  %29 = zext i32 %28 to i64
  %30 = icmp eq i64 %indvars.iv, %29
  %31 = zext i32 %.pre37 to i64
  %32 = icmp eq i64 %16, %31
  %or.cond48 = select i1 %30, i1 %32, i1 false
  br i1 %or.cond48, label %.sink.split, label %._crit_edge41

._crit_edge41:                                    ; preds = %27
  %33 = icmp eq i64 %16, %31
  br i1 %33, label %34, label %36

34:                                               ; preds = %._crit_edge41
  %35 = tail call i32 @isEmpty(i32 noundef 0, ptr noundef nonnull %0)
  %.not32 = icmp eq i32 %35, 0
  br i1 %.not32, label %.sink.split, label %36

36:                                               ; preds = %34, %._crit_edge41
  %37 = load i32, ptr %0, align 8, !tbaa !5
  %38 = zext i32 %37 to i64
  %39 = icmp eq i64 %16, %38
  br i1 %39, label %.sink.split, label %41

.sink.split:                                      ; preds = %36, %34, %27, %24, %19, %18
  %.str.4.sink = phi ptr [ %.str.5..str.4, %18 ], [ @.str.6, %19 ], [ @.str.7, %24 ], [ @.str.8, %27 ], [ @.str.9, %34 ], [ @.str.10, %36 ]
  %40 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.4.sink)
  br label %41

41:                                               ; preds = %.sink.split, %36
  %42 = load i32, ptr %0, align 8, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = icmp slt i64 %16, %43
  br i1 %44, label %9, label %._crit_edge, !llvm.loop !16

._crit_edge:                                      ; preds = %41, %1
  %45 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11)
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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 = { nofree 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" }

!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, !7, i64 0}
!6 = !{!"StackRecord", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !10, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!6, !7, i64 4}
!13 = !{!6, !7, i64 16}
!14 = !{!6, !7, i64 12}
!15 = !{!6, !7, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass