; 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_1 = external hidden unnamed_addr constant [51 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @intersection_1(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4) #0 {
  %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 i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i8, align 1
  %21 = alloca i32, align 4
  %22 = 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
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %34, label %25

25:                                               ; preds = %5
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %34, label %28

28:                                               ; preds = %25
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %34

31:                                               ; preds = %28
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %36, label %34

34:                                               ; preds = %31, %28, %25, %5
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 0, ptr %35, align 4, !tbaa !9
  store ptr null, ptr %6, align 8
  br label %138

36:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 0, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = load i32, ptr %10, align 4, !tbaa !9
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %40, label %45

40:                                               ; preds = %36
  %41 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %41, ptr %13, align 4, !tbaa !9
  %42 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %42, ptr %12, align 4, !tbaa !9
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %43, ptr %15, align 8, !tbaa !5
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %44, ptr %16, align 8, !tbaa !5
  br label %50

45:                                               ; preds = %36
  %46 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %46, ptr %13, align 4, !tbaa !9
  %47 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %47, ptr %12, align 4, !tbaa !9
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %48, ptr %15, align 8, !tbaa !5
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %49, ptr %16, align 8, !tbaa !5
  br label %50

50:                                               ; preds = %45, %40
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %51 = load i32, ptr %13, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = call noalias ptr @calloc(i64 noundef %52, i64 noundef 4) #5
  store ptr %53, ptr %17, align 8, !tbaa !5
  %54 = load ptr, ptr %17, align 8, !tbaa !5
  %55 = icmp ne ptr %54, null
  br i1 %55, label %56, label %57

56:                                               ; preds = %50
  br label %58

57:                                               ; preds = %50
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 26, ptr noundef @__PRETTY_FUNCTION__.intersection_1) #6
  unreachable

58:                                               ; preds = %56
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #4
  store i32 0, ptr %18, align 4, !tbaa !9
  br label %59

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

63:                                               ; preds = %59
  store i32 2, ptr %19, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #4
  br label %134

64:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 1, ptr %20) #4
  store i8 0, ptr %20, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #4
  store i32 0, ptr %21, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %84, %64
  %66 = load i32, ptr %21, align 4, !tbaa !9
  %67 = load i32, ptr %12, align 4, !tbaa !9
  %68 = icmp slt i32 %66, %67
  br i1 %68, label %70, label %69

69:                                               ; preds = %65
  store i32 5, ptr %19, align 4
  br label %87

70:                                               ; preds = %65
  %71 = load ptr, ptr %15, align 8, !tbaa !5
  %72 = load i32, ptr %18, align 4, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds i32, ptr %71, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !9
  %76 = load ptr, ptr %16, align 8, !tbaa !5
  %77 = load i32, ptr %21, align 4, !tbaa !9
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds i32, ptr %76, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !9
  %81 = icmp eq i32 %75, %80
  br i1 %81, label %82, label %83

82:                                               ; preds = %70
  store i8 1, ptr %20, align 1, !tbaa !11
  store i32 5, ptr %19, align 4
  br label %87

83:                                               ; preds = %70
  br label %84

84:                                               ; preds = %83
  %85 = load i32, ptr %21, align 4, !tbaa !9
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %21, align 4, !tbaa !9
  br label %65, !llvm.loop !13

87:                                               ; preds = %82, %69
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #4
  br label %88

88:                                               ; preds = %87
  %89 = load i8, ptr %20, align 1, !tbaa !11, !range !15, !noundef !16
  %90 = trunc i8 %89 to i1
  br i1 %90, label %91, label %130

91:                                               ; preds = %88
  store i8 0, ptr %20, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #4
  store i32 0, ptr %22, align 4, !tbaa !9
  br label %92

92:                                               ; preds = %111, %91
  %93 = load i32, ptr %22, align 4, !tbaa !9
  %94 = load i32, ptr %14, align 4, !tbaa !9
  %95 = icmp slt i32 %93, %94
  br i1 %95, label %97, label %96

