; LLVM IR from JessonYue/LeetCodeLearning :: Array/caiweixiong/c (homework_037)

; 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 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [95 x i8], align 1
@__PRETTY_FUNCTION__.intersection_3 = external hidden unnamed_addr constant [51 x i8], align 1

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

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

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

18:                                               ; preds = %5
  %19 = load i32, ptr %10, align 4, !tbaa !9
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %27, label %21

21:                                               ; preds = %18
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %27

24:                                               ; preds = %21
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %29, label %27

27:                                               ; preds = %24, %21, %18, %5
  %28 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 0, ptr %28, align 4, !tbaa !9
  store ptr null, ptr %6, align 8
  br label %138

29:                                               ; preds = %24
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  call void @qsort(ptr noundef %30, i64 noundef %32, i64 noundef 4, ptr noundef @compare)
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = load i32, ptr %10, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  call void @qsort(ptr noundef %33, i64 noundef %35, i64 noundef 4, ptr noundef @compare)
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = load i32, ptr %10, align 4, !tbaa !9
  %38 = icmp slt i32 %36, %37
  br i1 %38, label %39, label %41

39:                                               ; preds = %29
  %40 = load i32, ptr %8, align 4, !tbaa !9
  br label %43

41:                                               ; preds = %29
  %42 = load i32, ptr %10, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %41, %39
  %44 = phi i32 [ %40, %39 ], [ %42, %41 ]
  %45 = sext i32 %44 to i64
  %46 = mul i64 4, %45
  %47 = call noalias ptr @malloc(i64 noundef %46) #7
  store ptr %47, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #6
  store i32 0, ptr %13, align 4, !tbaa !9
  %48 = load ptr, ptr %12, align 8, !tbaa !5
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %51

50:                                               ; preds = %43
  br label %52

51:                                               ; preds = %43
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 88, ptr noundef @__PRETTY_FUNCTION__.intersection_3) #8
  unreachable

52:                                               ; preds = %50
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #6
  store i32 0, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #6
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %128, %52
  %54 = load i32, ptr %14, align 4, !tbaa !9
  %55 = load i32, ptr %8, align 4, !tbaa !9
  %56 = icmp slt i32 %54, %55
  br i1 %56, label %57, label %61

57:                                               ; preds = %53
  %58 = load i32, ptr %15, align 4, !tbaa !9
  %59 = load i32, ptr %10, align 4, !tbaa !9
  %60 = icmp slt i32 %58, %59
  br label %61

61:                                               ; preds = %57, %53
  %62 = phi i1 [ false, %53 ], [ %60, %57 ]
  br i1 %62, label %64, label %63

63:                                               ; preds = %61
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #6
  br label %129

64:                                               ; preds = %61
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = load i32, ptr %14, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds i32, ptr %65, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !9
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = load i32, ptr %15, align 4, !tbaa !9
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds i32, ptr %70, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !9
  %75 = icmp slt i32 %69, %74
  br i1 %75, label %76, label %79

76:                                               ; preds = %64
  %77 = load i32, ptr %14, align 4, !tbaa !9
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %14, align 4, !tbaa !9
  br label %128

79:                                               ; preds = %64
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = load i32, ptr %14, align 4, !tbaa !9
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds i32, ptr %80, i64 %82
  %84 = load i32, ptr %83, align 4, !tbaa !9
  %85 = load ptr, ptr %9, align 8, !tbaa !5
  %86 = load i32, ptr %15, align 4, !tbaa !9
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds i32, ptr %85, i64 %87
  %89 = load i32, ptr %88, align 4, !tbaa !9
  %90 = icmp sgt i32 %84, %89
  br i1 %90, label %91, label %94

91:                                               ; preds = %79
  %92 = load i32, ptr %15, align 4, !tbaa !9
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr %15, align 4, !tbaa !9
  br label %127

