; LLVM IR from HarshCasper/NeoAlgo :: C-Plus-Plus/other/Pair-Star.ll (Z8pairStarPc)

; 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: mustprogress uwtable
define dso_local void @_Z8pairStarPc(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  br label %7

7:                                                ; preds = %15, %1
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = load i32, ptr %3, align 4, !tbaa !9
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds i8, ptr %8, i64 %10
  %12 = load i8, ptr %11, align 1, !tbaa !11
  %13 = sext i8 %12 to i32
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %18

15:                                               ; preds = %7
  %16 = load i32, ptr %3, align 4, !tbaa !9
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %3, align 4, !tbaa !9
  br label %7, !llvm.loop !12

18:                                               ; preds = %7
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 0
  %21 = load i8, ptr %20, align 1, !tbaa !11
  %22 = sext i8 %21 to i32
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %27, label %24

24:                                               ; preds = %18
  %25 = load i32, ptr %3, align 4, !tbaa !9
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %24, %18
  store i32 1, ptr %5, align 4
  br label %73

28:                                               ; preds = %24
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %29, i64 0
  %31 = load i8, ptr %30, align 1, !tbaa !11
  %32 = sext i8 %31 to i32
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i64 1
  %35 = load i8, ptr %34, align 1, !tbaa !11
  %36 = sext i8 %35 to i32
  %37 = icmp eq i32 %32, %36
  br i1 %37, label %38, label %69

38:                                               ; preds = %28
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = load i32, ptr %3, align 4, !tbaa !9
  %41 = add nsw i32 %40, 1
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i8, ptr %39, i64 %42
  store i8 0, ptr %43, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %44 = load i32, ptr %3, align 4, !tbaa !9
  %45 = sub nsw i32 %44, 1
  store i32 %45, ptr %6, align 4, !tbaa !9
  br label %46

46:                                               ; preds = %61, %38
  %47 = load i32, ptr %6, align 4, !tbaa !9
  %48 = icmp sge i32 %47, 1
  br i1 %48, label %50, label %49

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

50:                                               ; preds = %46
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = load i32, ptr %6, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i8, ptr %51, i64 %53
  %55 = load i8, ptr %54, align 1, !tbaa !11
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = load i32, ptr %6, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i8, ptr %56, i64 %59
  store i8 %55, ptr %60, align 1, !tbaa !11
  br label %61

61:                                               ; preds = %50
  %62 = load i32, ptr %6, align 4, !tbaa !9
  %63 = add nsw i32 %62, -1
  store i32 %63, ptr %6, align 4, !tbaa !9
  br label %46, !llvm.loop !14

64:                                               ; preds = %49
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  %66 = getelementptr inbounds i8, ptr %65, i64 1
  store i8 42, ptr %66, align 1, !tbaa !11
  %67 = load ptr, ptr %2, align 8, !tbaa !5
  %68 = getelementptr inbounds i8, ptr %67, i64 1
  call void @_Z8pairStarPc(ptr noundef %68)
  br label %72

69:                                               ; preds = %28
  %70 = load ptr, ptr %2, align 8, !tbaa !5
  %71 = getelementptr inbounds i8, ptr %70, i64 1
  call void @_Z8pairStarPc(ptr noundef %71)
  br label %72

72:                                               ; preds = %69, %64
  store i32 0, ptr %5, align 4
  br label %73

73:                                               ; preds = %72, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  %74 = load i32, ptr %5, align 4
  switch i32 %74, label %76 [
    i32 0, label %75
    i32 1, label %75
  ]

75:                                               ; preds = %73, %73
  ret void

76:                                               ; preds = %73
  unreachable
}

; 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 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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: mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @_Z8pairStarPc(ptr nocapture noundef %0) local_unnamed_addr #0 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %tailrecurse.backedge, %1
  %indvar = phi i64 [ %indvar.next, %tailrecurse.backedge ], [ 0, %1 ]
  %.tr = phi ptr [ %11, %tailrecurse.backedge ], [ %0, %1 ]
  br label %2

2:                                                ; preds = %2, %tailrecurse
  %indvars.iv = phi i64 [ %indvars.iv.next, %2 ], [ 0, %tailrecurse ]
  %3 = getelementptr inbounds i8, ptr %.tr, i64 %indvars.iv
  %4 = load i8, ptr %3, align 1, !tbaa !5
  %.not = icmp eq i8 %4, 0
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  br i1 %.not, label %5, label %2, !llvm.loop !8

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %.tr, i64 %indvars.iv
  %7 = load i8, ptr %.tr, align 1, !tbaa !5
  %8 = icmp eq i8 %7, 0
  %9 = icmp eq i64 %indvars.iv, 0
  %or.cond = or i1 %9, %8
  br i1 %or.cond, label %47, label %10

10:                                               ; preds = %5
  %11 = getelementptr inbounds i8, ptr %.tr, i64 1
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %13 = icmp eq i8 %7, %12
  br i1 %13, label %14, label %tailrecurse.backedge

14:                                               ; preds = %10
  %15 = getelementptr inbounds i8, ptr %6, i64 1
  store i8 0, ptr %15, align 1, !tbaa !5
  %16 = icmp ugt i64 %indvars.iv, 1
  br i1 %16, label %iter.check, label %._crit_edge

