; LLVM IR from JessonYue/LeetCodeLearning :: Array/zhangjunwei/7.26-8.1/lru_cache.ll (Z11lRUCacheGetP8LRUCachei)

; 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, ptr, ptr, ptr }
%struct.hash = type { ptr, ptr }
%struct.node = type { i32, i32, ptr, ptr }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z7HashMapP4hashii(ptr noundef, i32 noundef, i32 noundef) #0

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z13HeadInsertionP4nodeS0_(ptr noundef, ptr noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z11lRUCacheGetP8LRUCachei(ptr noundef %0, i32 noundef %1) #0 {
  %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
  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) #2
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.LRUCache, ptr %8, i32 0, i32 2
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.LRUCache, ptr %12, i32 0, i32 1
  %14 = load i32, ptr %13, align 4, !tbaa !13
  %15 = call noundef ptr @_Z7HashMapP4hashii(ptr noundef %10, i32 noundef %11, i32 noundef %14)
  store ptr %15, ptr %6, align 8, !tbaa !5
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.hash, ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  store ptr %18, ptr %6, align 8, !tbaa !5
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %2
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %63

22:                                               ; preds = %2
  br label %23

23:                                               ; preds = %38, %22
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.hash, ptr %24, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %36

28:                                               ; preds = %23
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.hash, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !16
  %32 = getelementptr inbounds %struct.node, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !17
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = icmp ne i32 %33, %34
  br label %36

36:                                               ; preds = %28, %23
  %37 = phi i1 [ false, %23 ], [ %35, %28 ]
  br i1 %37, label %38, label %42

38:                                               ; preds = %36
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.hash, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !14
  store ptr %41, ptr %6, align 8, !tbaa !5
  br label %23, !llvm.loop !19

42:                                               ; preds = %36
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.hash, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !16
  %46 = getelementptr inbounds %struct.node, ptr %45, i32 0, i32 0
  %47 = load i32, ptr %46, align 8, !tbaa !17
  %48 = load i32, ptr %5, align 4, !tbaa !9
  %49 = icmp eq i32 %47, %48
  br i1 %49, label %50, label %62

50:                                               ; preds = %42
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.LRUCache, ptr %51, i32 0, i32 3
  %53 = load ptr, ptr %52, align 8, !tbaa !21
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.hash, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !16
  call void @_Z13HeadInsertionP4nodeS0_(ptr noundef %53, ptr noundef %56)
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.hash, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !16
  %60 = getelementptr inbounds %struct.node, ptr %59, i32 0, i32 1
  %61 = load i32, ptr %60, align 4, !tbaa !22
  store i32 %61, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %63

62:                                               ; preds = %42
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %63

63:                                               ; preds = %62, %50, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %64 = load i32, ptr %3, align 4
  ret i32 %64
}

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 = !{!12, !6, i64 8}
!12 = !{!"_ZTS8LRUCache", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16, !6, i64 24}
!13 = !{!12, !10, i64 4}
!14 = !{!15, !6, i64 8}
!15 = !{!"_ZTS4hash", !6, i64 0, !6, i64 8}
!16 = !{!15, !6, i64 0}
!17 = !{!18, !10, i64 0}
!18 = !{!"_ZTS4node", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!12, !6, i64 16}
!22 = !{!18, !10, i64 4}


; 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 dso_local noundef ptr @_Z7HashMapP4hashii(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z13HeadInsertionP4nodeS0_(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z11lRUCacheGetP8LRUCachei(ptr nocapture noundef readonly %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 = getelementptr inbounds i8, ptr %0, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !11
  %7 = tail call noundef ptr @_Z7HashMapP4hashii(ptr noundef %4, i32 noundef %1, i32 noundef %6)
  %8 = getelementptr inbounds i8, ptr %7, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %10 = icmp eq ptr %9, null
  br i1 %10, label %20, label %.preheader

.preheader:                                       ; preds = %2, %.preheader
  %.0 = phi ptr [ %12, %.preheader ], [ %9, %2 ]
  %11 = getelementptr inbounds i8, ptr %.0, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !12
  %.not = icmp eq ptr %12, null
  %.pre = load ptr, ptr %.0, align 8, !tbaa !14
  %.pre18 = load i32, ptr %.pre, align 8, !tbaa !15
  %.not17 = icmp eq i32 %.pre18, %1
  %or.cond = select i1 %.not, i1 true, i1 %.not17
  br i1 %or.cond, label %.critedge, label %.preheader, !llvm.loop !17

.critedge:                                        ; preds = %.preheader
  %13 = icmp eq i32 %.pre18, %1
  br i1 %13, label %14, label %20

14:                                               ; preds = %.critedge
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  %16 = load ptr, ptr %15, align 8, !tbaa !19
  tail call void @_Z13HeadInsertionP4nodeS0_(ptr noundef %16, ptr noundef nonnull %.pre)
  %17 = load ptr, ptr %.0, align 8, !tbaa !14
  %18 = getelementptr inbounds i8, ptr %17, i64 4
  %19 = load i32, ptr %18, align 4, !tbaa !20
  br label %20

20:                                               ; preds = %.critedge, %2, %14
  %.014 = phi i32 [ %19, %14 ], [ -1, %2 ], [ -1, %.critedge ]
  ret i32 %.014
}

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

!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 = !{!"_ZTS8LRUCache", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!13, !10, i64 8}
!13 = !{!"_ZTS4hash", !10, i64 0, !10, i64 8}
!14 = !{!13, !10, i64 0}
!15 = !{!16, !7, i64 0}
!16 = !{!"_ZTS4node", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!6, !10, i64 16}
!20 = !{!16, !7, i64 4}


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