94:                                               ; preds = %79
  %95 = load ptr, ptr %7, align 8, !tbaa !5
  %96 = load i32, ptr %14, align 4, !tbaa !9
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds i32, ptr %95, i64 %97
  %99 = load i32, ptr %98, align 4, !tbaa !9
  %100 = load ptr, ptr %12, align 8, !tbaa !5
  %101 = load i32, ptr %13, align 4, !tbaa !9
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds i32, ptr %100, i64 %102
  store i32 %99, ptr %103, align 4, !tbaa !9
  %104 = load i32, ptr %14, align 4, !tbaa !9
  %105 = add nsw i32 %104, 1
  store i32 %105, ptr %14, align 4, !tbaa !9
  %106 = load i32, ptr %15, align 4, !tbaa !9
  %107 = add nsw i32 %106, 1
  store i32 %107, ptr %15, align 4, !tbaa !9
  %108 = load i32, ptr %13, align 4, !tbaa !9
  %109 = icmp ne i32 %108, 0
  br i1 %109, label %110, label %123

110:                                              ; preds = %94
  %111 = load ptr, ptr %12, align 8, !tbaa !5
  %112 = load i32, ptr %13, align 4, !tbaa !9
  %113 = sub nsw i32 %112, 1
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds i32, ptr %111, i64 %114
  %116 = load i32, ptr %115, align 4, !tbaa !9
  %117 = load ptr, ptr %12, align 8, !tbaa !5
  %118 = load i32, ptr %13, align 4, !tbaa !9
  %119 = sext i32 %118 to i64
  %120 = getelementptr inbounds i32, ptr %117, i64 %119
  %121 = load i32, ptr %120, align 4, !tbaa !9
  %122 = icmp ne i32 %116, %121
  br i1 %122, label %123, label %126

123:                                              ; preds = %110, %94
  %124 = load i32, ptr %13, align 4, !tbaa !9
  %125 = add nsw i32 %124, 1
  store i32 %125, ptr %13, align 4, !tbaa !9
  br label %126

126:                                              ; preds = %123, %110
  br label %127

127:                                              ; preds = %126, %91
  br label %128

128:                                              ; preds = %127, %76
  br label %53, !llvm.loop !11

129:                                              ; preds = %63
  %130 = load ptr, ptr %12, align 8, !tbaa !5
  %131 = load i32, ptr %13, align 4, !tbaa !9
  %132 = sext i32 %131 to i64
  %133 = mul i64 4, %132
  %134 = call ptr @realloc(ptr noundef %130, i64 noundef %133) #9
  store ptr %134, ptr %12, align 8, !tbaa !5
  %135 = load i32, ptr %13, align 4, !tbaa !9
  %136 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 %135, ptr %136, align 4, !tbaa !9
  %137 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %137, ptr %6, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  br label %138

138:                                              ; preds = %129, %27
  %139 = load ptr, ptr %6, align 8
  ret ptr %139
}

declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #3

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #4

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn 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" }
attributes #2 = { 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 #3 = { "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 #4 = { nounwind allocsize(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 #5 = { nounwind allocsize(1) "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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }
attributes #8 = { noreturn nounwind }
attributes #9 = { nounwind allocsize(1) }

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


; 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 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [95 x i8], align 1
@__PRETTY_FUNCTION__.intersection_3 = external hidden unnamed_addr constant [51 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @intersection_3(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, ptr nocapture noundef writeonly %4) local_unnamed_addr #1 {
  %6 = icmp ne i32 %1, 0
  %7 = icmp ne i32 %3, 0
  %or.cond.not61 = and i1 %6, %7
  %8 = icmp ne ptr %0, null
  %or.cond3 = and i1 %8, %or.cond.not61
  %9 = icmp ne ptr %2, null
  %or.cond5 = and i1 %9, %or.cond3
  br i1 %or.cond5, label %10, label %51

10:                                               ; preds = %5
  %11 = sext i32 %1 to i64
  tail call void @qsort(ptr noundef nonnull %0, i64 noundef %11, i64 noundef 4, ptr noundef nonnull @compare) #6
  %12 = sext i32 %3 to i64
  tail call void @qsort(ptr noundef nonnull %2, i64 noundef %12, i64 noundef 4, ptr noundef nonnull @compare) #6
  %13 = tail call i32 @llvm.smin.i32(i32 %1, i32 %3)
  %14 = sext i32 %13 to i64
  %15 = shl nsw i64 %14, 2
  %16 = tail call noalias ptr @malloc(i64 noundef %15) #7
  %.not = icmp eq ptr %16, null
  br i1 %.not, label %20, label %.preheader

.preheader:                                       ; preds = %10
  %17 = icmp sgt i32 %1, 0
  %18 = icmp sgt i32 %3, 0
  %19 = and i1 %17, %18
  br i1 %19, label %.lr.ph, label %._crit_edge

20:                                               ; preds = %10
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 88, ptr noundef nonnull @__PRETTY_FUNCTION__.intersection_3) #8
  unreachable

