; LLVM IR from kfv/leetcode :: src/1 (two_pointer)

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @twoSum(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = 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 ptr %3, ptr %9, align 8, !tbaa !5
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = zext i32 %18 to i64
  %20 = call ptr @llvm.stacksave.p0()
  store ptr %20, ptr %10, align 8
  %21 = alloca %struct.num_index, i64 %19, align 16
  store i64 %19, ptr %11, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  store i32 0, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = sub nsw i32 %22, 1
  store i32 %23, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %44, %4
  %25 = load i32, ptr %14, align 4, !tbaa !9
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  br label %47

29:                                               ; preds = %24
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = load i32, ptr %14, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds i32, ptr %30, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !9
  %35 = load i32, ptr %14, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds %struct.num_index, ptr %21, i64 %36
  %38 = getelementptr inbounds %struct.num_index, ptr %37, i32 0, i32 0
  store i32 %34, ptr %38, align 8, !tbaa !11
  %39 = load i32, ptr %14, align 4, !tbaa !9
  %40 = load i32, ptr %14, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds %struct.num_index, ptr %21, i64 %41
  %43 = getelementptr inbounds %struct.num_index, ptr %42, i32 0, i32 1
  store i32 %39, ptr %43, align 4, !tbaa !13
  br label %44

44:                                               ; preds = %29
  %45 = load i32, ptr %14, align 4, !tbaa !9
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %14, align 4, !tbaa !9
  br label %24, !llvm.loop !14

47:                                               ; preds = %28
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  call void @qsort(ptr noundef %21, i64 noundef %49, i64 noundef 8, ptr noundef @compare)
  br label %50

50:                                               ; preds = %101, %47
  %51 = load i32, ptr %12, align 4, !tbaa !9
  %52 = load i32, ptr %13, align 4, !tbaa !9
  %53 = icmp slt i32 %51, %52
  br i1 %53, label %54, label %102

54:                                               ; preds = %50
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %55 = load i32, ptr %12, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds %struct.num_index, ptr %21, i64 %56
  %58 = getelementptr inbounds %struct.num_index, ptr %57, i32 0, i32 0
  %59 = load i32, ptr %58, align 8, !tbaa !11
  %60 = load i32, ptr %13, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds %struct.num_index, ptr %21, i64 %61
  %63 = getelementptr inbounds %struct.num_index, ptr %62, i32 0, i32 0
  %64 = load i32, ptr %63, align 8, !tbaa !11
  %65 = add nsw i32 %59, %64
  store i32 %65, ptr %15, align 4, !tbaa !9
  %66 = load i32, ptr %15, align 4, !tbaa !9
  %67 = load i32, ptr %8, align 4, !tbaa !9
  %68 = icmp eq i32 %66, %67
  br i1 %68, label %69, label %87

69:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  %70 = call noalias ptr @calloc(i64 noundef 2, i64 noundef 4) #6
  store ptr %70, ptr %16, align 8, !tbaa !5
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 2, ptr %71, align 4, !tbaa !9
  %72 = load i32, ptr %12, align 4, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds %struct.num_index, ptr %21, i64 %73
  %75 = getelementptr inbounds %struct.num_index, ptr %74, i32 0, i32 1
  %76 = load i32, ptr %75, align 4, !tbaa !13
  %77 = load ptr, ptr %16, align 8, !tbaa !5
  %78 = getelementptr inbounds i32, ptr %77, i64 0
  store i32 %76, ptr %78, align 4, !tbaa !9
  %79 = load i32, ptr %13, align 4, !tbaa !9
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds %struct.num_index, ptr %21, i64 %80
  %82 = getelementptr inbounds %struct.num_index, ptr %81, i32 0, i32 1
  %83 = load i32, ptr %82, align 4, !tbaa !13
  %84 = load ptr, ptr %16, align 8, !tbaa !5
  %85 = getelementptr inbounds i32, ptr %84, i64 1
  store i32 %83, ptr %85, align 4, !tbaa !9
  %86 = load ptr, ptr %16, align 8, !tbaa !5
  store ptr %86, ptr %5, align 8
  store i32 1, ptr %17, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  br label %99

87:                                               ; preds = %54
  %88 = load i32, ptr %15, align 4, !tbaa !9
  %89 = load i32, ptr %8, align 4, !tbaa !9
  %90 = icmp slt i32 %88, %89
  br i1 %90, label %91, label %94

91:                                               ; preds = %87
  %92 = load i32, ptr %12, align 4, !tbaa !9
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr %12, align 4, !tbaa !9
  br label %97

94:                                               ; preds = %87
  %95 = load i32, ptr %13, align 4, !tbaa !9
  %96 = add nsw i32 %95, -1
  store i32 %96, ptr %13, align 4, !tbaa !9
  br label %97

97:                                               ; preds = %94, %91
  %98 = phi i32 [ %92, %91 ], [ %95, %94 ]
  store i32 0, ptr %17, align 4
  br label %99

99:                                               ; preds = %97, %69
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  %100 = load i32, ptr %17, align 4
  switch i32 %100, label %104 [
    i32 0, label %101
  ]

101:                                              ; preds = %99
  br label %50, !llvm.loop !16

102:                                              ; preds = %50
  %103 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 0, ptr %103, align 4, !tbaa !9
  store ptr null, ptr %5, align 8
  store i32 1, ptr %17, align 4
  br label %104

104:                                              ; preds = %102, %99
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  %105 = load ptr, ptr %10, align 8
  call void @llvm.stackrestore.p0(ptr %105)
  %106 = load ptr, ptr %5, align 8
  ret ptr %106
}

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

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

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

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

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

