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

@.str = external hidden unnamed_addr constant [22 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [9 x i8], align 1

; 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 void @lRUCacheDump(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %8

7:                                                ; preds = %1
  br label %92

8:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.LRUCache, ptr %9, i32 0, i32 1
  %11 = load i32, ptr %10, align 4, !tbaa !9
  %12 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %11)
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %61, %8
  %14 = load i32, ptr %3, align 4, !tbaa !9
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.LRUCache, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = icmp slt i32 %14, %17
  br i1 %18, label %19, label %64

19:                                               ; preds = %13
  %20 = load i32, ptr %3, align 4, !tbaa !9
  %21 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %20)
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.LRUCache, ptr %22, i32 0, i32 3
  %24 = load i32, ptr %3, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [0 x %struct.list_head], ptr %23, i64 0, i64 %25
  %27 = getelementptr inbounds %struct.list_head, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = getelementptr inbounds i8, ptr %28, i64 sub (i64 0, i64 ptrtoint (ptr getelementptr inbounds (%struct.LRUNode, ptr null, i32 0, i32 2) to i64))
  store ptr %29, ptr %4, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %53, %19
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.LRUNode, ptr %31, i32 0, i32 2
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.LRUCache, ptr %33, i32 0, i32 3
  %35 = load i32, ptr %3, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [0 x %struct.list_head], ptr %34, i64 0, i64 %36
  %38 = icmp ne ptr %32, %37
  br i1 %38, label %39, label %59

39:                                               ; preds = %30
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %40, i64 sub (i64 0, i64 ptrtoint (ptr getelementptr inbounds (%struct.LRUNode, ptr null, i32 0, i32 2) to i64))
  store ptr %41, ptr %4, align 8, !tbaa !5
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %52

44:                                               ; preds = %39
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.LRUNode, ptr %45, i32 0, i32 0
  %47 = load i32, ptr %46, align 8, !tbaa !13
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.LRUNode, ptr %48, i32 0, i32 1
  %50 = load i32, ptr %49, align 4, !tbaa !15
  %51 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %47, i32 noundef %50)
  br label %52

52:                                               ; preds = %44, %39
  br label %53

53:                                               ; preds = %52
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.LRUNode, ptr %54, i32 0, i32 2
  %56 = getelementptr inbounds %struct.list_head, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !16
  %58 = getelementptr inbounds i8, ptr %57, i64 sub (i64 0, i64 ptrtoint (ptr getelementptr inbounds (%struct.LRUNode, ptr null, i32 0, i32 2) to i64))
  store ptr %58, ptr %4, align 8, !tbaa !5
  br label %30, !llvm.loop !17

59:                                               ; preds = %30
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %61

61:                                               ; preds = %59
  %62 = load i32, ptr %3, align 4, !tbaa !9
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %3, align 4, !tbaa !9
  br label %13, !llvm.loop !19

64:                                               ; preds = %13
  %65 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.LRUCache, ptr %66, i32 0, i32 2
  %68 = getelementptr inbounds %struct.list_head, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !11
  %70 = getelementptr inbounds i8, ptr %69, i64 sub (i64 0, i64 ptrtoint (ptr getelementptr inbounds (%struct.LRUNode, ptr null, i32 0, i32 3) to i64))
  store ptr %70, ptr %4, align 8, !tbaa !5
  br label %71

71:                                               ; preds = %85, %64
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.LRUNode, ptr %72, i32 0, i32 3
  %74 = load ptr, ptr %2, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.LRUCache, ptr %74, i32 0, i32 2
  %76 = icmp ne ptr %73, %75
  br i1 %76, label %77, label %91

77:                                               ; preds = %71
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.LRUNode, ptr %78, i32 0, i32 0
  %80 = load i32, ptr %79, align 8, !tbaa !13
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.LRUNode, ptr %81, i32 0, i32 1
  %83 = load i32, ptr %82, align 4, !tbaa !15
  %84 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %80, i32 noundef %83)
  br label %85

85:                                               ; preds = %77
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.LRUNode, ptr %86, i32 0, i32 3
  %88 = getelementptr inbounds %struct.list_head, ptr %87, i32 0, i32 0
  %89 = load ptr, ptr %88, align 8, !tbaa !20
  %90 = getelementptr inbounds i8, ptr %89, i64 sub (i64 0, i64 ptrtoint (ptr getelementptr inbounds (%struct.LRUNode, ptr null, i32 0, i32 3) to i64))
  store ptr %90, ptr %4, align 8, !tbaa !5
  br label %71, !llvm.loop !21

91:                                               ; preds = %71
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %92

92:                                               ; preds = %91, %7
  ret void
}

declare i32 @printf(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 = { "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"}
!19 = distinct !{!19, !18}
!20 = !{!14, !6, i64 24}
!21 = distinct !{!21, !18}


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

@.str = external hidden unnamed_addr constant [22 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local void @lRUCacheDump(ptr noundef readonly %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %.loopexit, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %5)
  %7 = load i32, ptr %4, align 4, !tbaa !5
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph31, label %._crit_edge32

.lr.ph31:                                         ; preds = %3
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  br label %10

10:                                               ; preds = %.lr.ph31, %._crit_edge
  %indvars.iv = phi i64 [ 0, %.lr.ph31 ], [ %indvars.iv.next, %._crit_edge ]
  %11 = trunc nuw nsw i64 %indvars.iv to i32
  %12 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %11)
  %13 = getelementptr inbounds [0 x %struct.list_head], ptr %9, i64 0, i64 %indvars.iv
  %.pn2426 = load ptr, ptr %13, align 8, !tbaa !9
  %.not2527 = icmp eq ptr %.pn2426, %13
  br i1 %.not2527, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %10, %.lr.ph
  %.pn2428 = phi ptr [ %.pn24, %.lr.ph ], [ %.pn2426, %10 ]
  %14 = getelementptr inbounds i8, ptr %.pn2428, i64 -16
  %15 = load i32, ptr %14, align 8, !tbaa !12
  %16 = getelementptr inbounds i8, ptr %.pn2428, i64 -12
  %17 = load i32, ptr %16, align 4, !tbaa !14
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %15, i32 noundef %17)
  %19 = getelementptr inbounds i8, ptr %.pn2428, i64 -8
  %.pn24 = load ptr, ptr %19, align 8, !tbaa !9
  %.not25 = icmp eq ptr %.pn24, %13
  br i1 %.not25, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph, %10
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = icmp slt i64 %indvars.iv.next, %22
  br i1 %23, label %10, label %._crit_edge32, !llvm.loop !17

._crit_edge32:                                    ; preds = %._crit_edge, %3
  %24 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %25 = getelementptr inbounds i8, ptr %0, i64 8
  %.pn33 = load ptr, ptr %25, align 8, !tbaa !9
  %.not34 = icmp eq ptr %.pn33, %25
  br i1 %.not34, label %.loopexit, label %.lr.ph37

.lr.ph37:                                         ; preds = %._crit_edge32, %.lr.ph37
  %.pn35 = phi ptr [ %.pn, %.lr.ph37 ], [ %.pn33, %._crit_edge32 ]
  %.1 = getelementptr inbounds i8, ptr %.pn35, i64 -24
  %26 = load i32, ptr %.1, align 8, !tbaa !12
  %27 = getelementptr inbounds i8, ptr %.pn35, i64 -20
  %28 = load i32, ptr %27, align 4, !tbaa !14
  %29 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %26, i32 noundef %28)
  %.pn = load ptr, ptr %.pn35, align 8, !tbaa !9
  %.not = icmp eq ptr %.pn, %25
  br i1 %.not, label %.loopexit, label %.lr.ph37, !llvm.loop !18

.loopexit:                                        ; preds = %.lr.ph37, %._crit_edge32, %1
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

attributes #0 = { nofree 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 = { nofree nounwind "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 = !{!13, !6, i64 4}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !16}


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