; LLVM IR from 6leetcode/6leetcode :: questions/Algorithms/0015. 3Sum (Testing)

; 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 [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 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

declare ptr @sdsnew(ptr noundef) #1

declare ptr @sdscat(ptr noundef, ptr noundef) #1

declare ptr @sdscatprintf(ptr 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
define dso_local ptr @matrix_show(ptr noundef %0, i32 noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %11 = call ptr @sdsnew(ptr noundef @.str)
  store ptr %11, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %81, %3
  %13 = load i32, ptr %8, align 4, !tbaa !9
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %84

17:                                               ; preds = %12
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = call ptr @sdscat(ptr noundef %18, ptr noundef @.str)
  store ptr %19, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %69, %17
  %21 = load i32, ptr %10, align 4, !tbaa !9
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds i32, ptr %22, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = icmp slt i32 %21, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %20
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %72

29:                                               ; preds = %20
  %30 = load i32, ptr %10, align 4, !tbaa !9
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %44

32:                                               ; preds = %29
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds ptr, ptr %34, i64 %36
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = load i32, ptr %10, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds i32, ptr %38, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !9
  %43 = call ptr (ptr, ptr, ...) @sdscatprintf(ptr noundef %33, ptr noundef @.str.2, i32 noundef %42)
  store ptr %43, ptr %7, align 8, !tbaa !5
  br label %56

44:                                               ; preds = %29
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds ptr, ptr %46, i64 %48
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  %51 = load i32, ptr %10, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i32, ptr %50, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !9
  %55 = call ptr (ptr, ptr, ...) @sdscatprintf(ptr noundef %45, ptr noundef @.str.3, i32 noundef %54)
  store ptr %55, ptr %7, align 8, !tbaa !5
  br label %56

56:                                               ; preds = %44, %32
  %57 = load i32, ptr %10, align 4, !tbaa !9
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = load i32, ptr %8, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds i32, ptr %58, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !9
  %63 = sub nsw i32 %62, 1
  %64 = icmp eq i32 %57, %63
  br i1 %64, label %65, label %68

65:                                               ; preds = %56
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = call ptr @sdscat(ptr noundef %66, ptr noundef @.str.4)
  store ptr %67, ptr %7, align 8, !tbaa !5
  br label %68

68:                                               ; preds = %65, %56
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %10, align 4, !tbaa !9
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %10, align 4, !tbaa !9
  br label %20, !llvm.loop !11

72:                                               ; preds = %28
  %73 = load i32, ptr %8, align 4, !tbaa !9
  %74 = load i32, ptr %5, align 4, !tbaa !9
  %75 = sub nsw i32 %74, 1
  %76 = icmp ne i32 %73, %75
  br i1 %76, label %77, label %80

77:                                               ; preds = %72
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  %79 = call ptr @sdscat(ptr noundef %78, ptr noundef @.str.5)
  store ptr %79, ptr %7, align 8, !tbaa !5
  br label %80

80:                                               ; preds = %77, %72
  br label %81

81:                                               ; preds = %80
  %82 = load i32, ptr %8, align 4, !tbaa !9
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %8, align 4, !tbaa !9
  br label %12, !llvm.loop !13

84:                                               ; preds = %16
  %85 = load ptr, ptr %7, align 8, !tbaa !5
  %86 = call ptr @sdscat(ptr noundef %85, ptr noundef @.str.4)
  store ptr %86, ptr %7, align 8, !tbaa !5
  %87 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret ptr %87
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #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 #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 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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 [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1

declare ptr @sdsnew(ptr noundef) local_unnamed_addr #0

declare ptr @sdscat(ptr noundef, ptr noundef) local_unnamed_addr #0

declare ptr @sdscatprintf(ptr noundef, ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @matrix_show(ptr nocapture noundef readonly %0, i32 noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #1 {
  %4 = tail call ptr @sdsnew(ptr noundef nonnull @.str) #2
  %5 = icmp sgt i32 %1, 0
  br i1 %5, label %.lr.ph33, label %._crit_edge34

.lr.ph33:                                         ; preds = %3
  %6 = add nsw i32 %1, -1
  %7 = zext nneg i32 %6 to i64
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %9

._crit_edge34:                                    ; preds = %40, %3
  %.026.lcssa = phi ptr [ %4, %3 ], [ %.4, %40 ]
  %8 = tail call ptr @sdscat(ptr noundef %.026.lcssa, ptr noundef nonnull @.str.4) #2
  ret ptr %8

9:                                                ; preds = %.lr.ph33, %40
  %indvars.iv38 = phi i64 [ 0, %.lr.ph33 ], [ %indvars.iv.next39, %40 ]
  %.02630 = phi ptr [ %4, %.lr.ph33 ], [ %.4, %40 ]
  %10 = tail call ptr @sdscat(ptr noundef %.02630, ptr noundef nonnull @.str) #2
  %11 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv38
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %14, label %._crit_edge

14:                                               ; preds = %9
  %15 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv38
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = tail call ptr (ptr, ptr, ...) @sdscatprintf(ptr noundef %10, ptr noundef nonnull @.str.2, i32 noundef %17) #2
  %.pre = load i32, ptr %11, align 4, !tbaa !5
  %19 = icmp eq i32 %.pre, 1
  br i1 %19, label %20, label %22

20:                                               ; preds = %14
  %21 = tail call ptr @sdscat(ptr noundef %18, ptr noundef nonnull @.str.4) #2
  %.pre41 = load i32, ptr %11, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %20, %14
  %23 = phi i32 [ %.pre41, %20 ], [ %.pre, %14 ]
  %.3.peel = phi ptr [ %21, %20 ], [ %18, %14 ]
  %24 = icmp sgt i32 %23, 1
  br i1 %24, label %.peel.next, label %._crit_edge

._crit_edge:                                      ; preds = %34, %22, %9
  %.1.lcssa = phi ptr [ %10, %9 ], [ %.3.peel, %22 ], [ %.3, %34 ]
  %.not = icmp eq i64 %indvars.iv38, %7
  br i1 %.not, label %40, label %38

.peel.next:                                       ; preds = %22, %34
  %indvars.iv = phi i64 [ %indvars.iv.next, %34 ], [ 1, %22 ]
  %.128 = phi ptr [ %.3, %34 ], [ %.3.peel, %22 ]
  %25 = load ptr, ptr %15, align 8, !tbaa !9
  %26 = getelementptr inbounds i32, ptr %25, i64 %indvars.iv
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = tail call ptr (ptr, ptr, ...) @sdscatprintf(ptr noundef %.128, ptr noundef nonnull @.str.3, i32 noundef %27) #2
  %.pre42 = load i32, ptr %11, align 4, !tbaa !5
  %29 = add nsw i32 %.pre42, -1
  %30 = zext i32 %29 to i64
  %31 = icmp eq i64 %indvars.iv, %30
  br i1 %31, label %32, label %34

32:                                               ; preds = %.peel.next
  %33 = tail call ptr @sdscat(ptr noundef %28, ptr noundef nonnull @.str.4) #2
  %.pre43 = load i32, ptr %11, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %.peel.next, %32
  %35 = phi i32 [ %.pre43, %32 ], [ %.pre42, %.peel.next ]
  %.3 = phi ptr [ %33, %32 ], [ %28, %.peel.next ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %36 = sext i32 %35 to i64
  %37 = icmp slt i64 %indvars.iv.next, %36
  br i1 %37, label %.peel.next, label %._crit_edge, !llvm.loop !11

38:                                               ; preds = %._crit_edge
  %39 = tail call ptr @sdscat(ptr noundef %.1.lcssa, ptr noundef nonnull @.str.5) #2
  br label %40

40:                                               ; preds = %._crit_edge, %38
  %.4 = phi ptr [ %39, %38 ], [ %.1.lcssa, %._crit_edge ]
  %indvars.iv.next39 = add nuw nsw i64 %indvars.iv38, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next39, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge34, label %9, !llvm.loop !14
}

attributes #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 = { 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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12, !13}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.peeled.count", i32 1}
!14 = distinct !{!14, !12}


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