; LLVM IR from begeekmyfriend/leetcode :: 0146_lru_cache (lru_cache)

; 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.LRUCache = type { i32, i32, %struct.list_head, [0 x %struct.list_head] }
%struct.list_head = type { ptr, ptr }
%struct.LRUNode = type { i32, i32, %struct.list_head, %struct.list_head }

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @lRUCacheGet(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.LRUCache, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = srem i32 %9, %12
  store i32 %13, ptr %7, align 4, !tbaa !9
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.LRUCache, ptr %14, i32 0, i32 3
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [0 x %struct.list_head], ptr %15, i64 0, i64 %17
  %19 = getelementptr inbounds %struct.list_head, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = getelementptr inbounds i8, ptr %20, i64 sub (i64 0, i64 ptrtoint (ptr getelementptr inbounds (%struct.LRUNode, ptr null, i32 0, i32 2) to i64))
  store ptr %21, ptr %6, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %46, %2
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.LRUNode, ptr %23, i32 0, i32 2
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.LRUCache, ptr %25, i32 0, i32 3
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [0 x %struct.list_head], ptr %26, i64 0, i64 %28
  %30 = icmp ne ptr %24, %29
  br i1 %30, label %31, label %52

31:                                               ; preds = %22
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.LRUNode, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !13
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = icmp eq i32 %34, %35
  br i1 %36, label %37, label %45

37:                                               ; preds = %31
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.LRUNode, ptr %38, i32 0, i32 3
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.LRUCache, ptr %40, i32 0, i32 2
  call void @list_move(ptr noundef %39, ptr noundef %41)
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.LRUNode, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %43, align 4, !tbaa !15
  store i32 %44, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %53

45:                                               ; preds = %31
  br label %46

46:                                               ; preds = %45
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.LRUNode, ptr %47, i32 0, i32 2
  %49 = getelementptr inbounds %struct.list_head, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !16
  %51 = getelementptr inbounds i8, ptr %50, i64 sub (i64 0, i64 ptrtoint (ptr getelementptr inbounds (%struct.LRUNode, ptr null, i32 0, i32 2) to i64))
  store ptr %51, ptr %6, align 8, !tbaa !5
  br label %22, !llvm.loop !17

52:                                               ; preds = %22
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %53

53:                                               ; preds = %52, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %54 = load i32, ptr %3, align 4
  ret i32 %54
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @list_move(ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { inlinehint 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"list_head", !6, i64 0, !6, i64 8}
!13 = !{!14, !10, i64 0}
!14 = !{!"", !10, i64 0, !10, i64 4, !12, i64 8, !12, i64 24}
!15 = !{!14, !10, i64 4}
!16 = !{!14, !6, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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

%struct.list_head = type { ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local i32 @lRUCacheGet(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr %0, align 8, !tbaa !5
  %4 = srem i32 %1, %3
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = sext i32 %4 to i64
  %7 = getelementptr inbounds [0 x %struct.list_head], ptr %5, i64 0, i64 %6
  br label %8

8:                                                ; preds = %9, %2
  %.pn.in = phi ptr [ %7, %2 ], [ %.pn, %9 ]
  %.pn = load ptr, ptr %.pn.in, align 8, !tbaa !9
  %.not = icmp eq ptr %.pn, %7
  br i1 %.not, label %.loopexit, label %9

9:                                                ; preds = %8
  %.013 = getelementptr inbounds i8, ptr %.pn, i64 -8
  %10 = load i32, ptr %.013, align 8, !tbaa !12
  %11 = icmp eq i32 %10, %1
  br i1 %11, label %12, label %8, !llvm.loop !14

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %.pn, i64 16
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @list_move(ptr noundef nonnull %13, ptr noundef nonnull %14)
  %15 = getelementptr inbounds i8, ptr %.pn, i64 -4
  %16 = load i32, ptr %15, align 4, !tbaa !16
  br label %.loopexit

.loopexit:                                        ; preds = %8, %12
  %.0 = phi i32 [ %16, %12 ], [ -1, %8 ]
  ret i32 %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @list_move(ptr noundef, 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 = { inlinehint 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" }

!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/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"list_head", !11, i64 0, !11, i64 8}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"", !6, i64 0, !6, i64 4, !10, i64 8, !10, i64 24}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!13, !6, i64 4}


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