._crit_edge:                                      ; preds = %47, %.preheader
  %.052.lcssa = phi i32 [ 0, %.preheader ], [ %.153, %47 ]
  %21 = sext i32 %.052.lcssa to i64
  %22 = shl nsw i64 %21, 2
  %23 = tail call ptr @realloc(ptr noundef nonnull %16, i64 noundef %22) #9
  br label %51

.lr.ph:                                           ; preds = %.preheader, %47
  %.066 = phi i32 [ %.1, %47 ], [ 0, %.preheader ]
  %.05065 = phi i32 [ %.151, %47 ], [ 0, %.preheader ]
  %.05264 = phi i32 [ %.153, %47 ], [ 0, %.preheader ]
  %24 = sext i32 %.05065 to i64
  %25 = getelementptr inbounds i32, ptr %0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = sext i32 %.066 to i64
  %28 = getelementptr inbounds i32, ptr %2, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = icmp slt i32 %26, %29
  br i1 %30, label %31, label %33

31:                                               ; preds = %.lr.ph
  %32 = add nsw i32 %.05065, 1
  br label %47

33:                                               ; preds = %.lr.ph
  %34 = icmp sgt i32 %26, %29
  br i1 %34, label %35, label %37

35:                                               ; preds = %33
  %36 = add nsw i32 %.066, 1
  br label %47

37:                                               ; preds = %33
  %38 = sext i32 %.05264 to i64
  %39 = getelementptr inbounds i32, ptr %16, i64 %38
  store i32 %26, ptr %39, align 4, !tbaa !5
  %40 = add nsw i32 %.05065, 1
  %41 = add nsw i32 %.066, 1
  %.not62 = icmp eq i32 %.05264, 0
  br i1 %.not62, label %45, label %42

42:                                               ; preds = %37
  %43 = getelementptr i8, ptr %39, i64 -4
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %.not63 = icmp eq i32 %44, %26
  br i1 %.not63, label %47, label %45

45:                                               ; preds = %42, %37
  %46 = add nsw i32 %.05264, 1
  br label %47

47:                                               ; preds = %35, %45, %42, %31
  %.153 = phi i32 [ %.05264, %31 ], [ %.05264, %35 ], [ %46, %45 ], [ %.05264, %42 ]
  %.151 = phi i32 [ %32, %31 ], [ %.05065, %35 ], [ %40, %45 ], [ %40, %42 ]
  %.1 = phi i32 [ %.066, %31 ], [ %36, %35 ], [ %41, %45 ], [ %41, %42 ]
  %48 = icmp slt i32 %.151, %1
  %49 = icmp slt i32 %.1, %3
  %50 = select i1 %48, i1 %49, i1 false
  br i1 %50, label %.lr.ph, label %._crit_edge, !llvm.loop !9

51:                                               ; preds = %5, %._crit_edge
  %storemerge = phi i32 [ %.052.lcssa, %._crit_edge ], [ 0, %5 ]
  %.054 = phi ptr [ %23, %._crit_edge ], [ null, %5 ]
  store i32 %storemerge, ptr %4, align 4, !tbaa !5
  ret ptr %.054
}

; Function Attrs: nofree
declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #5

attributes #0 = { noreturn 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" }
attributes #1 = { 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 #2 = { nofree "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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #4 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }
attributes #8 = { noreturn nounwind }
attributes #9 = { nounwind allocsize(1) }

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass