; LLVM IR from wuzhouhui/leetcode :: 220_contain_dup_III (containsNearbyAlmostDuplicate)

; 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.node = type { i32, i32 }

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

17:                                               ; preds = %4
  store i32 0, ptr %5, align 4
  br label %94

18:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = zext i32 %19 to i64
  %21 = call ptr @llvm.stacksave.p0()
  store ptr %21, ptr %12, align 8
  %22 = alloca %struct.node, i64 %20, align 16
  store i64 %20, ptr %13, align 8
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %42, %18
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %27, label %45

27:                                               ; preds = %23
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load i32, ptr %10, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i32, ptr %28, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = load i32, ptr %10, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds %struct.node, ptr %22, i64 %34
  %36 = getelementptr inbounds %struct.node, ptr %35, i32 0, i32 0
  store i32 %32, ptr %36, align 8, !tbaa !11
  %37 = load i32, ptr %10, align 4, !tbaa !9
  %38 = load i32, ptr %10, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds %struct.node, ptr %22, i64 %39
  %41 = getelementptr inbounds %struct.node, ptr %40, i32 0, i32 1
  store i32 %37, ptr %41, align 4, !tbaa !13
  br label %42

42:                                               ; preds = %27
  %43 = load i32, ptr %10, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %10, align 4, !tbaa !9
  br label %23, !llvm.loop !14

45:                                               ; preds = %23
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  call void @qsort(ptr noundef %22, i64 noundef %47, i64 noundef 8, ptr noundef @nodecmp)
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %88, %45
  %49 = load i32, ptr %10, align 4, !tbaa !9
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = sub nsw i32 %50, 1
  %52 = icmp slt i32 %49, %51
  br i1 %52, label %53, label %91

53:                                               ; preds = %48
  %54 = load i32, ptr %10, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds %struct.node, ptr %22, i64 %55
  %57 = load i32, ptr %9, align 4, !tbaa !9
  %58 = load i32, ptr %10, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = sub nsw i32 %60, 1
  %62 = call i32 @binsrc(ptr noundef %56, i32 noundef %57, i32 noundef %59, i32 noundef %61, ptr noundef %22)
  store i32 %62, ptr %11, align 4, !tbaa !9
  br label %63

63:                                               ; preds = %84, %53
  %64 = load i32, ptr %11, align 4, !tbaa !9
  %65 = load i32, ptr %10, align 4, !tbaa !9
  %66 = icmp sgt i32 %64, %65
  br i1 %66, label %67, label %87

67:                                               ; preds = %63
  %68 = load i32, ptr %10, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds %struct.node, ptr %22, i64 %69
  %71 = getelementptr inbounds %struct.node, ptr %70, i32 0, i32 1
  %72 = load i32, ptr %71, align 4, !tbaa !13
  %73 = load i32, ptr %11, align 4, !tbaa !9
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds %struct.node, ptr %22, i64 %74
  %76 = getelementptr inbounds %struct.node, ptr %75, i32 0, i32 1
  %77 = load i32, ptr %76, align 4, !tbaa !13
  %78 = sub nsw i32 %72, %77
  %79 = call i32 @llvm.abs.i32(i32 %78, i1 true)
  %80 = load i32, ptr %8, align 4, !tbaa !9
  %81 = icmp sle i32 %79, %80
  br i1 %81, label %82, label %83

82:                                               ; preds = %67
  store i32 1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %92

83:                                               ; preds = %67
  br label %84

84:                                               ; preds = %83
  %85 = load i32, ptr %11, align 4, !tbaa !9
  %86 = add nsw i32 %85, -1
  store i32 %86, ptr %11, align 4, !tbaa !9
  br label %63, !llvm.loop !16

87:                                               ; preds = %63
  br label %88

88:                                               ; preds = %87
  %89 = load i32, ptr %10, align 4, !tbaa !9
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %10, align 4, !tbaa !9
  br label %48, !llvm.loop !17

91:                                               ; preds = %48
  store i32 0, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %92

92:                                               ; preds = %91, %82
  %93 = load ptr, ptr %12, align 8
  call void @llvm.stackrestore.p0(ptr %93)
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %94

94:                                               ; preds = %92, %17
  %95 = load i32, ptr %5, align 4
  ret i32 %95
}

; 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
declare ptr @llvm.stacksave.p0() #2

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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #2

; 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 = { nocallback nofree nosync nounwind willreturn }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 = !{!"node", !10, i64 0, !10, i64 4}
!13 = !{!12, !10, i64 4}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !15}


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

