; LLVM IR from int32bit/leetcode :: algorithms/LRUCache (solve)

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

@lru = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local ptr @find(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: nounwind uwtable
define dso_local ptr @fetch(i32 noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = call ptr @find(i32 noundef %6)
  store ptr %7, ptr %4, align 8, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !9
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %11

10:                                               ; preds = %1
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %82

11:                                               ; preds = %1
  %12 = load ptr, ptr @lru, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.anon, ptr %12, i32 0, i32 2
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = load ptr, ptr %4, align 8, !tbaa !9
  %16 = icmp eq ptr %14, %15
  br i1 %16, label %17, label %19

17:                                               ; preds = %11
  %18 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %18, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %82

19:                                               ; preds = %11
  %20 = load ptr, ptr @lru, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.anon, ptr %20, i32 0, i32 3
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  %23 = load ptr, ptr %4, align 8, !tbaa !9
  %24 = icmp eq ptr %22, %23
  br i1 %24, label %25, label %51

25:                                               ; preds = %19
  %26 = load ptr, ptr %4, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.node, ptr %26, i32 0, i32 3
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = getelementptr inbounds %struct.node, ptr %28, i32 0, i32 2
  store ptr null, ptr %29, align 8, !tbaa !16
  %30 = load ptr, ptr %4, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.node, ptr %30, i32 0, i32 3
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  %33 = load ptr, ptr @lru, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.anon, ptr %33, i32 0, i32 3
  store ptr %32, ptr %34, align 8, !tbaa !13
  %35 = load ptr, ptr %4, align 8, !tbaa !9
  %36 = load ptr, ptr @lru, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.anon, ptr %36, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = getelementptr inbounds %struct.node, ptr %38, i32 0, i32 3
  store ptr %35, ptr %39, align 8, !tbaa !14
  %40 = load ptr, ptr @lru, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.anon, ptr %40, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !11
  %43 = load ptr, ptr %4, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.node, ptr %43, i32 0, i32 2
  store ptr %42, ptr %44, align 8, !tbaa !16
  %45 = load ptr, ptr %4, align 8, !tbaa !9
  %46 = getelementptr inbounds %struct.node, ptr %45, i32 0, i32 3
  store ptr null, ptr %46, align 8, !tbaa !14
  %47 = load ptr, ptr %4, align 8, !tbaa !9
  %48 = load ptr, ptr @lru, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.anon, ptr %48, i32 0, i32 2
  store ptr %47, ptr %49, align 8, !tbaa !11
  %50 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %50, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %82

51:                                               ; preds = %19
  %52 = load ptr, ptr %4, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.node, ptr %52, i32 0, i32 3
  %54 = load ptr, ptr %53, align 8, !tbaa !14
  %55 = load ptr, ptr %4, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.node, ptr %55, i32 0, i32 2
  %57 = load ptr, ptr %56, align 8, !tbaa !16
  %58 = getelementptr inbounds %struct.node, ptr %57, i32 0, i32 3
  store ptr %54, ptr %58, align 8, !tbaa !14
  %59 = load ptr, ptr %4, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct.node, ptr %59, i32 0, i32 2
  %61 = load ptr, ptr %60, align 8, !tbaa !16
  %62 = load ptr, ptr %4, align 8, !tbaa !9
  %63 = getelementptr inbounds %struct.node, ptr %62, i32 0, i32 3
  %64 = load ptr, ptr %63, align 8, !tbaa !14
  %65 = getelementptr inbounds %struct.node, ptr %64, i32 0, i32 2
  store ptr %61, ptr %65, align 8, !tbaa !16
  %66 = load ptr, ptr @lru, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.anon, ptr %66, i32 0, i32 2
  %68 = load ptr, ptr %67, align 8, !tbaa !11
  %69 = load ptr, ptr %4, align 8, !tbaa !9
  %70 = getelementptr inbounds %struct.node, ptr %69, i32 0, i32 2
  store ptr %68, ptr %70, align 8, !tbaa !16
  %71 = load ptr, ptr %4, align 8, !tbaa !9
  %72 = load ptr, ptr @lru, align 8, !tbaa !9
  %73 = getelementptr inbounds %struct.anon, ptr %72, i32 0, i32 2
  %74 = load ptr, ptr %73, align 8, !tbaa !11
  %75 = getelementptr inbounds %struct.node, ptr %74, i32 0, i32 3
  store ptr %71, ptr %75, align 8, !tbaa !14
  %76 = load ptr, ptr %4, align 8, !tbaa !9
  %77 = getelementptr inbounds %struct.node, ptr %76, i32 0, i32 3
  store ptr null, ptr %77, align 8, !tbaa !14
  %78 = load ptr, ptr %4, align 8, !tbaa !9
  %79 = load ptr, ptr @lru, align 8, !tbaa !9
  %80 = getelementptr inbounds %struct.anon, ptr %79, i32 0, i32 2
  store ptr %78, ptr %80, align 8, !tbaa !11
  %81 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %81, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %82

82:                                               ; preds = %51, %25, %17, %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %83 = load ptr, ptr %2, align 8
  ret ptr %83
}

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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"", !6, i64 0, !6, i64 4, !10, i64 8, !10, i64 16}
!13 = !{!12, !10, i64 16}
!14 = !{!15, !10, i64 16}
!15 = !{!"node", !6, i64 0, !6, i64 4, !10, i64 8, !10, i64 16}
!16 = !{!15, !10, i64 8}


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

@lru = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local ptr @find(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @fetch(i32 noundef %0) local_unnamed_addr #0 {
  %2 = tail call ptr @find(i32 noundef %0)
  %3 = icmp eq ptr %2, null
  br i1 %3, label %25, label %4

4:                                                ; preds = %1
  %5 = load ptr, ptr @lru, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = icmp eq ptr %7, %2
  br i1 %8, label %25, label %9

9:                                                ; preds = %4
  %10 = getelementptr inbounds i8, ptr %5, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %12 = icmp eq ptr %11, %2
  %13 = getelementptr inbounds i8, ptr %2, i64 16
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  br i1 %12, label %15, label %19

15:                                               ; preds = %9
  %16 = getelementptr inbounds i8, ptr %14, i64 8
  store ptr null, ptr %16, align 8, !tbaa !15
  store ptr %14, ptr %10, align 8, !tbaa !12
  %17 = getelementptr inbounds i8, ptr %7, i64 16
  store ptr %2, ptr %17, align 8, !tbaa !13
  %18 = getelementptr inbounds i8, ptr %2, i64 8
  store ptr %7, ptr %18, align 8, !tbaa !15
  br label %.sink.split

19:                                               ; preds = %9
  %20 = getelementptr inbounds i8, ptr %2, i64 8
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = getelementptr inbounds i8, ptr %21, i64 16
  store ptr %14, ptr %22, align 8, !tbaa !13
  %23 = getelementptr inbounds i8, ptr %14, i64 8
  store ptr %21, ptr %23, align 8, !tbaa !15
  store ptr %7, ptr %20, align 8, !tbaa !15
  %24 = getelementptr inbounds i8, ptr %7, i64 16
  store ptr %2, ptr %24, align 8, !tbaa !13
  br label %.sink.split

.sink.split:                                      ; preds = %15, %19
  store ptr null, ptr %13, align 8, !tbaa !13
  store ptr %2, ptr %6, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %.sink.split, %4, %1
  ret ptr %2
}

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

!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, !6, i64 8}
!10 = !{!"", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 16}
!13 = !{!14, !6, i64 16}
!14 = !{!"node", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16}
!15 = !{!14, !6, i64 8}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass