; LLVM IR from HarshCasper/NeoAlgo :: C-Plus-Plus/cp/zalgorithm.ll/Z4getZNSt7 (cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPi)

; 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 @_Z4getZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPi(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %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 ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %10 = call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #3
  %11 = trunc i64 %10 to i32
  store i32 %11, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 1, ptr %8, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %117, %2
  %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
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %120

17:                                               ; preds = %12
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = icmp sgt i32 %18, %19
  br i1 %20, label %21, label %56

21:                                               ; preds = %17
  %22 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %22, ptr %7, align 4, !tbaa !9
  store i32 %22, ptr %6, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %43, %21
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %27, label %41

27:                                               ; preds = %23
  %28 = load i32, ptr %7, align 4, !tbaa !9
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = sub nsw i32 %28, %29
  %31 = sext i32 %30 to i64
  %32 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %31)
  %33 = load i8, ptr %32, align 1, !tbaa !11
  %34 = sext i8 %33 to i32
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %36)
  %38 = load i8, ptr %37, align 1, !tbaa !11
  %39 = sext i8 %38 to i32
  %40 = icmp eq i32 %34, %39
  br label %41

41:                                               ; preds = %27, %23
  %42 = phi i1 [ false, %23 ], [ %40, %27 ]
  br i1 %42, label %43, label %46

43:                                               ; preds = %41
  %44 = load i32, ptr %7, align 4, !tbaa !9
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %7, align 4, !tbaa !9
  br label %23, !llvm.loop !12

46:                                               ; preds = %41
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = sub nsw i32 %47, %48
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = load i32, ptr %8, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i32, ptr %50, i64 %52
  store i32 %49, ptr %53, align 4, !tbaa !9
  %54 = load i32, ptr %7, align 4, !tbaa !9
  %55 = add nsw i32 %54, -1
  store i32 %55, ptr %7, align 4, !tbaa !9
  br label %116

56:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = load i32, ptr %6, align 4, !tbaa !9
  %59 = sub nsw i32 %57, %58
  store i32 %59, ptr %9, align 4, !tbaa !9
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = load i32, ptr %9, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds i32, ptr %60, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !9
  %65 = load i32, ptr %7, align 4, !tbaa !9
  %66 = load i32, ptr %8, align 4, !tbaa !9
  %67 = sub nsw i32 %65, %66
  %68 = add nsw i32 %67, 1
  %69 = icmp slt i32 %64, %68
  br i1 %69, label %70, label %80

70:                                               ; preds = %56
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = load i32, ptr %9, align 4, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds i32, ptr %71, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !9
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = load i32, ptr %8, align 4, !tbaa !9
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds i32, ptr %76, i64 %78
  store i32 %75, ptr %79, align 4, !tbaa !9
  br label %115

80:                                               ; preds = %56
  %81 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %81, ptr %6, align 4, !tbaa !9
  br label %82

82:                                               ; preds = %102, %80
  %83 = load i32, ptr %7, align 4, !tbaa !9
  %84 = load i32, ptr %5, align 4, !tbaa !9
  %85 = icmp slt i32 %83, %84
  br i1 %85, label %86, label %100

86:                                               ; preds = %82
  %87 = load i32, ptr %7, align 4, !tbaa !9
  %88 = load i32, ptr %6, align 4, !tbaa !9
  %89 = sub nsw i32 %87, %88
  %90 = sext i32 %89 to i64
  %91 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %90)
  %92 = load i8, ptr %91, align 1, !tbaa !11
  %93 = sext i8 %92 to i32
  %94 = load i32, ptr %7, align 4, !tbaa !9
  %95 = sext i32 %94 to i64
  %96 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %95)
  %97 = load i8, ptr %96, align 1, !tbaa !11
  %98 = sext i8 %97 to i32
  %99 = icmp eq i32 %93, %98
  br label %100

100:                                              ; preds = %86, %82
  %101 = phi i1 [ false, %82 ], [ %99, %86 ]
  br i1 %101, label %102, label %105

102:                                              ; preds = %100
  %103 = load i32, ptr %7, align 4, !tbaa !9
  %104 = add nsw i32 %103, 1
  store i32 %104, ptr %7, align 4, !tbaa !9
  br label %82, !llvm.loop !14

105:                                              ; preds = %100
  %106 = load i32, ptr %7, align 4, !tbaa !9
  %107 = load i32, ptr %6, align 4, !tbaa !9
  %108 = sub nsw i32 %106, %107
  %109 = load ptr, ptr %4, align 8, !tbaa !5
  %110 = load i32, ptr %8, align 4, !tbaa !9
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds i32, ptr %109, i64 %111
  store i32 %108, ptr %112, align 4, !tbaa !9
  %113 = load i32, ptr %7, align 4, !tbaa !9
  %114 = add nsw i32 %113, -1
  store i32 %114, ptr %7, align 4, !tbaa !9
  br label %115

115:                                              ; preds = %105, %70
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %116

116:                                              ; preds = %115, %46
  br label %117

117:                                              ; preds = %116
  %118 = load i32, ptr %8, align 4, !tbaa !9
  %119 = add nsw i32 %118, 1
  store i32 %119, ptr %8, align 4, !tbaa !9
  br label %12, !llvm.loop !15

120:                                              ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) #2 align 2

