; LLVM IR from begeekmyfriend/leetcode :: 0001_two_sum (two_sum)

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

; 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 i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = mul i64 %17, 8
  %19 = call noalias ptr @malloc(i64 noundef %18) #5
  store ptr %19, ptr %12, align 8, !tbaa !5
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %41, %4
  %21 = load i32, ptr %10, align 4, !tbaa !9
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %24, label %44

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

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

44:                                               ; preds = %20
  %45 = load ptr, ptr %12, align 8, !tbaa !5
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  call void @qsort(ptr noundef %45, i64 noundef %47, i64 noundef 8, ptr noundef @compare)
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %48 = call noalias ptr @malloc(i64 noundef 8) #5
  store ptr %48, ptr %13, align 8, !tbaa !5
  store i32 0, ptr %10, align 4, !tbaa !9
  %49 = load i32, ptr %7, align 4, !tbaa !9
  %50 = sub nsw i32 %49, 1
  store i32 %50, ptr %11, align 4, !tbaa !9
  br label %51

51:                                               ; preds = %105, %44
  %52 = load i32, ptr %10, align 4, !tbaa !9
  %53 = load i32, ptr %11, align 4, !tbaa !9
  %54 = icmp slt i32 %52, %53
  br i1 %54, label %55, label %106

55:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %56 = load ptr, ptr %12, align 8, !tbaa !5
  %57 = load i32, ptr %10, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds %struct.object, ptr %56, i64 %58
  %60 = getelementptr inbounds %struct.object, ptr %59, i32 0, i32 0
  %61 = load i32, ptr %60, align 4, !tbaa !11
  %62 = load ptr, ptr %12, align 8, !tbaa !5
  %63 = load i32, ptr %11, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds %struct.object, ptr %62, i64 %64
  %66 = getelementptr inbounds %struct.object, ptr %65, i32 0, i32 0
  %67 = load i32, ptr %66, align 4, !tbaa !11
  %68 = add nsw i32 %61, %67
  store i32 %68, ptr %14, align 4, !tbaa !9
  %69 = load i32, ptr %14, align 4, !tbaa !9
  %70 = load i32, ptr %8, align 4, !tbaa !9
  %71 = icmp slt i32 %69, %70
  br i1 %71, label %72, label %75

72:                                               ; preds = %55
  %73 = load i32, ptr %10, align 4, !tbaa !9
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %10, align 4, !tbaa !9
  br label %102

75:                                               ; preds = %55
  %76 = load i32, ptr %14, align 4, !tbaa !9
  %77 = load i32, ptr %8, align 4, !tbaa !9
  %78 = icmp sgt i32 %76, %77
  br i1 %78, label %79, label %82

79:                                               ; preds = %75
  %80 = load i32, ptr %11, align 4, !tbaa !9
  %81 = add nsw i32 %80, -1
  store i32 %81, ptr %11, align 4, !tbaa !9
  br label %101

82:                                               ; preds = %75
  %83 = load ptr, ptr %12, align 8, !tbaa !5
  %84 = load i32, ptr %10, align 4, !tbaa !9
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds %struct.object, ptr %83, i64 %85
  %87 = getelementptr inbounds %struct.object, ptr %86, i32 0, i32 1
  %88 = load i32, ptr %87, align 4, !tbaa !13
  %89 = load ptr, ptr %13, align 8, !tbaa !5
  %90 = getelementptr inbounds i32, ptr %89, i64 0
  store i32 %88, ptr %90, align 4, !tbaa !9
  %91 = load ptr, ptr %12, align 8, !tbaa !5
  %92 = load i32, ptr %11, align 4, !tbaa !9
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds %struct.object, ptr %91, i64 %93
  %95 = getelementptr inbounds %struct.object, ptr %94, i32 0, i32 1
  %96 = load i32, ptr %95, align 4, !tbaa !13
  %97 = load ptr, ptr %13, align 8, !tbaa !5
  %98 = getelementptr inbounds i32, ptr %97, i64 1
  store i32 %96, ptr %98, align 4, !tbaa !9
  %99 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 2, ptr %99, align 4, !tbaa !9
  %100 = load ptr, ptr %13, align 8, !tbaa !5
  store ptr %100, ptr %5, align 8
  store i32 1, ptr %15, align 4
  br label %103

101:                                              ; preds = %79
  br label %102

102:                                              ; preds = %101, %72
  store i32 0, ptr %15, align 4
  br label %103

103:                                              ; preds = %102, %82
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  %104 = load i32, ptr %15, align 4
  switch i32 %104, label %107 [
    i32 0, label %105
  ]

105:                                              ; preds = %103
  br label %51, !llvm.loop !16

106:                                              ; preds = %51
  store ptr null, ptr %5, align 8
  store i32 1, ptr %15, align 4
  br label %107

