; LLVM IR from JessonYue/LeetCodeLearning :: Array/caiweixiong/c (homework_035)

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

; 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 ptr @findSuitableNode(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = 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
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.LRUCache_3, ptr %13, i32 0, i32 3
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  store ptr %15, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store ptr null, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  store ptr null, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.LRUCache_3, ptr %16, i32 0, i32 4
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  %19 = getelementptr inbounds %struct.kvnode_3, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !14
  store i32 %20, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %21 = load i32, ptr %10, align 4, !tbaa !9
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.LRUCache_3, ptr %22, i32 0, i32 2
  %24 = load i32, ptr %23, align 8, !tbaa !16
  %25 = sub nsw i32 %24, 1
  %26 = and i32 %21, %25
  store i32 %26, ptr %11, align 4, !tbaa !9
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = load i32, ptr %11, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds ptr, ptr %27, i64 %29
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  store ptr %31, ptr %8, align 8, !tbaa !5
  store ptr %31, ptr %7, align 8, !tbaa !5
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.kvnode_3, ptr %32, i32 0, i32 4
  %34 = load ptr, ptr %33, align 8, !tbaa !17
  store ptr %34, ptr %9, align 8, !tbaa !5
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.kvnode_3, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 8, !tbaa !14
  %38 = load i32, ptr %10, align 4, !tbaa !9
  %39 = icmp eq i32 %37, %38
  br i1 %39, label %40, label %52

40:                                               ; preds = %2
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load i32, ptr %11, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds ptr, ptr %42, i64 %44
  store ptr %41, ptr %45, align 8, !tbaa !5
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.kvnode_3, ptr %46, i32 0, i32 4
  store ptr null, ptr %47, align 8, !tbaa !17
  %48 = load i32, ptr %5, align 4, !tbaa !9
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.kvnode_3, ptr %49, i32 0, i32 0
  store i32 %48, ptr %50, align 8, !tbaa !14
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %51, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %88

52:                                               ; preds = %2
  br label %53

53:                                               ; preds = %76, %52
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.kvnode_3, ptr %54, i32 0, i32 4
  %56 = load ptr, ptr %55, align 8, !tbaa !17
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %81

58:                                               ; preds = %53
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.kvnode_3, ptr %59, i32 0, i32 0
  %61 = load i32, ptr %60, align 8, !tbaa !14
  %62 = load i32, ptr %10, align 4, !tbaa !9
  %63 = icmp eq i32 %61, %62
  br i1 %63, label %64, label %76

64:                                               ; preds = %58
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.kvnode_3, ptr %65, i32 0, i32 4
  %67 = load ptr, ptr %66, align 8, !tbaa !17
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.kvnode_3, ptr %68, i32 0, i32 4
  store ptr %67, ptr %69, align 8, !tbaa !17
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.kvnode_3, ptr %70, i32 0, i32 4
  store ptr null, ptr %71, align 8, !tbaa !17
  %72 = load i32, ptr %5, align 4, !tbaa !9
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.kvnode_3, ptr %73, i32 0, i32 0
  store i32 %72, ptr %74, align 8, !tbaa !14
  %75 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %75, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %88

76:                                               ; preds = %58
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %77, ptr %8, align 8, !tbaa !5
  %78 = load ptr, ptr %9, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.kvnode_3, ptr %78, i32 0, i32 4
  %80 = load ptr, ptr %79, align 8, !tbaa !17
  store ptr %80, ptr %9, align 8, !tbaa !5
  br label %53, !llvm.loop !18

81:                                               ; preds = %53
  %82 = load ptr, ptr %8, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.kvnode_3, ptr %82, i32 0, i32 4
  store ptr null, ptr %83, align 8, !tbaa !17
  %84 = load i32, ptr %5, align 4, !tbaa !9
  %85 = load ptr, ptr %9, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.kvnode_3, ptr %85, i32 0, i32 0
  store i32 %84, ptr %86, align 8, !tbaa !14
  %87 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %87, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %88

88:                                               ; preds = %81, %64, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %89 = load ptr, ptr %3, align 8
  ret ptr %89
}

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 = { 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 16}
!12 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!13 = !{!12, !6, i64 24}
!14 = !{!15, !10, i64 0}
!15 = !{!"kvnode_3", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16, !6, i64 24}
!16 = !{!12, !10, i64 8}
!17 = !{!15, !6, i64 24}
!18 = distinct !{!18, !19}
!19 = !{!"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"

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef ptr @findSuitableNode(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load ptr, ptr %5, align 8, !tbaa !11
  %7 = load i32, ptr %6, align 8, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i32, ptr %8, align 8, !tbaa !14
  %10 = add nsw i32 %9, -1
  %11 = and i32 %10, %7
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds ptr, ptr %4, i64 %12
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  %15 = getelementptr inbounds i8, ptr %14, i64 24
  %16 = load ptr, ptr %15, align 8, !tbaa !16
  %17 = load i32, ptr %14, align 8, !tbaa !12
  %18 = icmp eq i32 %17, %7
  br i1 %18, label %19, label %.preheader

19:                                               ; preds = %2
  store ptr %16, ptr %13, align 8, !tbaa !15
  br label %30

.preheader:                                       ; preds = %2, %22
  %.032 = phi ptr [ %.031, %22 ], [ %14, %2 ]
  %.031 = phi ptr [ %21, %22 ], [ %16, %2 ]
  %20 = getelementptr inbounds i8, ptr %.031, i64 24
  %21 = load ptr, ptr %20, align 8, !tbaa !16
  %.not = icmp eq ptr %21, null
  br i1 %.not, label %28, label %22

22:                                               ; preds = %.preheader
  %23 = load i32, ptr %.031, align 8, !tbaa !12
  %24 = icmp eq i32 %23, %7
  br i1 %24, label %25, label %.preheader, !llvm.loop !17

25:                                               ; preds = %22
  %26 = getelementptr inbounds i8, ptr %.031, i64 24
  %27 = getelementptr inbounds i8, ptr %.032, i64 24
  store ptr %21, ptr %27, align 8, !tbaa !16
  br label %30

28:                                               ; preds = %.preheader
  %29 = getelementptr inbounds i8, ptr %.032, i64 24
  br label %30

30:                                               ; preds = %28, %25, %19
  %.sink = phi ptr [ %29, %28 ], [ %26, %25 ], [ %15, %19 ]
  %.031.lcssa.sink = phi ptr [ %.031, %28 ], [ %.031, %25 ], [ %14, %19 ]
  store ptr null, ptr %.sink, align 8, !tbaa !16
  store i32 %1, ptr %.031.lcssa.sink, align 8, !tbaa !12
  ret ptr %.031.lcssa.sink
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, 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, !10, i64 16}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 24}
!12 = !{!13, !7, i64 0}
!13 = !{!"kvnode_3", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !10, i64 24}
!14 = !{!6, !7, i64 8}
!15 = !{!10, !10, i64 0}
!16 = !{!13, !10, i64 24}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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