96:                                               ; preds = %92
  store i32 8, ptr %19, align 4
  br label %114

97:                                               ; preds = %92
  %98 = load ptr, ptr %17, align 8, !tbaa !5
  %99 = load i32, ptr %22, align 4, !tbaa !9
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds i32, ptr %98, i64 %100
  %102 = load i32, ptr %101, align 4, !tbaa !9
  %103 = load ptr, ptr %15, align 8, !tbaa !5
  %104 = load i32, ptr %18, align 4, !tbaa !9
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds i32, ptr %103, i64 %105
  %107 = load i32, ptr %106, align 4, !tbaa !9
  %108 = icmp eq i32 %102, %107
  br i1 %108, label %109, label %110

109:                                              ; preds = %97
  store i8 1, ptr %20, align 1, !tbaa !11
  store i32 8, ptr %19, align 4
  br label %114

110:                                              ; preds = %97
  br label %111

111:                                              ; preds = %110
  %112 = load i32, ptr %22, align 4, !tbaa !9
  %113 = add nsw i32 %112, 1
  store i32 %113, ptr %22, align 4, !tbaa !9
  br label %92, !llvm.loop !17

114:                                              ; preds = %109, %96
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #4
  br label %115

115:                                              ; preds = %114
  %116 = load i8, ptr %20, align 1, !tbaa !11, !range !15, !noundef !16
  %117 = trunc i8 %116 to i1
  br i1 %117, label %129, label %118

118:                                              ; preds = %115
  %119 = load ptr, ptr %15, align 8, !tbaa !5
  %120 = load i32, ptr %18, align 4, !tbaa !9
  %121 = sext i32 %120 to i64
  %122 = getelementptr inbounds i32, ptr %119, i64 %121
  %123 = load i32, ptr %122, align 4, !tbaa !9
  %124 = load ptr, ptr %17, align 8, !tbaa !5
  %125 = load i32, ptr %14, align 4, !tbaa !9
  %126 = add nsw i32 %125, 1
  store i32 %126, ptr %14, align 4, !tbaa !9
  %127 = sext i32 %125 to i64
  %128 = getelementptr inbounds i32, ptr %124, i64 %127
  store i32 %123, ptr %128, align 4, !tbaa !9
  br label %129

129:                                              ; preds = %118, %115
  br label %130

130:                                              ; preds = %129, %88
  call void @llvm.lifetime.end.p0(i64 1, ptr %20) #4
  br label %131

131:                                              ; preds = %130
  %132 = load i32, ptr %18, align 4, !tbaa !9
  %133 = add nsw i32 %132, 1
  store i32 %133, ptr %18, align 4, !tbaa !9
  br label %59, !llvm.loop !18

134:                                              ; preds = %63
  %135 = load i32, ptr %14, 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 %17, align 8, !tbaa !5
  store ptr %137, ptr %6, align 8
  store i32 1, ptr %19, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %138

138:                                              ; preds = %134, %34
  %139 = load ptr, ptr %6, align 8
  ret ptr %139
}

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

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind allocsize(0,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 #3 = { 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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0,1) }
attributes #6 = { noreturn 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, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !14}
!18 = distinct !{!18, !14}


; 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_1 = external hidden unnamed_addr constant [51 x i8], align 1

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

10:                                               ; preds = %5
  %11 = icmp slt i32 %1, %3
  %. = tail call i32 @llvm.smax.i32(i32 %1, i32 %3)
  %.67 = tail call i32 @llvm.smin.i32(i32 %1, i32 %3)
  %.68 = select i1 %11, ptr %0, ptr %2
  %.69 = select i1 %11, ptr %2, ptr %0
  %12 = sext i32 %.67 to i64
  %13 = tail call noalias ptr @calloc(i64 noundef %12, i64 noundef 4) #4
  %.not = icmp eq ptr %13, null
  br i1 %.not, label %30, label %.preheader74

.preheader74:                                     ; preds = %10
  %14 = icmp sgt i32 %.67, 0
  br i1 %14, label %.preheader72.us.preheader, label %.loopexit

.preheader72.us.preheader:                        ; preds = %.preheader74
  %wide.trip.count92 = zext nneg i32 %.67 to i64
  %wide.trip.count = zext i32 %. to i64
  br label %.preheader72.us

.preheader72.us:                                  ; preds = %.preheader72.us.preheader, %.critedge.us
  %indvars.iv89 = phi i64 [ 0, %.preheader72.us.preheader ], [ %indvars.iv.next90, %.critedge.us ]
  %.05478.us = phi i32 [ 0, %.preheader72.us.preheader ], [ %.155.us, %.critedge.us ]
  %15 = getelementptr inbounds i32, ptr %.68, i64 %indvars.iv89
  %16 = load i32, ptr %15, align 4, !tbaa !5
  br label %18

17:                                               ; preds = %18
  %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 %.critedge.us, label %18, !llvm.loop !9

18:                                               ; preds = %.preheader72.us, %17
  %indvars.iv = phi i64 [ 0, %.preheader72.us ], [ %indvars.iv.next, %17 ]
  %19 = getelementptr inbounds i32, ptr %.69, i64 %indvars.iv
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = icmp eq i32 %16, %20
  br i1 %21, label %.preheader.us, label %17

22:                                               ; preds = %.lr.ph77.us
  %indvars.iv.next85 = add nuw nsw i64 %indvars.iv84, 1
  %exitcond88.not = icmp eq i64 %indvars.iv.next85, %wide.trip.count87
  br i1 %exitcond88.not, label %.critedge71.us, label %.lr.ph77.us, !llvm.loop !11

.critedge71.us:                                   ; preds = %22, %.preheader.us
  %23 = add nsw i32 %.05478.us, 1
  %24 = sext i32 %.05478.us to i64
  %25 = getelementptr inbounds i32, ptr %13, i64 %24
  store i32 %16, ptr %25, align 4, !tbaa !5
  br label %.critedge.us

.lr.ph77.us:                                      ; preds = %.lr.ph77.us.preheader, %22
  %indvars.iv84 = phi i64 [ 0, %.lr.ph77.us.preheader ], [ %indvars.iv.next85, %22 ]
  %26 = getelementptr inbounds i32, ptr %13, i64 %indvars.iv84
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = icmp eq i32 %27, %16
  br i1 %28, label %.critedge.us, label %22

.critedge.us:                                     ; preds = %17, %.lr.ph77.us, %.critedge71.us
  %.155.us = phi i32 [ %23, %.critedge71.us ], [ %.05478.us, %.lr.ph77.us ], [ %.05478.us, %17 ]
  %indvars.iv.next90 = add nuw nsw i64 %indvars.iv89, 1
  %exitcond93.not = icmp eq i64 %indvars.iv.next90, %wide.trip.count92
  br i1 %exitcond93.not, label %.loopexit, label %.preheader72.us, !llvm.loop !12

.preheader.us:                                    ; preds = %18
  %29 = icmp sgt i32 %.05478.us, 0
  br i1 %29, label %.lr.ph77.us.preheader, label %.critedge71.us

.lr.ph77.us.preheader:                            ; preds = %.preheader.us
  %wide.trip.count87 = zext nneg i32 %.05478.us to i64
  br label %.lr.ph77.us

30:                                               ; preds = %10
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 26, ptr noundef nonnull @__PRETTY_FUNCTION__.intersection_1) #5
  unreachable

.loopexit:                                        ; preds = %.critedge.us, %.preheader74, %5
  %storemerge = phi i32 [ 0, %5 ], [ 0, %.preheader74 ], [ %.155.us, %.critedge.us ]
  %.051 = phi ptr [ null, %5 ], [ %13, %.preheader74 ], [ %13, %.critedge.us ]
  store i32 %storemerge, ptr %4, align 4, !tbaa !5
  ret ptr %.051
}

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

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

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

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

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 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) 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 #2 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind allocsize(0,1) }
attributes #5 = { noreturn 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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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