; LLVM IR from DimitrisJim/leetcode_solutions :: C/Algorithms (933)

; 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.RecentCounter = type { i32, ptr }

; Function Attrs: nounwind uwtable
define dso_local i32 @recentCounterPing(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.RecentCounter, ptr %6, i32 0, i32 1
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %9 = call i32 @length(ptr noundef %8)
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %18, label %11

11:                                               ; preds = %2
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.RecentCounter, ptr %13, i32 0, i32 0
  %15 = load i32, ptr %14, align 8, !tbaa !13
  %16 = sub nsw i32 %12, %15
  %17 = icmp sgt i32 %16, 3000
  br i1 %17, label %18, label %26

18:                                               ; preds = %11, %2
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.RecentCounter, ptr %19, i32 0, i32 1
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  %22 = load i32, ptr %5, align 4, !tbaa !9
  call void @push_back(ptr noundef %21, i32 noundef %22)
  %23 = load i32, ptr %5, align 4, !tbaa !9
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.RecentCounter, ptr %24, i32 0, i32 0
  store i32 %23, ptr %25, align 8, !tbaa !13
  store i32 1, ptr %3, align 4
  br label %53

26:                                               ; preds = %11
  br label %27

27:                                               ; preds = %43, %26
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.RecentCounter, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !11
  %32 = call i32 @front(ptr noundef %31)
  %33 = sub nsw i32 %28, %32
  %34 = icmp sle i32 %33, 3000
  br i1 %34, label %35, label %43

35:                                               ; preds = %27
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.RecentCounter, ptr %36, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = load i32, ptr %5, align 4, !tbaa !9
  call void @push_back(ptr noundef %38, i32 noundef %39)
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.RecentCounter, ptr %41, i32 0, i32 0
  store i32 %40, ptr %42, align 8, !tbaa !13
  br label %48

43:                                               ; preds = %27
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.RecentCounter, ptr %44, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !11
  %47 = call i32 @pop_front(ptr noundef %46)
  br label %27

48:                                               ; preds = %35
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.RecentCounter, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !11
  %52 = call i32 @length(ptr noundef %51)
  store i32 %52, ptr %3, align 4
  br label %53

53:                                               ; preds = %48, %18
  %54 = load i32, ptr %3, align 4
  ret i32 %54
}

declare i32 @length(ptr noundef) #1

declare void @push_back(ptr noundef, i32 noundef) #1

declare i32 @front(ptr noundef) #1

declare i32 @pop_front(ptr noundef) #1

attributes #0 = { 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 = { "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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"", !10, i64 0, !6, i64 8}
!13 = !{!12, !10, i64 0}


; 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: nounwind uwtable
define dso_local i32 @recentCounterPing(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = tail call i32 @length(ptr noundef %4) #2
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %15, label %7

7:                                                ; preds = %2
  %8 = load i32, ptr %0, align 8, !tbaa !11
  %9 = sub nsw i32 %1, %8
  %10 = icmp sgt i32 %9, 3000
  br i1 %10, label %15, label %.preheader

.preheader:                                       ; preds = %7
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = tail call i32 @front(ptr noundef %11) #2
  %13 = sub nsw i32 %1, %12
  %14 = icmp slt i32 %13, 3001
  br i1 %14, label %._crit_edge, label %.lr.ph

15:                                               ; preds = %7, %2
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  tail call void @push_back(ptr noundef %16, i32 noundef %1) #2
  store i32 %1, ptr %0, align 8, !tbaa !11
  br label %26

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  tail call void @push_back(ptr noundef %17, i32 noundef %1) #2
  store i32 %1, ptr %0, align 8, !tbaa !11
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = tail call i32 @length(ptr noundef %18) #2
  br label %26

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = tail call i32 @pop_front(ptr noundef %20) #2
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = tail call i32 @front(ptr noundef %22) #2
  %24 = sub nsw i32 %1, %23
  %25 = icmp slt i32 %24, 3001
  br i1 %25, label %._crit_edge, label %.lr.ph

26:                                               ; preds = %._crit_edge, %15
  %.0 = phi i32 [ 1, %15 ], [ %19, %._crit_edge ]
  ret i32 %.0
}

declare i32 @length(ptr noundef) local_unnamed_addr #1

declare void @push_back(ptr noundef, i32 noundef) local_unnamed_addr #1

declare i32 @front(ptr noundef) local_unnamed_addr #1

declare i32 @pop_front(ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 = { "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 = { 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, !10, i64 8}
!6 = !{!"", !7, i64 0, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}


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