; LLVM IR from ImChong/Practice_LeetCode_C :: F01_Common_Functions/src (common_array)

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

@.str.6 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @Array_Sort2D(ptr noundef, 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

declare i32 @printf(ptr noundef, ...) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @Validate_Array2D(i8 noundef signext %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, i32 noundef %5, ptr noundef %6, i32 noundef %7) #0 {
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  store i8 %0, ptr %10, align 1, !tbaa !5
  store ptr %1, ptr %11, align 8, !tbaa !8
  store i32 %2, ptr %12, align 4, !tbaa !10
  store ptr %3, ptr %13, align 8, !tbaa !8
  store ptr %4, ptr %14, align 8, !tbaa !8
  store i32 %5, ptr %15, align 4, !tbaa !10
  store ptr %6, ptr %16, align 8, !tbaa !8
  store i32 %7, ptr %17, align 4, !tbaa !10
  %22 = load i32, ptr %17, align 4, !tbaa !10
  %23 = icmp eq i32 %22, 1
  br i1 %23, label %24, label %33

24:                                               ; preds = %8
  %25 = load ptr, ptr %11, align 8, !tbaa !8
  %26 = load i32, ptr %12, align 4, !tbaa !10
  %27 = load ptr, ptr %13, align 8, !tbaa !8
  %28 = call i32 @Array_Sort2D(ptr noundef %25, i32 noundef %26, ptr noundef %27)
  %29 = load ptr, ptr %14, align 8, !tbaa !8
  %30 = load i32, ptr %15, align 4, !tbaa !10
  %31 = load ptr, ptr %16, align 8, !tbaa !8
  %32 = call i32 @Array_Sort2D(ptr noundef %29, i32 noundef %30, ptr noundef %31)
  br label %33

33:                                               ; preds = %24, %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  store i32 1, ptr %18, align 4, !tbaa !10
  %34 = load i32, ptr %15, align 4, !tbaa !10
  %35 = load i32, ptr %12, align 4, !tbaa !10
  %36 = icmp ne i32 %34, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %33
  store i32 0, ptr %18, align 4, !tbaa !10
  br label %99

38:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #3
  store i32 0, ptr %19, align 4, !tbaa !10
  br label %39

39:                                               ; preds = %94, %38
  %40 = load i32, ptr %19, align 4, !tbaa !10
  %41 = load i32, ptr %12, align 4, !tbaa !10
  %42 = icmp slt i32 %40, %41
  br i1 %42, label %44, label %43

43:                                               ; preds = %39
  store i32 2, ptr %20, align 4
  br label %97

44:                                               ; preds = %39
  %45 = load ptr, ptr %16, align 8, !tbaa !8
  %46 = load i32, ptr %19, align 4, !tbaa !10
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i32, ptr %45, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !10
  %50 = load ptr, ptr %13, align 8, !tbaa !8
  %51 = load i32, ptr %19, align 4, !tbaa !10
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i32, ptr %50, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !10
  %55 = icmp ne i32 %49, %54
  br i1 %55, label %56, label %57

56:                                               ; preds = %44
  store i32 0, ptr %18, align 4, !tbaa !10
  store i32 2, ptr %20, align 4
  br label %97

57:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #3
  store i32 0, ptr %21, align 4, !tbaa !10
  br label %58

58:                                               ; preds = %89, %57
  %59 = load i32, ptr %21, align 4, !tbaa !10
  %60 = load ptr, ptr %13, align 8, !tbaa !8
  %61 = load i32, ptr %19, align 4, !tbaa !10
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds i32, ptr %60, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !10
  %65 = icmp slt i32 %59, %64
  br i1 %65, label %67, label %66

66:                                               ; preds = %58
  store i32 5, ptr %20, align 4
  br label %92

67:                                               ; preds = %58
  %68 = load ptr, ptr %14, align 8, !tbaa !8
  %69 = load i32, ptr %19, align 4, !tbaa !10
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds ptr, ptr %68, i64 %70
  %72 = load ptr, ptr %71, align 8, !tbaa !8
  %73 = load i32, ptr %21, align 4, !tbaa !10
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds i32, ptr %72, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !10
  %77 = load ptr, ptr %11, align 8, !tbaa !8
  %78 = load i32, ptr %19, align 4, !tbaa !10
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds ptr, ptr %77, i64 %79
  %81 = load ptr, ptr %80, align 8, !tbaa !8
  %82 = load i32, ptr %21, align 4, !tbaa !10
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds i32, ptr %81, i64 %83
  %85 = load i32, ptr %84, align 4, !tbaa !10
  %86 = icmp ne i32 %76, %85
  br i1 %86, label %87, label %88

87:                                               ; preds = %67
  store i32 0, ptr %18, align 4, !tbaa !10
  store i32 5, ptr %20, align 4
  br label %92

88:                                               ; preds = %67
  br label %89

89:                                               ; preds = %88
  %90 = load i32, ptr %21, align 4, !tbaa !10
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %21, align 4, !tbaa !10
  br label %58, !llvm.loop !12

92:                                               ; preds = %87, %66
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #3
  br label %93

93:                                               ; preds = %92
  br label %94

94:                                               ; preds = %93
  %95 = load i32, ptr %19, align 4, !tbaa !10
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %19, align 4, !tbaa !10
  br label %39, !llvm.loop !14

97:                                               ; preds = %56, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #3
  br label %98

98:                                               ; preds = %97
  br label %99

99:                                               ; preds = %98, %37
  %100 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  %101 = load i32, ptr %18, align 4, !tbaa !10
  %102 = icmp ne i32 %101, 0
  br i1 %102, label %103, label %107

103:                                              ; preds = %99
  %104 = load i8, ptr %10, align 1, !tbaa !5
  %105 = sext i8 %104 to i32
  %106 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, i32 noundef %105)
  br label %111