; Function Attrs: 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 = { nocallback nofree nosync nounwind willreturn }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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,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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0,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 = !{!12, !10, i64 0}
!12 = !{!"", !10, i64 0, !10, i64 4}
!13 = !{!12, !10, i64 4}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !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.num_index = type { i32, i32 }

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

; Function Attrs: nofree nounwind uwtable
define dso_local noalias noundef ptr @twoSum(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #1 {
  %5 = zext i32 %1 to i64
  %6 = alloca %struct.num_index, i64 %5, align 16
  %7 = add nsw i32 %1, -1
  %8 = icmp sgt i32 %1, 0
  br i1 %8, label %.lr.ph.preheader, label %._crit_edge.thread

.lr.ph.preheader:                                 ; preds = %4
  %min.iters.check = icmp ult i32 %1, 4
  br i1 %min.iters.check, label %.lr.ph.preheader69, label %vector.ph

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

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %5, 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>
  %9 = or disjoint i64 %index, 2
  %10 = getelementptr inbounds i32, ptr %0, i64 %index
  %11 = getelementptr inbounds i8, ptr %10, i64 8
  %wide.load = load <2 x i32>, ptr %10, align 4, !tbaa !5
  %wide.load64 = load <2 x i32>, ptr %11, align 4, !tbaa !5
  %12 = getelementptr inbounds %struct.num_index, ptr %6, i64 %index
  %13 = getelementptr inbounds %struct.num_index, ptr %6, i64 %9
  %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 %12, align 16, !tbaa !5
  %interleaved.vec65 = shufflevector <2 x i32> %wide.load64, <2 x i32> %step.add, <4 x i32> <i32 0, i32 2, i32 1, i32 3>
  store <4 x i32> %interleaved.vec65, ptr %13, align 16, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %vec.ind.next = add <2 x i32> %vec.ind, <i32 4, i32 4>
  %14 = icmp eq i64 %index.next, %n.vec
  br i1 %14, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %5
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader69

._crit_edge.thread:                               ; preds = %4
  %15 = sext i32 %1 to i64
  call void @qsort(ptr noundef nonnull %6, i64 noundef %15, i64 noundef 8, ptr noundef nonnull @compare) #4
  br label %._crit_edge51

._crit_edge:                                      ; preds = %.lr.ph, %middle.block
  %16 = zext nneg i32 %1 to i64
  call void @qsort(ptr noundef nonnull %6, i64 noundef %16, i64 noundef 8, ptr noundef nonnull @compare) #4
  %.not59 = icmp eq i32 %1, 1
  br i1 %.not59, label %._crit_edge51, label %.lr.ph50

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

.lr.ph50:                                         ; preds = %._crit_edge, %35
  %.03148 = phi i32 [ %.132, %35 ], [ 0, %._crit_edge ]
  %.03547 = phi i32 [ %.136, %35 ], [ %7, %._crit_edge ]
  %22 = zext nneg i32 %.03148 to i64
  %23 = getelementptr inbounds %struct.num_index, ptr %6, i64 %22
  %24 = load i32, ptr %23, align 8, !tbaa !13
  %25 = sext i32 %.03547 to i64
  %26 = getelementptr inbounds %struct.num_index, ptr %6, i64 %25
  %27 = load i32, ptr %26, align 8, !tbaa !13
  %28 = add nsw i32 %27, %24
  %.not = icmp eq i32 %28, %2
  br i1 %.not, label %.thread, label %35

.thread:                                          ; preds = %.lr.ph50
  %29 = call noalias dereferenceable_or_null(8) ptr @calloc(i64 noundef 2, i64 noundef 4) #5
  store i32 2, ptr %3, align 4, !tbaa !5
  %30 = getelementptr inbounds %struct.num_index, ptr %6, i64 %22, i32 1
  %31 = load i32, ptr %30, align 4, !tbaa !15
  store i32 %31, ptr %29, align 4, !tbaa !5
  %32 = getelementptr inbounds %struct.num_index, ptr %6, i64 %25, i32 1
  %33 = load i32, ptr %32, align 4, !tbaa !15
  %34 = getelementptr inbounds i8, ptr %29, i64 4
  store i32 %33, ptr %34, align 4, !tbaa !5
  br label %40

35:                                               ; preds = %.lr.ph50
  %36 = icmp sge i32 %28, %2
  %37 = sext i1 %36 to i32
  %.136 = add nsw i32 %.03547, %37
  %not. = xor i1 %36, true
  %38 = zext i1 %not. to i32
  %.132 = add nuw nsw i32 %.03148, %38
  %39 = icmp slt i32 %.132, %.136
  br i1 %39, label %.lr.ph50, label %._crit_edge51

._crit_edge51:                                    ; preds = %35, %._crit_edge.thread, %._crit_edge
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %.thread, %._crit_edge51
  %.2 = phi ptr [ null, %._crit_edge51 ], [ %29, %.thread ]
  ret ptr %.2
}

; 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,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #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 = { nofree 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,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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0,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, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = !{!14, !6, i64 0}
!14 = !{!"", !6, i64 0, !6, i64 4}
!15 = !{!14, !6, i64 4}
!16 = distinct !{!16, !10, !12, !11}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass