; LLVM IR from JessonYue/LeetCodeLearning :: Array/caiweixiong/cpp (Homework_003)

; 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 nounwind uwtable
declare noundef zeroext i1 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(32)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN12Homework_0038strStr_2ENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_(ptr noundef nonnull align 1 dereferenceable(1) %0, ptr noundef %1, ptr noundef %2) #0 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %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
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8
  %17 = call noundef zeroext i1 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(32) %2) #2
  br i1 %17, label %18, label %19

18:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  br label %110

19:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %20 = call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %1) #2
  %21 = trunc i64 %20 to i32
  store i32 %21, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %22 = call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %2) #2
  %23 = trunc i64 %22 to i32
  store i32 %23, ptr %9, align 4, !tbaa !9
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %19
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %109

28:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %29 = call noundef ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4dataEv(ptr noundef nonnull align 8 dereferenceable(32) %1) #2
  store ptr %29, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %30 = call noundef ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4dataEv(ptr noundef nonnull align 8 dereferenceable(32) %2) #2
  store ptr %30, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  store i32 0, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = sub nsw i32 %31, %32
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %14, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %106, %28
  %36 = load i32, ptr %13, align 4, !tbaa !9
  %37 = load i32, ptr %14, align 4, !tbaa !9
  %38 = icmp slt i32 %36, %37
  br i1 %38, label %39, label %107

39:                                               ; preds = %35
  br label %40

40:                                               ; preds = %58, %39
  %41 = load i32, ptr %13, align 4, !tbaa !9
  %42 = load i32, ptr %14, align 4, !tbaa !9
  %43 = icmp slt i32 %41, %42
  br i1 %43, label %44, label %56

44:                                               ; preds = %40
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = load i32, ptr %13, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i8, ptr %45, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !11
  %50 = sext i8 %49 to i32
  %51 = load ptr, ptr %12, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %51, i64 0
  %53 = load i8, ptr %52, align 1, !tbaa !11
  %54 = sext i8 %53 to i32
  %55 = icmp ne i32 %50, %54
  br label %56

56:                                               ; preds = %44, %40
  %57 = phi i1 [ false, %40 ], [ %55, %44 ]
  br i1 %57, label %58, label %61

58:                                               ; preds = %56
  %59 = load i32, ptr %13, align 4, !tbaa !9
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %13, align 4, !tbaa !9
  br label %40, !llvm.loop !12

61:                                               ; preds = %56
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #2
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %62

62:                                               ; preds = %86, %61
  %63 = load i32, ptr %15, align 4, !tbaa !9
  %64 = load i32, ptr %9, align 4, !tbaa !9
  %65 = icmp slt i32 %63, %64
  br i1 %65, label %66, label %84

66:                                               ; preds = %62
  %67 = load i32, ptr %13, align 4, !tbaa !9
  %68 = load i32, ptr %8, align 4, !tbaa !9
  %69 = icmp slt i32 %67, %68
  br i1 %69, label %70, label %84

70:                                               ; preds = %66
  %71 = load ptr, ptr %11, align 8, !tbaa !5
  %72 = load i32, ptr %13, align 4, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds i8, ptr %71, i64 %73
  %75 = load i8, ptr %74, align 1, !tbaa !11
  %76 = sext i8 %75 to i32
  %77 = load ptr, ptr %12, align 8, !tbaa !5
  %78 = load i32, ptr %15, align 4, !tbaa !9
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds i8, ptr %77, i64 %79
  %81 = load i8, ptr %80, align 1, !tbaa !11
  %82 = sext i8 %81 to i32
  %83 = icmp eq i32 %76, %82
  br label %84

84:                                               ; preds = %70, %66, %62
  %85 = phi i1 [ false, %66 ], [ false, %62 ], [ %83, %70 ]
  br i1 %85, label %86, label %91

86:                                               ; preds = %84
  %87 = load i32, ptr %15, align 4, !tbaa !9
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %15, align 4, !tbaa !9
  %89 = load i32, ptr %13, align 4, !tbaa !9
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %13, align 4, !tbaa !9
  br label %62, !llvm.loop !14

91:                                               ; preds = %84
  %92 = load i32, ptr %15, align 4, !tbaa !9
  %93 = load i32, ptr %9, align 4, !tbaa !9
  %94 = icmp eq i32 %92, %93
  br i1 %94, label %95, label %99

95:                                               ; preds = %91
  %96 = load i32, ptr %13, align 4, !tbaa !9
  %97 = load i32, ptr %9, align 4, !tbaa !9
  %98 = sub nsw i32 %96, %97
  store i32 %98, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %104

99:                                               ; preds = %91
  %100 = load i32, ptr %13, align 4, !tbaa !9
  %101 = load i32, ptr %15, align 4, !tbaa !9
  %102 = sub nsw i32 %100, %101
  %103 = add nsw i32 %102, 1
  store i32 %103, ptr %13, align 4, !tbaa !9
  store i32 0, ptr %10, align 4
  br label %104

104:                                              ; preds = %99, %95
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  %105 = load i32, ptr %10, align 4
  switch i32 %105, label %108 [
    i32 0, label %106
  ]

106:                                              ; preds = %104
  br label %35, !llvm.loop !15

107:                                              ; preds = %35
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %108

108:                                              ; preds = %107, %104
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  br label %109

109:                                              ; preds = %108, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %110

110:                                              ; preds = %109, %18
  %111 = load i32, ptr %4, align 4
  ret i32 %111
}

; 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)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare noundef ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4dataEv(ptr noundef nonnull align 8 dereferenceable(32)) #0 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 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++ 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
declare noundef zeroext i1 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN12Homework_0038strStr_2ENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_(ptr nocapture noundef nonnull readnone align 1 dereferenceable(1) %0, ptr noundef %1, ptr noundef nonnull %2) local_unnamed_addr #0 align 2 {
  %4 = tail call noundef zeroext i1 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(32) %2) #1
  br i1 %4, label %.loopexit, label %5

5:                                                ; preds = %3
  %6 = tail call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %1) #1
  %7 = trunc i64 %6 to i32
  %8 = tail call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %2) #1
  %9 = trunc i64 %8 to i32
  %10 = icmp slt i32 %7, %9
  br i1 %10, label %.loopexit, label %11

11:                                               ; preds = %5
  %12 = tail call noundef ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4dataEv(ptr noundef nonnull align 8 dereferenceable(32) %1) #1
  %13 = tail call noundef ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4dataEv(ptr noundef nonnull align 8 dereferenceable(32) %2) #1
  %14 = sub i32 %7, %9
  %15 = icmp sgt i32 %9, 0
  br i1 %15, label %.split.preheader, label %.split.us

.split.preheader:                                 ; preds = %11
  %16 = sext i32 %14 to i64
  %17 = add i32 %7, 1
  %18 = sub i32 %17, %9
  %19 = and i64 %8, 2147483647
  %sext = shl i64 %6, 32
  %20 = ashr exact i64 %sext, 32
  br label %.split

.split.us:                                        ; preds = %11
  %.not42.us = icmp ne i32 %9, 0
  %.not.us.us = icmp slt i32 %14, 0
  %or.cond77 = or i1 %.not42.us, %.not.us.us
  br i1 %or.cond77, label %.loopexit, label %.preheader.us.us, !llvm.loop !5

21:                                               ; preds = %.preheader.us.us, %24
  %indvars.iv = phi i64 [ 0, %.preheader.us.us ], [ %indvars.iv.next, %24 ]
  %22 = getelementptr inbounds i8, ptr %12, i64 %indvars.iv
  %23 = load i8, ptr %22, align 1, !tbaa !7
  %.not41.us.us = icmp eq i8 %23, %25
  br i1 %.not41.us.us, label %.loopexit.split.loop.exit.loopexit72.split.loop.exit73, label %24

24:                                               ; preds = %21
  %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 %.loopexit.split.loop.exit, label %21, !llvm.loop !10

.preheader.us.us:                                 ; preds = %.split.us
  %25 = load i8, ptr %13, align 1, !tbaa !7
  %26 = add i32 %7, 1
  %wide.trip.count = zext i32 %26 to i64
  br label %21

.split:                                           ; preds = %.split.preheader, %.critedge2
  %.033 = phi i32 [ %45, %.critedge2 ], [ 0, %.split.preheader ]
  %.not = icmp sgt i32 %.033, %14
  br i1 %.not, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %.split
  %27 = load i8, ptr %13, align 1, !tbaa !7
  %28 = sext i32 %.033 to i64
  br label %29

29:                                               ; preds = %.preheader, %32
  %indvars.iv62 = phi i64 [ %28, %.preheader ], [ %indvars.iv.next63, %32 ]
  %30 = getelementptr inbounds i8, ptr %12, i64 %indvars.iv62
  %31 = load i8, ptr %30, align 1, !tbaa !7
  %.not41 = icmp eq i8 %31, %27
  br i1 %.not41, label %.critedge.split.loop.exit75, label %32

32:                                               ; preds = %29
  %indvars.iv.next63 = add nsw i64 %indvars.iv62, 1
  %.not40.not = icmp slt i64 %indvars.iv62, %16
  br i1 %.not40.not, label %29, label %.critedge, !llvm.loop !10

.critedge.split.loop.exit75:                      ; preds = %29
  %33 = trunc nsw i64 %indvars.iv62 to i32
  br label %.critedge

.critedge:                                        ; preds = %32, %.critedge.split.loop.exit75
  %.134.lcssa = phi i32 [ %33, %.critedge.split.loop.exit75 ], [ %18, %32 ]
  %34 = icmp slt i32 %.134.lcssa, %7
  br i1 %34, label %.lr.ph.preheader, label %.critedge2

.lr.ph.preheader:                                 ; preds = %.critedge
  %35 = sext i32 %.134.lcssa to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %41
  %indvars.iv67 = phi i64 [ %35, %.lr.ph.preheader ], [ %indvars.iv.next68, %41 ]
  %indvars.iv65 = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next66, %41 ]
  %36 = getelementptr inbounds i8, ptr %12, i64 %indvars.iv67
  %37 = load i8, ptr %36, align 1, !tbaa !7
  %38 = getelementptr inbounds i8, ptr %13, i64 %indvars.iv65
  %39 = load i8, ptr %38, align 1, !tbaa !7
  %40 = icmp eq i8 %37, %39
  br i1 %40, label %41, label %.critedge2.loopexit

41:                                               ; preds = %.lr.ph
  %indvars.iv.next66 = add nuw nsw i64 %indvars.iv65, 1
  %indvars.iv.next68 = add nsw i64 %indvars.iv67, 1
  %42 = icmp ult i64 %indvars.iv.next66, %19
  %43 = icmp slt i64 %indvars.iv.next68, %20
  %or.cond = select i1 %42, i1 %43, i1 false
  br i1 %or.cond, label %.lr.ph, label %.critedge2.loopexit, !llvm.loop !11

.critedge2.loopexit:                              ; preds = %41, %.lr.ph
  %.235.lcssa.ph.in = phi i64 [ %indvars.iv67, %.lr.ph ], [ %indvars.iv.next68, %41 ]
  %.0.lcssa.ph.in = phi i64 [ %indvars.iv65, %.lr.ph ], [ %indvars.iv.next66, %41 ]
  %.0.lcssa.ph = trunc i64 %.0.lcssa.ph.in to i32
  %.235.lcssa.ph = trunc i64 %.235.lcssa.ph.in to i32
  br label %.critedge2

.critedge2:                                       ; preds = %.critedge2.loopexit, %.critedge
  %.235.lcssa = phi i32 [ %.134.lcssa, %.critedge ], [ %.235.lcssa.ph, %.critedge2.loopexit ]
  %.0.lcssa = phi i32 [ 0, %.critedge ], [ %.0.lcssa.ph, %.critedge2.loopexit ]
  %.not42 = icmp eq i32 %.0.lcssa, %9
  %44 = add i32 %.235.lcssa, 1
  %45 = sub i32 %44, %.0.lcssa
  br i1 %.not42, label %.loopexit.split.loop.exit, label %.split, !llvm.loop !5

.loopexit.split.loop.exit.loopexit72.split.loop.exit73: ; preds = %21
  %46 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.loopexit.split.loop.exit

.loopexit.split.loop.exit:                        ; preds = %24, %.critedge2, %.loopexit.split.loop.exit.loopexit72.split.loop.exit73
  %.us-phi53 = phi i32 [ %46, %.loopexit.split.loop.exit.loopexit72.split.loop.exit73 ], [ %.235.lcssa, %.critedge2 ], [ %26, %24 ]
  %47 = sub nsw i32 %.us-phi53, %9
  br label %.loopexit

.loopexit:                                        ; preds = %.split, %.split.us, %.loopexit.split.loop.exit, %5, %3
  %.4 = phi i32 [ 0, %3 ], [ -1, %5 ], [ %47, %.loopexit.split.loop.exit ], [ -1, %.split.us ], [ -1, %.split ]
  ret i32 %.4
}

; 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 ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4dataEv(ptr noundef nonnull align 8 dereferenceable(32)) 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = distinct !{!10, !6}
!11 = distinct !{!11, !6}


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