; 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 = { mustprogress 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++ 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}
!15 = distinct !{!15, !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 nounwind uwtable
define dso_local void @_Z4getZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPi(ptr noundef nonnull %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %3 = tail call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #1
  %4 = trunc i64 %3 to i32
  %5 = icmp sgt i32 %4, 1
  br i1 %5, label %.lr.ph58.preheader, label %._crit_edge

.lr.ph58.preheader:                               ; preds = %2
  %6 = and i64 %3, 2147483647
  %wide.trip.count67 = and i64 %3, 2147483647
  br label %.lr.ph58

._crit_edge:                                      ; preds = %39, %2
  ret void

.lr.ph58:                                         ; preds = %.lr.ph58.preheader, %39
  %indvars.iv60 = phi i64 [ 1, %.lr.ph58.preheader ], [ %indvars.iv.next61, %39 ]
  %.057 = phi i32 [ 0, %.lr.ph58.preheader ], [ %.2, %39 ]
  %.04155 = phi i32 [ 0, %.lr.ph58.preheader ], [ %.4, %39 ]
  %indvars66 = trunc i64 %indvars.iv60 to i32
  %7 = sext i32 %.04155 to i64
  %8 = icmp sgt i64 %indvars.iv60, %7
  br i1 %8, label %.lr.ph51, label %20

.lr.ph51:                                         ; preds = %.lr.ph58, %15
  %indvars.iv62 = phi i64 [ %indvars.iv.next63, %15 ], [ %indvars.iv60, %.lr.ph58 ]
  %9 = sub nuw nsw i64 %indvars.iv62, %indvars.iv60
  %10 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %9)
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %12 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %indvars.iv62)
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %14 = icmp eq i8 %11, %13
  br i1 %14, label %15, label %.critedge.split.loop.exit

15:                                               ; preds = %.lr.ph51
  %indvars.iv.next63 = add nuw nsw i64 %indvars.iv62, 1
  %exitcond65.not = icmp eq i64 %indvars.iv.next63, %wide.trip.count67
  br i1 %exitcond65.not, label %.critedge, label %.lr.ph51, !llvm.loop !8

.critedge.split.loop.exit:                        ; preds = %.lr.ph51
  %16 = trunc nuw nsw i64 %indvars.iv62 to i32
  br label %.critedge

.critedge:                                        ; preds = %15, %.critedge.split.loop.exit
  %.142.lcssa.ph = phi i32 [ %16, %.critedge.split.loop.exit ], [ %4, %15 ]
  %17 = sub nsw i32 %.142.lcssa.ph, %indvars66
  %18 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv60
  store i32 %17, ptr %18, align 4, !tbaa !10
  %19 = add nsw i32 %.142.lcssa.ph, -1
  br label %39

20:                                               ; preds = %.lr.ph58
  %21 = sext i32 %.057 to i64
  %22 = sub nsw i64 %indvars.iv60, %21
  %23 = getelementptr inbounds i32, ptr %1, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !10
  %25 = sub nsw i32 %.04155, %indvars66
  %.not = icmp sgt i32 %24, %25
  br i1 %.not, label %.preheader46, label %27

.preheader46:                                     ; preds = %20
  %26 = icmp slt i32 %.04155, %4
  br i1 %26, label %.lr.ph, label %.critedge2

27:                                               ; preds = %20
  %28 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv60
  store i32 %24, ptr %28, align 4, !tbaa !10
  br label %39

.lr.ph:                                           ; preds = %.preheader46, %35
  %indvars.iv = phi i64 [ %indvars.iv.next, %35 ], [ %7, %.preheader46 ]
  %29 = sub nsw i64 %indvars.iv, %indvars.iv60
  %30 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %29)
  %31 = load i8, ptr %30, align 1, !tbaa !5
  %32 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %indvars.iv)
  %33 = load i8, ptr %32, align 1, !tbaa !5
  %34 = icmp eq i8 %31, %33
  br i1 %34, label %35, label %.critedge2.loopexit.split.loop.exit69

35:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %6
  br i1 %exitcond.not, label %.critedge2.loopexit, label %.lr.ph, !llvm.loop !12

.critedge2.loopexit.split.loop.exit69:            ; preds = %.lr.ph
  %36 = trunc nsw i64 %indvars.iv to i32
  br label %.critedge2.loopexit

.critedge2.loopexit:                              ; preds = %35, %.critedge2.loopexit.split.loop.exit69
  %.243.lcssa.ph = phi i32 [ %36, %.critedge2.loopexit.split.loop.exit69 ], [ %4, %35 ]
  %.pre = sub nsw i32 %.243.lcssa.ph, %indvars66
  br label %.critedge2

.critedge2:                                       ; preds = %.critedge2.loopexit, %.preheader46
  %.pre-phi = phi i32 [ %.pre, %.critedge2.loopexit ], [ %25, %.preheader46 ]
  %.243.lcssa = phi i32 [ %.243.lcssa.ph, %.critedge2.loopexit ], [ %.04155, %.preheader46 ]
  %37 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv60
  store i32 %.pre-phi, ptr %37, align 4, !tbaa !10
  %38 = add nsw i32 %.243.lcssa, -1
  br label %39

39:                                               ; preds = %27, %.critedge2, %.critedge
  %.4 = phi i32 [ %19, %.critedge ], [ %.04155, %27 ], [ %38, %.critedge2 ]
  %.2 = phi i32 [ %indvars66, %.critedge ], [ %.057, %27 ], [ %indvars66, %.critedge2 ]
  %indvars.iv.next61 = add nuw nsw i64 %indvars.iv60, 1
  %exitcond68.not = icmp eq i64 %indvars.iv.next61, %wide.trip.count67
  br i1 %exitcond68.not, label %._crit_edge, label %.lr.ph58, !llvm.loop !13
}

; Function Attrs: mustprogress nounwind uwtable
declare noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) local_unnamed_addr #0 align 2

attributes #0 = { mustprogress 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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = distinct !{!12, !9}
!13 = distinct !{!13, !9}


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