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

@lru = external hidden global ptr, align 8

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 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
declare dso_local ptr @fetch(i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @lruCacheSet(i32 noundef %0, i32 noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = call ptr @fetch(i32 noundef %9)
  store ptr %10, ptr %5, align 8, !tbaa !9
  %11 = load ptr, ptr %5, align 8, !tbaa !9
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %17

13:                                               ; preds = %2
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = load ptr, ptr %5, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.node, ptr %15, i32 0, i32 1
  store i32 %14, ptr %16, align 4, !tbaa !11
  store i32 1, ptr %6, align 4
  br label %122

17:                                               ; preds = %2
  %18 = load ptr, ptr @lru, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.anon, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = load ptr, ptr @lru, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.anon, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !15
  %24 = icmp slt i32 %20, %23
  br i1 %24, label %25, label %71

25:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %26 = call noalias ptr @malloc(i64 noundef 24) #4
  store ptr %26, ptr %7, align 8, !tbaa !9
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = load ptr, ptr %7, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.node, ptr %28, i32 0, i32 0
  store i32 %27, ptr %29, align 8, !tbaa !16
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = load ptr, ptr %7, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.node, ptr %31, i32 0, i32 1
  store i32 %30, ptr %32, align 4, !tbaa !11
  %33 = load ptr, ptr %7, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.node, ptr %33, i32 0, i32 3
  store ptr null, ptr %34, align 8, !tbaa !17
  %35 = load ptr, ptr @lru, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.anon, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !13
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %39, label %52

39:                                               ; preds = %25
  %40 = load ptr, ptr %7, align 8, !tbaa !9
  %41 = load ptr, ptr @lru, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.anon, ptr %41, i32 0, i32 2
  store ptr %40, ptr %42, align 8, !tbaa !18
  %43 = load ptr, ptr %7, align 8, !tbaa !9
  %44 = load ptr, ptr @lru, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.anon, ptr %44, i32 0, i32 3
  store ptr %43, ptr %45, align 8, !tbaa !19
  %46 = load ptr, ptr %7, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.node, ptr %46, i32 0, i32 2
  store ptr null, ptr %47, align 8, !tbaa !20
  %48 = load ptr, ptr @lru, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.anon, ptr %48, i32 0, i32 1
  %50 = load i32, ptr %49, align 4, !tbaa !13
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %49, align 4, !tbaa !13
  br label %70

52:                                               ; preds = %25
  %53 = load ptr, ptr @lru, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct.anon, ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !18
  %56 = load ptr, ptr %7, align 8, !tbaa !9
  %57 = getelementptr inbounds %struct.node, ptr %56, i32 0, i32 2
  store ptr %55, ptr %57, align 8, !tbaa !20
  %58 = load ptr, ptr %7, align 8, !tbaa !9
  %59 = load ptr, ptr @lru, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct.anon, ptr %59, i32 0, i32 2
  %61 = load ptr, ptr %60, align 8, !tbaa !18
  %62 = getelementptr inbounds %struct.node, ptr %61, i32 0, i32 3
  store ptr %58, ptr %62, align 8, !tbaa !17
  %63 = load ptr, ptr %7, align 8, !tbaa !9
  %64 = load ptr, ptr @lru, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.anon, ptr %64, i32 0, i32 2
  store ptr %63, ptr %65, align 8, !tbaa !18
  %66 = load ptr, ptr @lru, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.anon, ptr %66, i32 0, i32 1
  %68 = load i32, ptr %67, align 4, !tbaa !13
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %67, align 4, !tbaa !13
  br label %70

70:                                               ; preds = %52, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %121

71:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %72 = load ptr, ptr @lru, align 8, !tbaa !9
  %73 = getelementptr inbounds %struct.anon, ptr %72, i32 0, i32 3
  %74 = load ptr, ptr %73, align 8, !tbaa !19
  store ptr %74, ptr %8, align 8, !tbaa !9
  %75 = load ptr, ptr %8, align 8, !tbaa !9
  %76 = load ptr, ptr @lru, align 8, !tbaa !9
  %77 = getelementptr inbounds %struct.anon, ptr %76, i32 0, i32 2
  %78 = load ptr, ptr %77, align 8, !tbaa !18
  %79 = icmp eq ptr %75, %78
  br i1 %79, label %80, label %87

80:                                               ; preds = %71
  %81 = load i32, ptr %3, align 4, !tbaa !5
  %82 = load ptr, ptr %8, align 8, !tbaa !9
  %83 = getelementptr inbounds %struct.node, ptr %82, i32 0, i32 0
  store i32 %81, ptr %83, align 8, !tbaa !16
  %84 = load i32, ptr %4, align 4, !tbaa !5
  %85 = load ptr, ptr %8, align 8, !tbaa !9
  %86 = getelementptr inbounds %struct.node, ptr %85, i32 0, i32 1
  store i32 %84, ptr %86, align 4, !tbaa !11
  store i32 1, ptr %6, align 4
  br label %118

87:                                               ; preds = %71
  %88 = load ptr, ptr %8, align 8, !tbaa !9
  %89 = getelementptr inbounds %struct.node, ptr %88, i32 0, i32 3
  %90 = load ptr, ptr %89, align 8, !tbaa !17
  %91 = getelementptr inbounds %struct.node, ptr %90, i32 0, i32 2
  store ptr null, ptr %91, align 8, !tbaa !20
  %92 = load ptr, ptr %8, align 8, !tbaa !9
  %93 = getelementptr inbounds %struct.node, ptr %92, i32 0, i32 3
  %94 = load ptr, ptr %93, align 8, !tbaa !17
  %95 = load ptr, ptr @lru, align 8, !tbaa !9
  %96 = getelementptr inbounds %struct.anon, ptr %95, i32 0, i32 3
  store ptr %94, ptr %96, align 8, !tbaa !19
  %97 = load i32, ptr %3, align 4, !tbaa !5
  %98 = load ptr, ptr %8, align 8, !tbaa !9
  %99 = getelementptr inbounds %struct.node, ptr %98, i32 0, i32 0
  store i32 %97, ptr %99, align 8, !tbaa !16
  %100 = load i32, ptr %4, align 4, !tbaa !5
  %101 = load ptr, ptr %8, align 8, !tbaa !9
  %102 = getelementptr inbounds %struct.node, ptr %101, i32 0, i32 1
  store i32 %100, ptr %102, align 4, !tbaa !11
  %103 = load ptr, ptr %8, align 8, !tbaa !9
  %104 = load ptr, ptr @lru, align 8, !tbaa !9
  %105 = getelementptr inbounds %struct.anon, ptr %104, i32 0, i32 2
  %106 = load ptr, ptr %105, align 8, !tbaa !18
  %107 = getelementptr inbounds %struct.node, ptr %106, i32 0, i32 3
  store ptr %103, ptr %107, align 8, !tbaa !17
  %108 = load ptr, ptr @lru, align 8, !tbaa !9
  %109 = getelementptr inbounds %struct.anon, ptr %108, i32 0, i32 2
  %110 = load ptr, ptr %109, align 8, !tbaa !18
  %111 = load ptr, ptr %8, align 8, !tbaa !9
  %112 = getelementptr inbounds %struct.node, ptr %111, i32 0, i32 2
  store ptr %110, ptr %112, align 8, !tbaa !20
  %113 = load ptr, ptr %8, align 8, !tbaa !9
  %114 = getelementptr inbounds %struct.node, ptr %113, i32 0, i32 3
  store ptr null, ptr %114, align 8, !tbaa !17
  %115 = load ptr, ptr %8, align 8, !tbaa !9
  %116 = load ptr, ptr @lru, align 8, !tbaa !9
  %117 = getelementptr inbounds %struct.anon, ptr %116, i32 0, i32 2
  store ptr %115, ptr %117, align 8, !tbaa !18
  store i32 0, ptr %6, align 4
  br label %118

118:                                              ; preds = %87, %80
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %119 = load i32, ptr %6, align 4
  switch i32 %119, label %122 [
    i32 0, label %120
  ]

120:                                              ; preds = %118
  br label %121

121:                                              ; preds = %120, %70
  store i32 0, ptr %6, align 4
  br label %122

122:                                              ; preds = %121, %118, %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  %123 = load i32, ptr %6, align 4
  switch i32 %123, label %125 [
    i32 0, label %124
    i32 1, label %124
  ]

124:                                              ; preds = %122, %122
  ret void

125:                                              ; preds = %122
  unreachable
}

attributes #0 = { nounwind allocsize(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 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 }
attributes #4 = { nounwind allocsize(0) }

!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, !6, i64 4}
!12 = !{!"node", !6, i64 0, !6, i64 4, !10, i64 8, !10, i64 16}
!13 = !{!14, !6, i64 4}
!14 = !{!"", !6, i64 0, !6, i64 4, !10, i64 8, !10, i64 16}
!15 = !{!14, !6, i64 0}
!16 = !{!12, !6, i64 0}
!17 = !{!12, !10, i64 16}
!18 = !{!14, !10, i64 8}
!19 = !{!14, !10, i64 16}
!20 = !{!12, !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: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @lruCacheSet(i32 noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = tail call ptr @fetch(i32 noundef %0)
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %6, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %3, i64 4
  store i32 %1, ptr %5, align 4, !tbaa !5
  br label %40

6:                                                ; preds = %2
  %7 = load ptr, ptr @lru, align 8, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %7, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !12
  %10 = load i32, ptr %7, align 8, !tbaa !14
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %12, label %26

12:                                               ; preds = %6
  %13 = tail call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #2
  store i32 %0, ptr %13, align 8, !tbaa !15
  %14 = getelementptr inbounds i8, ptr %13, i64 4
  store i32 %1, ptr %14, align 4, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %13, i64 16
  store ptr null, ptr %15, align 8, !tbaa !16
  %16 = icmp eq i32 %9, 0
  %17 = getelementptr inbounds i8, ptr %7, i64 8
  br i1 %16, label %18, label %21

18:                                               ; preds = %12
  store ptr %13, ptr %17, align 8, !tbaa !17
  %19 = getelementptr inbounds i8, ptr %7, i64 16
  store ptr %13, ptr %19, align 8, !tbaa !18
  %20 = getelementptr inbounds i8, ptr %13, i64 8
  store ptr null, ptr %20, align 8, !tbaa !19
  store i32 1, ptr %8, align 4, !tbaa !12
  br label %40

21:                                               ; preds = %12
  %22 = load ptr, ptr %17, align 8, !tbaa !17
  %23 = getelementptr inbounds i8, ptr %13, i64 8
  store ptr %22, ptr %23, align 8, !tbaa !19
  %24 = getelementptr inbounds i8, ptr %22, i64 16
  store ptr %13, ptr %24, align 8, !tbaa !16
  store ptr %13, ptr %17, align 8, !tbaa !17
  %25 = add nsw i32 %9, 1
  store i32 %25, ptr %8, align 4, !tbaa !12
  br label %40

26:                                               ; preds = %6
  %27 = getelementptr inbounds i8, ptr %7, i64 16
  %28 = load ptr, ptr %27, align 8, !tbaa !18
  %29 = getelementptr inbounds i8, ptr %7, i64 8
  %30 = load ptr, ptr %29, align 8, !tbaa !17
  %.not32 = icmp eq ptr %28, %30
  br i1 %.not32, label %31, label %33

31:                                               ; preds = %26
  store i32 %0, ptr %28, align 8, !tbaa !15
  %32 = getelementptr inbounds i8, ptr %28, i64 4
  store i32 %1, ptr %32, align 4, !tbaa !5
  br label %40

33:                                               ; preds = %26
  %34 = getelementptr inbounds i8, ptr %28, i64 16
  %35 = load ptr, ptr %34, align 8, !tbaa !16
  %36 = getelementptr inbounds i8, ptr %35, i64 8
  store ptr null, ptr %36, align 8, !tbaa !19
  store ptr %35, ptr %27, align 8, !tbaa !18
  store i32 %0, ptr %28, align 8, !tbaa !15
  %37 = getelementptr inbounds i8, ptr %28, i64 4
  store i32 %1, ptr %37, align 4, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %30, i64 16
  store ptr %28, ptr %38, align 8, !tbaa !16
  %39 = getelementptr inbounds i8, ptr %28, i64 8
  store ptr %30, ptr %39, align 8, !tbaa !19
  store ptr null, ptr %34, align 8, !tbaa !16
  store ptr %28, ptr %29, align 8, !tbaa !17
  br label %40

40:                                               ; preds = %31, %33, %21, %18, %4
  ret void
}

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 allocsize(0) }

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


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