107:                                              ; preds = %99
  %108 = load i8, ptr %10, align 1, !tbaa !5
  %109 = sext i8 %108 to i32
  %110 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, i32 noundef %109)
  br label %111

111:                                              ; preds = %107, %103
  %112 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  %113 = call i32 (ptr, ...) @printf(ptr noundef @.str.9)
  %114 = load ptr, ptr %11, align 8, !tbaa !8
  %115 = load i32, ptr %12, align 4, !tbaa !10
  %116 = load ptr, ptr %13, align 8, !tbaa !8
  %117 = call i32 @Array_Print2D(ptr noundef %114, i32 noundef %115, ptr noundef %116)
  %118 = call i32 (ptr, ...) @printf(ptr noundef @.str.10)
  %119 = load ptr, ptr %14, align 8, !tbaa !8
  %120 = load i32, ptr %15, align 4, !tbaa !10
  %121 = load ptr, ptr %16, align 8, !tbaa !8
  %122 = call i32 @Array_Print2D(ptr noundef %119, i32 noundef %120, ptr noundef %121)
  %123 = call i32 (ptr, ...) @printf(ptr noundef @.str.11)
  %124 = load i32, ptr %18, align 4, !tbaa !10
  %125 = icmp ne i32 %124, 0
  br i1 %125, label %126, label %127

126:                                              ; preds = %111
  store i32 0, ptr %9, align 4
  store i32 1, ptr %20, align 4
  br label %128

127:                                              ; preds = %111
  store i32 -1, ptr %9, align 4
  store i32 1, ptr %20, align 4
  br label %128

128:                                              ; preds = %127, %126
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  %129 = load i32, ptr %9, align 4
  ret i32 %129
}

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


; 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.6 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [2 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @Validate_Array2D(i8 noundef signext %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, i32 noundef %5, ptr noundef %6, i32 noundef %7) local_unnamed_addr #0 {
  %9 = icmp eq i32 %7, 1
  br i1 %9, label %10, label %13

10:                                               ; preds = %8
  %11 = tail call i32 @Array_Sort2D(ptr noundef %1, i32 noundef %2, ptr noundef %3)
  %12 = tail call i32 @Array_Sort2D(ptr noundef %4, i32 noundef %5, ptr noundef %6)
  br label %13

13:                                               ; preds = %10, %8
  %.not = icmp eq i32 %5, %2
  br i1 %.not, label %.preheader46, label %.thread

.preheader46:                                     ; preds = %13
  %14 = icmp sgt i32 %5, 0
  br i1 %14, label %.lr.ph53.preheader, label %._crit_edge54.thread

._crit_edge54.thread:                             ; preds = %.preheader46
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6)
  br label %35

.lr.ph53.preheader:                               ; preds = %.preheader46
  %wide.trip.count59 = zext nneg i32 %5 to i64
  br label %.lr.ph53

.lr.ph53:                                         ; preds = %.lr.ph53.preheader, %._crit_edge
  %indvars.iv56 = phi i64 [ 0, %.lr.ph53.preheader ], [ %indvars.iv.next57, %._crit_edge ]
  %.03751 = phi i32 [ 1, %.lr.ph53.preheader ], [ %.1, %._crit_edge ]
  %16 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv56
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = getelementptr inbounds i32, ptr %3, i64 %indvars.iv56
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %.not40 = icmp eq i32 %17, %19
  br i1 %.not40, label %.preheader, label %.thread

.preheader:                                       ; preds = %.lr.ph53
  %20 = icmp sgt i32 %17, 0
  br i1 %20, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %21 = getelementptr inbounds ptr, ptr %4, i64 %indvars.iv56
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = getelementptr inbounds ptr, ptr %1, i64 %indvars.iv56
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %wide.trip.count = zext nneg i32 %17 to i64
  br label %26

25:                                               ; preds = %26
  %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 %._crit_edge, label %26, !llvm.loop !11

26:                                               ; preds = %.lr.ph, %25
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %25 ]
  %27 = getelementptr inbounds i32, ptr %22, i64 %indvars.iv
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = getelementptr inbounds i32, ptr %24, i64 %indvars.iv
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %.not41 = icmp eq i32 %28, %30
  br i1 %.not41, label %25, label %._crit_edge

._crit_edge:                                      ; preds = %25, %26, %.preheader
  %.1 = phi i32 [ %.03751, %.preheader ], [ 0, %26 ], [ %.03751, %25 ]
  %indvars.iv.next57 = add nuw nsw i64 %indvars.iv56, 1
  %exitcond60.not = icmp eq i64 %indvars.iv.next57, %wide.trip.count59
  br i1 %exitcond60.not, label %._crit_edge54, label %.lr.ph53, !llvm.loop !13

.thread:                                          ; preds = %.lr.ph53, %13
  %31 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6)
  br label %34

._crit_edge54:                                    ; preds = %._crit_edge
  %32 = icmp eq i32 %.1, 0
  %33 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6)
  br i1 %32, label %34, label %35

34:                                               ; preds = %.thread, %._crit_edge54
  br label %35

35:                                               ; preds = %._crit_edge54, %._crit_edge54.thread, %34
  %.str.8.sink = phi ptr [ @.str.8, %34 ], [ @.str.7, %._crit_edge54.thread ], [ @.str.7, %._crit_edge54 ]
  %.344 = phi i32 [ -1, %34 ], [ 0, %._crit_edge54.thread ], [ 0, %._crit_edge54 ]
  %36 = sext i8 %0 to i32
  %37 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.8.sink, i32 noundef %36)
  %38 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6)
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9)
  %40 = tail call i32 @Array_Print2D(ptr noundef %1, i32 noundef %2, ptr noundef %3)
  %41 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10)
  %42 = tail call i32 @Array_Print2D(ptr noundef %4, i32 noundef %5, ptr noundef %6)
  %43 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11)
  ret i32 %.344
}

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


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