; LLVM IR from priyankchheda/algorithms :: _other_languages/cpp/LinkedList (countFrequency)

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

%"struct.LinkedList::Node" = type { i8, ptr }

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z23countFrequencyRecursionPN10LinkedList4NodeIcEEc(ptr noundef %0, i8 noundef signext %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %2
  store i32 0, ptr %3, align 4
  br label %30

9:                                                ; preds = %2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %"struct.LinkedList::Node", ptr %10, i32 0, i32 0
  %12 = load i8, ptr %11, align 8, !tbaa !10
  %13 = sext i8 %12 to i32
  %14 = load i8, ptr %5, align 1, !tbaa !9
  %15 = sext i8 %14 to i32
  %16 = icmp eq i32 %13, %15
  br i1 %16, label %17, label %24

17:                                               ; preds = %9
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.LinkedList::Node", ptr %18, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !12
  %21 = load i8, ptr %5, align 1, !tbaa !9
  %22 = call noundef i32 @_Z23countFrequencyRecursionPN10LinkedList4NodeIcEEc(ptr noundef %20, i8 noundef signext %21)
  %23 = add nsw i32 1, %22
  store i32 %23, ptr %3, align 4
  br label %30

24:                                               ; preds = %9
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %"struct.LinkedList::Node", ptr %25, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !12
  %28 = load i8, ptr %5, align 1, !tbaa !9
  %29 = call noundef i32 @_Z23countFrequencyRecursionPN10LinkedList4NodeIcEEc(ptr noundef %27, i8 noundef signext %28)
  store i32 %29, ptr %3, align 4
  br label %30

30:                                               ; preds = %24, %17, %8
  %31 = load i32, ptr %3, align 4
  ret i32 %31
}

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

!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 = !{!7, !7, i64 0}
!10 = !{!11, !7, i64 0}
!11 = !{!"_ZTSN10LinkedList4NodeIcEE", !7, i64 0, !6, i64 8}
!12 = !{!11, !6, i64 8}


; 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 willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_Z23countFrequencyRecursionPN10LinkedList4NodeIcEEc(ptr noundef readonly %0, i8 noundef signext %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %tailrecurse.outer._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %tailrecurse.outer
  %.tr.ph13 = phi ptr [ %8, %tailrecurse.outer ], [ %0, %2 ]
  %accumulator.tr.ph12 = phi i32 [ %9, %tailrecurse.outer ], [ 0, %2 ]
  br label %4

4:                                                ; preds = %.lr.ph, %tailrecurse
  %.tr10 = phi ptr [ %.tr.ph13, %.lr.ph ], [ %8, %tailrecurse ]
  %5 = load i8, ptr %.tr10, align 8, !tbaa !5
  %6 = icmp eq i8 %5, %1
  %7 = getelementptr inbounds i8, ptr %.tr10, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !10
  br i1 %6, label %tailrecurse.outer, label %tailrecurse

tailrecurse.outer:                                ; preds = %4
  %9 = add nuw nsw i32 %accumulator.tr.ph12, 1
  %10 = icmp eq ptr %8, null
  br i1 %10, label %tailrecurse.outer._crit_edge, label %.lr.ph

tailrecurse:                                      ; preds = %4
  %11 = icmp eq ptr %8, null
  br i1 %11, label %tailrecurse.outer._crit_edge, label %4

tailrecurse.outer._crit_edge:                     ; preds = %tailrecurse.outer, %tailrecurse, %2
  %accumulator.tr.ph.lcssa = phi i32 [ 0, %2 ], [ %accumulator.tr.ph12, %tailrecurse ], [ %9, %tailrecurse.outer ]
  ret i32 %accumulator.tr.ph.lcssa
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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, !7, i64 0}
!6 = !{!"_ZTSN10LinkedList4NodeIcEE", !7, i64 0, !9, i64 8}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"any pointer", !7, i64 0}
!10 = !{!6, !9, i64 8}


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