iter.check:                                       ; preds = %14
  %17 = add nsw i64 %indvars.iv, -1
  %min.iters.check = icmp ult i64 %indvars.iv, 5
  br i1 %min.iters.check, label %.lr.ph.preheader, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %iter.check
  %18 = trunc i64 %indvars.iv to i32
  %19 = add i32 %18, -1
  %20 = icmp eq i32 %19, 0
  %21 = add nsw i64 %indvars.iv, -4294967298
  %22 = icmp ult i64 %21, -4294967296
  %23 = or i1 %20, %22
  %24 = getelementptr i8, ptr %0, i64 %indvar
  %scevgep = getelementptr i8, ptr %24, i64 %indvars.iv
  %25 = getelementptr i8, ptr %24, i64 2
  %26 = icmp ugt ptr %25, %scevgep
  %27 = zext i32 %19 to i64
  %scevgep31 = getelementptr i8, ptr %.tr, i64 %27
  %28 = sub nsw i64 2, %indvars.iv
  %29 = getelementptr i8, ptr %scevgep31, i64 %28
  %30 = icmp ugt ptr %29, %scevgep31
  %31 = or i1 %23, %26
  %32 = or i1 %31, %30
  br i1 %32, label %.lr.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %vector.scevcheck
  %33 = add nuw nsw i64 %indvars.iv, 4294967295
  %34 = and i64 %33, 4294967295
  %35 = sub nsw i64 %34, %indvars.iv
  %diff.check = icmp ult i64 %35, 16
  br i1 %diff.check, label %.lr.ph.preheader, label %vector.main.loop.iter.check

vector.main.loop.iter.check:                      ; preds = %vector.memcheck
  %min.iters.check36 = icmp ult i64 %indvars.iv, 17
  br i1 %min.iters.check36, label %vec.epilog.ph, label %vector.ph

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %n.vec = and i64 %17, -16
  %invariant.gep = getelementptr i8, ptr %.tr, i64 -15
  %invariant.gep48 = getelementptr i8, ptr %.tr, i64 -15
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = sub i64 %indvars.iv, %index
  %36 = add i64 %offset.idx, 4294967295
  %37 = and i64 %36, 4294967295
  %gep = getelementptr i8, ptr %invariant.gep, i64 %37
  %wide.load = load <16 x i8>, ptr %gep, align 1, !tbaa !5
  %gep49 = getelementptr i8, ptr %invariant.gep48, i64 %offset.idx
  store <16 x i8> %wide.load, ptr %gep49, align 1, !tbaa !5
  %index.next = add nuw i64 %index, 16
  %38 = icmp eq i64 %index.next, %n.vec
  br i1 %38, label %middle.block, label %vector.body, !llvm.loop !10

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %17, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %vec.epilog.iter.check

vec.epilog.iter.check:                            ; preds = %middle.block
  %ind.end40 = sub i64 %indvars.iv, %n.vec
  %n.vec.remaining = and i64 %17, 12
  %min.epilog.iters.check = icmp eq i64 %n.vec.remaining, 0
  br i1 %min.epilog.iters.check, label %.lr.ph.preheader, label %vec.epilog.ph

.lr.ph.preheader:                                 ; preds = %vec.epilog.middle.block, %vector.memcheck, %vector.scevcheck, %iter.check, %vec.epilog.iter.check
  %indvars.iv24.ph = phi i64 [ %indvars.iv, %iter.check ], [ %indvars.iv, %vector.memcheck ], [ %indvars.iv, %vector.scevcheck ], [ %ind.end40, %vec.epilog.iter.check ], [ %ind.end, %vec.epilog.middle.block ]
  br label %.lr.ph

vec.epilog.ph:                                    ; preds = %vector.main.loop.iter.check, %vec.epilog.iter.check
  %vec.epilog.resume.val = phi i64 [ %n.vec, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %n.vec39 = and i64 %17, -4
  %ind.end = sub i64 %indvars.iv, %n.vec39
  %invariant.gep50 = getelementptr i8, ptr %.tr, i64 -3
  %invariant.gep52 = getelementptr i8, ptr %.tr, i64 -3
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index41 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next46, %vec.epilog.vector.body ]
  %offset.idx42 = sub i64 %indvars.iv, %index41
  %39 = add i64 %offset.idx42, 4294967295
  %40 = and i64 %39, 4294967295
  %gep51 = getelementptr i8, ptr %invariant.gep50, i64 %40
  %wide.load43 = load <4 x i8>, ptr %gep51, align 1, !tbaa !5
  %gep53 = getelementptr i8, ptr %invariant.gep52, i64 %offset.idx42
  store <4 x i8> %wide.load43, ptr %gep53, align 1, !tbaa !5
  %index.next46 = add nuw i64 %index41, 4
  %41 = icmp eq i64 %index.next46, %n.vec39
  br i1 %41, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !13

vec.epilog.middle.block:                          ; preds = %vec.epilog.vector.body
  %cmp.n47 = icmp eq i64 %17, %n.vec39
  br i1 %cmp.n47, label %._crit_edge, label %.lr.ph.preheader

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %vec.epilog.middle.block, %14
  store i8 42, ptr %11, align 1, !tbaa !5
  br label %tailrecurse.backedge

tailrecurse.backedge:                             ; preds = %._crit_edge, %10
  %indvar.next = add i64 %indvar, 1
  br label %tailrecurse

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv24 = phi i64 [ %indvars.iv.next25, %.lr.ph ], [ %indvars.iv24.ph, %.lr.ph.preheader ]
  %indvars.iv.next25 = add nsw i64 %indvars.iv24, -1
  %42 = and i64 %indvars.iv.next25, 4294967295
  %43 = getelementptr inbounds i8, ptr %.tr, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %.tr, i64 %indvars.iv24
  store i8 %44, ptr %45, align 1, !tbaa !5
  %46 = icmp sgt i64 %indvars.iv24, 2
  br i1 %46, label %.lr.ph, label %._crit_edge, !llvm.loop !14

47:                                               ; preds = %5
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9, !11, !12}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !9, !11, !12}
!14 = distinct !{!14, !9, !11}


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