%struct.node = type { i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @containsNearbyAlmostDuplicate(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp slt i32 %1, 2
  br i1 %5, label %36, label %6

6:                                                ; preds = %4
  %7 = zext nneg i32 %1 to i64
  %8 = tail call ptr @llvm.stacksave.p0()
  %9 = alloca %struct.node, i64 %7, align 16
  %min.iters.check = icmp ult i32 %1, 4
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %6
  %n.vec = and i64 %7, 2147483644
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <2 x i32> [ <i32 0, i32 1>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %step.add = add <2 x i32> %vec.ind, <i32 2, i32 2>
  %10 = or disjoint i64 %index, 2
  %11 = getelementptr inbounds i32, ptr %0, i64 %index
  %12 = getelementptr inbounds i8, ptr %11, i64 8
  %wide.load = load <2 x i32>, ptr %11, align 4, !tbaa !5
  %wide.load49 = load <2 x i32>, ptr %12, align 4, !tbaa !5
  %13 = getelementptr inbounds %struct.node, ptr %9, i64 %index
  %14 = getelementptr inbounds %struct.node, ptr %9, i64 %10
  %interleaved.vec = shufflevector <2 x i32> %wide.load, <2 x i32> %vec.ind, <4 x i32> <i32 0, i32 2, i32 1, i32 3>
  store <4 x i32> %interleaved.vec, ptr %13, align 16, !tbaa !5
  %interleaved.vec50 = shufflevector <2 x i32> %wide.load49, <2 x i32> %step.add, <4 x i32> <i32 0, i32 2, i32 1, i32 3>
  store <4 x i32> %interleaved.vec50, ptr %14, align 16, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %vec.ind.next = add <2 x i32> %vec.ind, <i32 4, i32 4>
  %15 = icmp eq i64 %index.next, %n.vec
  br i1 %15, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %7
  br i1 %cmp.n, label %.lr.ph35.preheader, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %6
  %indvars.iv.ph = phi i64 [ 0, %6 ], [ %n.vec, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %16 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = getelementptr inbounds %struct.node, ptr %9, i64 %indvars.iv
  store i32 %17, ptr %18, align 8, !tbaa !13
  %19 = getelementptr inbounds i8, ptr %18, i64 4
  %20 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %20, ptr %19, align 4, !tbaa !15
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %7
  br i1 %exitcond.not, label %.lr.ph35.preheader, label %scalar.ph, !llvm.loop !16

.lr.ph35.preheader:                               ; preds = %scalar.ph, %middle.block
  call void @qsort(ptr noundef nonnull %9, i64 noundef %7, i64 noundef 8, ptr noundef nonnull @nodecmp) #4
  %21 = add nsw i32 %1, -1
  %wide.trip.count44 = zext i32 %21 to i64
  br label %.lr.ph35

.loopexit:                                        ; preds = %29, %.lr.ph35
  %exitcond45.not = icmp eq i64 %indvars.iv.next42, %wide.trip.count44
  br i1 %exitcond45.not, label %.loopexit30, label %.lr.ph35, !llvm.loop !17

.lr.ph35:                                         ; preds = %.lr.ph35.preheader, %.loopexit
  %indvars.iv41 = phi i64 [ 0, %.lr.ph35.preheader ], [ %indvars.iv.next42, %.loopexit ]
  %22 = getelementptr inbounds %struct.node, ptr %9, i64 %indvars.iv41
  %indvars.iv.next42 = add nuw nsw i64 %indvars.iv41, 1
  %23 = trunc nuw nsw i64 %indvars.iv.next42 to i32
  %24 = call i32 @binsrc(ptr noundef nonnull %22, i32 noundef %3, i32 noundef %23, i32 noundef %21, ptr noundef nonnull %9)
  %25 = sext i32 %24 to i64
  %26 = icmp slt i64 %indvars.iv41, %25
  br i1 %26, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph35
  %27 = getelementptr inbounds i8, ptr %22, i64 4
  %28 = load i32, ptr %27, align 4, !tbaa !15
  br label %31

29:                                               ; preds = %31
  %indvars.iv.next39 = add nsw i64 %indvars.iv38, -1
  %30 = icmp sgt i64 %indvars.iv.next39, %indvars.iv41
  br i1 %30, label %31, label %.loopexit, !llvm.loop !18

31:                                               ; preds = %.lr.ph, %29
  %indvars.iv38 = phi i64 [ %25, %.lr.ph ], [ %indvars.iv.next39, %29 ]
  %32 = getelementptr inbounds %struct.node, ptr %9, i64 %indvars.iv38, i32 1
  %33 = load i32, ptr %32, align 4, !tbaa !15
  %34 = sub nsw i32 %28, %33
  %35 = call i32 @llvm.abs.i32(i32 %34, i1 true)
  %.not = icmp sgt i32 %35, %2
  br i1 %.not, label %29, label %.loopexit30

.loopexit30:                                      ; preds = %.loopexit, %31
  %.0 = phi i32 [ 1, %31 ], [ 0, %.loopexit ]
  call void @llvm.stackrestore.p0(ptr %8)
  br label %36

36:                                               ; preds = %4, %.loopexit30
  %.1 = phi i32 [ %.0, %.loopexit30 ], [ 0, %4 ]
  ret i32 %.1
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #1

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

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

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #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 = { mustprogress nocallback nofree nosync nounwind willreturn }
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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = !{!14, !6, i64 0}
!14 = !{!"node", !6, i64 0, !6, i64 4}
!15 = !{!14, !6, i64 4}
!16 = distinct !{!16, !10, !12, !11}
!17 = distinct !{!17, !10}
!18 = distinct !{!18, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass