; LLVM IR from devparthgarg/Data-Structures-and-Algorithms :: 10. Strings/10 Check for Anagram (10b Check for Anagram)

; 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 noundef zeroext i1 @_Z9isAnagramNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca [256 x i32], align 16
  %7 = alloca i32, align 4
  %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 ptr %1, ptr %5, align 8, !tbaa !5
  %11 = call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #4
  %12 = call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv(ptr noundef nonnull align 8 dereferenceable(32) %1) #4
  %13 = icmp ne i64 %11, %12
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  store i1 false, ptr %3, align 1
  br label %63

15:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 1024, ptr %6) #4
  call void @llvm.memset.p0.i64(ptr align 16 %6, i8 0, i64 1024, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %16 = call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #4
  %17 = trunc i64 %16 to i32
  store i32 %17, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %40, %15
  %19 = load i32, ptr %8, align 4, !tbaa !9
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %43

23:                                               ; preds = %18
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %25)
  %27 = load i8, ptr %26, align 1, !tbaa !11
  %28 = sext i8 %27 to i64
  %29 = getelementptr inbounds [256 x i32], ptr %6, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %29, align 4, !tbaa !9
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %1, i64 noundef %33)
  %35 = load i8, ptr %34, align 1, !tbaa !11
  %36 = sext i8 %35 to i64
  %37 = getelementptr inbounds [256 x i32], ptr %6, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !9
  %39 = add nsw i32 %38, -1
  store i32 %39, ptr %37, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %23
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %8, align 4, !tbaa !9
  br label %18, !llvm.loop !12

43:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %44

44:                                               ; preds = %56, %43
  %45 = load i32, ptr %9, align 4, !tbaa !9
  %46 = icmp slt i32 %45, 256
  br i1 %46, label %48, label %47

47:                                               ; preds = %44
  store i32 5, ptr %10, align 4
  br label %59

48:                                               ; preds = %44
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [256 x i32], ptr %6, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !9
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %54, label %55

54:                                               ; preds = %48
  store i1 false, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %59

55:                                               ; preds = %48
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %9, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %9, align 4, !tbaa !9
  br label %44, !llvm.loop !14

59:                                               ; preds = %54, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  %60 = load i32, ptr %10, align 4
  switch i32 %60, label %62 [
    i32 5, label %61
  ]

61:                                               ; preds = %59
  store i1 true, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %62

62:                                               ; preds = %61, %59
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 1024, ptr %6) #4
  br label %63

63:                                               ; preds = %62, %14
  %64 = load i1, ptr %3, align 1
  ret i1 %64
}

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

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

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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 nounwind uwtable
define dso_local noundef zeroext i1 @_Z9isAnagramNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_(ptr noundef nonnull %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca [256 x i32], align 16
  %4 = tail call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #3
  %5 = tail call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv(ptr noundef nonnull align 8 dereferenceable(32) %1) #3
  %.not = icmp eq i64 %4, %5
  br i1 %.not, label %6, label %34

6:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %3) #3
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1024) %3, i8 0, i64 1024, i1 false)
  %7 = tail call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #3
  %8 = trunc i64 %7 to i32
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph.preheader, label %.preheader

.lr.ph.preheader:                                 ; preds = %6
  %wide.trip.count = and i64 %7, 2147483647
  br label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %6
  %10 = load i32, ptr %3, align 16, !tbaa !5
  %.not1219 = icmp eq i32 %10, 0
  br i1 %.not1219, label %.lr.ph21, label %.critedge

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %11 = 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)
  %12 = load i8, ptr %11, align 1, !tbaa !9
  %13 = sext i8 %12 to i64
  %14 = getelementptr inbounds [256 x i32], ptr %3, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %14, align 4, !tbaa !5
  %17 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %1, i64 noundef %indvars.iv)
  %18 = load i8, ptr %17, align 1, !tbaa !9
  %19 = sext i8 %18 to i64
  %20 = getelementptr inbounds [256 x i32], ptr %3, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = add nsw i32 %21, -1
  store i32 %22, ptr %20, align 4, !tbaa !5
  %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 %.preheader, label %.lr.ph, !llvm.loop !10

.lr.ph21:                                         ; preds = %.preheader, %29
  %indvars.iv1620 = phi i64 [ %indvars.iv.next17.3, %29 ], [ 0, %.preheader ]
  %indvars.iv.next17 = or disjoint i64 %indvars.iv1620, 1
  %23 = getelementptr inbounds [256 x i32], ptr %3, i64 0, i64 %indvars.iv.next17
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %.not12 = icmp eq i32 %24, 0
  br i1 %.not12, label %.lr.ph21.1, label %.critedge, !llvm.loop !12

.lr.ph21.1:                                       ; preds = %.lr.ph21
  %indvars.iv.next17.1 = or disjoint i64 %indvars.iv1620, 2
  %25 = getelementptr inbounds [256 x i32], ptr %3, i64 0, i64 %indvars.iv.next17.1
  %26 = load i32, ptr %25, align 8, !tbaa !5
  %.not12.1 = icmp eq i32 %26, 0
  br i1 %.not12.1, label %.lr.ph21.2, label %.critedge, !llvm.loop !12

.lr.ph21.2:                                       ; preds = %.lr.ph21.1
  %indvars.iv.next17.2 = or disjoint i64 %indvars.iv1620, 3
  %27 = getelementptr inbounds [256 x i32], ptr %3, i64 0, i64 %indvars.iv.next17.2
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %.not12.2 = icmp eq i32 %28, 0
  br i1 %.not12.2, label %.lr.ph21.3, label %.critedge, !llvm.loop !12

.lr.ph21.3:                                       ; preds = %.lr.ph21.2
  %indvars.iv.next17.3 = add nuw nsw i64 %indvars.iv1620, 4
  %exitcond18.3 = icmp eq i64 %indvars.iv.next17.3, 256
  br i1 %exitcond18.3, label %.critedge.loopexit.split.loop.exit25, label %29, !llvm.loop !12

29:                                               ; preds = %.lr.ph21.3
  %30 = getelementptr inbounds [256 x i32], ptr %3, i64 0, i64 %indvars.iv.next17.3
  %31 = load i32, ptr %30, align 16, !tbaa !5
  %.not12.3 = icmp eq i32 %31, 0
  br i1 %.not12.3, label %.lr.ph21, label %.critedge.loopexit.split.loop.exit, !llvm.loop !12

.critedge.loopexit.split.loop.exit:               ; preds = %29
  %32 = icmp ugt i64 %indvars.iv.next17.2, 254
  br label %.critedge

.critedge.loopexit.split.loop.exit25:             ; preds = %.lr.ph21.3
  %33 = icmp ugt i64 %indvars.iv.next17.2, 254
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit.split.loop.exit, %.critedge.loopexit.split.loop.exit25, %.lr.ph21.2, %.lr.ph21.1, %.lr.ph21, %.preheader
  %.lcssa = phi i1 [ false, %.preheader ], [ %32, %.critedge.loopexit.split.loop.exit ], [ %33, %.critedge.loopexit.split.loop.exit25 ], [ false, %.lr.ph21.2 ], [ false, %.lr.ph21.1 ], [ false, %.lr.ph21 ]
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %3) #3
  br label %34

34:                                               ; preds = %2, %.critedge
  %.2 = phi i1 [ %.lcssa, %.critedge ], [ false, %2 ]
  ret i1 %.2
}

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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