; LLVM IR from kenjin/Awesome-LC-C-Cracker :: leetcode-c-sol/1442_count-triplets-that-can-form-two-arrays-of-equal-xor (countTriplets)

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

; Function Attrs: nounwind uwtable
define dso_local i32 @countTriplets(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %50, %2
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = sub nsw i32 %12, 1
  %14 = icmp slt i32 %11, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %10
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %53

16:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i32, ptr %17, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !9
  store i32 %21, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %9, align 4, !tbaa !9
  br label %24

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

28:                                               ; preds = %24
  store i32 5, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %49

29:                                               ; preds = %24
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = load i32, ptr %9, 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 %8, align 4, !tbaa !9
  %36 = xor i32 %35, %34
  store i32 %36, ptr %8, align 4, !tbaa !9
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %45, label %39

39:                                               ; preds = %29
  %40 = load i32, ptr %9, align 4, !tbaa !9
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = sub nsw i32 %40, %41
  %43 = load i32, ptr %5, align 4, !tbaa !9
  %44 = add nsw i32 %43, %42
  store i32 %44, ptr %5, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %39, %29
  br label %46

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

49:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %50

50:                                               ; preds = %49
  %51 = load i32, ptr %6, align 4, !tbaa !9
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %6, align 4, !tbaa !9
  br label %10, !llvm.loop !13

53:                                               ; preds = %15
  %54 = load i32, ptr %5, align 4, !tbaa !9
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %54
}

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

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

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: read) uwtable
define dso_local i32 @countTriplets(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp sgt i32 %1, 1
  br i1 %3, label %.lr.ph24.preheader, label %._crit_edge

.lr.ph24.preheader:                               ; preds = %2
  %4 = add nsw i32 %1, -1
  %wide.trip.count32 = zext i32 %4 to i64
  %wide.trip.count = zext nneg i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count32, 1
  %5 = icmp eq i32 %4, 1
  br i1 %5, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph24.preheader.new

.lr.ph24.preheader.new:                           ; preds = %.lr.ph24.preheader
  %unroll_iter = and i64 %wide.trip.count32, 4294967294
  br label %.lr.ph.preheader

.loopexit:                                        ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %indvars.iv.next30.1 = add nuw nsw i64 %indvars.iv29, 2
  %6 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next30
  %7 = load i32, ptr %6, align 4, !tbaa !5
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %.lr.ph.1, %.loopexit
  %indvars.iv26.1 = phi i64 [ %indvars.iv.next, %.loopexit ], [ %indvars.iv.next27.1, %.lr.ph.1 ]
  %.01620.1 = phi i32 [ %7, %.loopexit ], [ %10, %.lr.ph.1 ]
  %.119.1 = phi i32 [ %.2, %.loopexit ], [ %.2.1, %.lr.ph.1 ]
  %8 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv26.1
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = xor i32 %9, %.01620.1
  %.not.1 = icmp eq i32 %.01620.1, %9
  %11 = sub nuw nsw i64 %indvars.iv26.1, %indvars.iv.next30
  %12 = trunc nsw i64 %11 to i32
  %13 = select i1 %.not.1, i32 %12, i32 0
  %.2.1 = add nsw i32 %13, %.119.1
  %indvars.iv.next27.1 = add nuw nsw i64 %indvars.iv26.1, 1
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next27.1, %wide.trip.count
  br i1 %exitcond.not.1, label %.loopexit.1, label %.lr.ph.1, !llvm.loop !9

.loopexit.1:                                      ; preds = %.lr.ph.1
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add nuw i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader, !llvm.loop !11

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.loopexit.1, %.lr.ph24.preheader
  %.2.lcssa.lcssa.ph = phi i32 [ poison, %.lr.ph24.preheader ], [ %.2.1, %.loopexit.1 ]
  %indvars.iv29.unr = phi i64 [ 0, %.lr.ph24.preheader ], [ %indvars.iv.next30.1, %.loopexit.1 ]
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph24.preheader ], [ %indvars.iv.next.1, %.loopexit.1 ]
  %.01822.unr = phi i32 [ 0, %.lr.ph24.preheader ], [ %.2.1, %.loopexit.1 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.preheader.epil

.lr.ph.preheader.epil:                            ; preds = %._crit_edge.loopexit.unr-lcssa
  %14 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv29.unr
  %15 = load i32, ptr %14, align 4, !tbaa !5
  br label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.lr.ph.epil, %.lr.ph.preheader.epil
  %indvars.iv26.epil = phi i64 [ %indvars.iv.unr, %.lr.ph.preheader.epil ], [ %indvars.iv.next27.epil, %.lr.ph.epil ]
  %.01620.epil = phi i32 [ %15, %.lr.ph.preheader.epil ], [ %18, %.lr.ph.epil ]
  %.119.epil = phi i32 [ %.01822.unr, %.lr.ph.preheader.epil ], [ %.2.epil, %.lr.ph.epil ]
  %16 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv26.epil
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = xor i32 %17, %.01620.epil
  %.not.epil = icmp eq i32 %.01620.epil, %17
  %19 = sub nuw nsw i64 %indvars.iv26.epil, %indvars.iv29.unr
  %20 = trunc nsw i64 %19 to i32
  %21 = select i1 %.not.epil, i32 %20, i32 0
  %.2.epil = add nsw i32 %21, %.119.epil
  %indvars.iv.next27.epil = add nuw nsw i64 %indvars.iv26.epil, 1
  %exitcond.not.epil = icmp eq i64 %indvars.iv.next27.epil, %wide.trip.count
  br i1 %exitcond.not.epil, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !9

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %2
  %.018.lcssa = phi i32 [ 0, %2 ], [ %.2.lcssa.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %.2.epil, %.lr.ph.epil ]
  ret i32 %.018.lcssa

.lr.ph.preheader:                                 ; preds = %.loopexit.1, %.lr.ph24.preheader.new
  %indvars.iv29 = phi i64 [ 0, %.lr.ph24.preheader.new ], [ %indvars.iv.next30.1, %.loopexit.1 ]
  %indvars.iv = phi i64 [ 1, %.lr.ph24.preheader.new ], [ %indvars.iv.next.1, %.loopexit.1 ]
  %.01822 = phi i32 [ 0, %.lr.ph24.preheader.new ], [ %.2.1, %.loopexit.1 ]
  %niter = phi i64 [ 0, %.lr.ph24.preheader.new ], [ %niter.next.1, %.loopexit.1 ]
  %indvars.iv.next30 = or disjoint i64 %indvars.iv29, 1
  %22 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv29
  %23 = load i32, ptr %22, align 4, !tbaa !5
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv26 = phi i64 [ %indvars.iv, %.lr.ph.preheader ], [ %indvars.iv.next27, %.lr.ph ]
  %.01620 = phi i32 [ %23, %.lr.ph.preheader ], [ %26, %.lr.ph ]
  %.119 = phi i32 [ %.01822, %.lr.ph.preheader ], [ %.2, %.lr.ph ]
  %24 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv26
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = xor i32 %25, %.01620
  %.not = icmp eq i32 %.01620, %25
  %27 = sub nuw nsw i64 %indvars.iv26, %indvars.iv29
  %28 = trunc nsw i64 %27 to i32
  %29 = select i1 %.not, i32 %28, i32 0
  %.2 = add nsw i32 %29, %.119
  %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next27, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !9
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: read) 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" }

!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}


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