107:                                              ; preds = %106, %103
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %108 = load ptr, ptr %5, align 8
  ret ptr %108
}

; 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)
declare noalias ptr @malloc(i64 noundef) #2

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

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

; 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) "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 }
attributes #5 = { nounwind allocsize(0) }

!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 = !{!"object", !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.object = type { i32, i32 }

; 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 #0 {
  %5 = sext i32 %1 to i64
  %6 = shl nsw i64 %5, 3
  %7 = tail call noalias ptr @malloc(i64 noundef %6) #4
  %8 = icmp sgt i32 %1, 0
  br i1 %8, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %4
  %wide.trip.count = zext nneg i32 %1 to i64
  %min.iters.check = icmp ult i32 %1, 4
  br i1 %min.iters.check, label %.lr.ph.preheader72, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %wide.trip.count, 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.load67 = load <2 x i32>, ptr %11, align 4, !tbaa !5
  %12 = getelementptr inbounds %struct.object, ptr %7, i64 %index
  %13 = getelementptr inbounds %struct.object, ptr %7, 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 4, !tbaa !5
  %interleaved.vec68 = shufflevector <2 x i32> %wide.load67, <2 x i32> %step.add, <4 x i32> <i32 0, i32 2, i32 1, i32 3>
  store <4 x i32> %interleaved.vec68, ptr %13, align 4, !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, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader72

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

.lr.ph:                                           ; preds = %.lr.ph.preheader72, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader72 ]
  %15 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = getelementptr inbounds %struct.object, ptr %7, i64 %indvars.iv
  store i32 %16, ptr %17, align 4, !tbaa !13
  %18 = getelementptr inbounds i8, ptr %17, i64 4
  %19 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %19, ptr %18, align 4, !tbaa !15
  %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 %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %4
  tail call void @qsort(ptr noundef %7, i64 noundef %5, i64 noundef 8, ptr noundef nonnull @compare) #5
  %20 = tail call noalias dereferenceable_or_null(8) ptr @malloc(i64 noundef 8) #4
  %21 = icmp sgt i32 %1, 1
  br i1 %21, label %.lr.ph55.preheader, label %.loopexit

.lr.ph55.preheader:                               ; preds = %._crit_edge
  %22 = add nsw i32 %1, -1
  br label %.lr.ph55

.lr.ph55:                                         ; preds = %.lr.ph55.preheader, %42
  %.13753 = phi i32 [ %.3, %42 ], [ 0, %.lr.ph55.preheader ]
  %.03952 = phi i32 [ %.241, %42 ], [ %22, %.lr.ph55.preheader ]
  %23 = sext i32 %.13753 to i64
  %24 = getelementptr inbounds %struct.object, ptr %7, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !13
  %26 = sext i32 %.03952 to i64
  %27 = getelementptr inbounds %struct.object, ptr %7, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !13
  %29 = add nsw i32 %28, %25
  %30 = icmp slt i32 %29, %2
  br i1 %30, label %31, label %33

31:                                               ; preds = %.lr.ph55
  %32 = add nsw i32 %.13753, 1
  br label %42

33:                                               ; preds = %.lr.ph55
  %34 = icmp sgt i32 %29, %2
  br i1 %34, label %35, label %.thread

35:                                               ; preds = %33
  %36 = add nsw i32 %.03952, -1
  br label %42

.thread:                                          ; preds = %33
  %37 = getelementptr inbounds %struct.object, ptr %7, i64 %23, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !15
  store i32 %38, ptr %20, align 4, !tbaa !5
  %39 = getelementptr inbounds %struct.object, ptr %7, i64 %26, i32 1
  %40 = load i32, ptr %39, align 4, !tbaa !15
  %41 = getelementptr inbounds i8, ptr %20, i64 4
  store i32 %40, ptr %41, align 4, !tbaa !5
  store i32 2, ptr %3, align 4, !tbaa !5
  br label %.loopexit

42:                                               ; preds = %31, %35
  %.241 = phi i32 [ %.03952, %31 ], [ %36, %35 ]
  %.3 = phi i32 [ %32, %31 ], [ %.13753, %35 ]
  %43 = icmp slt i32 %.3, %.241
  br i1 %43, label %.lr.ph55, label %.loopexit, !llvm.loop !17

.loopexit:                                        ; preds = %42, %._crit_edge, %.thread
  %.2 = phi ptr [ %20, %.thread ], [ null, %._crit_edge ], [ null, %42 ]
  ret ptr %.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 #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 @compare(ptr noundef, ptr noundef) #3

attributes #0 = { 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 #1 = { 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 #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 = { 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 #4 = { nounwind allocsize(0) }
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 = !{!"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 = !{!"object", !6, i64 0, !6, i64 4}
!15 = !{!14, !6, i64 4}
!16 = distinct !{!16, !10, !12, !11}
!17 = distinct !{!17, !10}


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