; LLVM IR from pmwkaa/monotone :: monotone/runtime/lib (encryption_mgr)

; 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.EncryptionMgr = type { %struct.Cache }
%struct.Cache = type { %struct.Spinlock, %struct.List, i32 }
%struct.Spinlock = type { i32 }
%struct.List = type { ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local void @encryption_mgr_free(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.EncryptionMgr, ptr %6, i32 0, i32 0
  %8 = getelementptr inbounds %struct.Cache, ptr %7, i32 0, i32 1
  %9 = getelementptr inbounds %struct.List, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %10, ptr %4, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %29, %1
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.EncryptionMgr, ptr %13, i32 0, i32 0
  %15 = getelementptr inbounds %struct.Cache, ptr %14, i32 0, i32 1
  %16 = icmp ne ptr %12, %15
  br i1 %16, label %17, label %22

17:                                               ; preds = %11
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.List, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !15
  store ptr %20, ptr %3, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br label %22

22:                                               ; preds = %17, %11
  %23 = phi i1 [ false, %11 ], [ %21, %17 ]
  br i1 %23, label %25, label %24

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

25:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i64 -8
  store ptr %27, ptr %5, align 8, !tbaa !5
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  call void @encryption_free(ptr noundef %28)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %29

29:                                               ; preds = %25
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %30, ptr %4, align 8, !tbaa !5
  br label %11, !llvm.loop !16

31:                                               ; preds = %24
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.EncryptionMgr, ptr %32, i32 0, i32 0
  call void @cache_reset(ptr noundef %33)
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.EncryptionMgr, ptr %34, i32 0, i32 0
  call void @cache_free(ptr noundef %35)
  ret void
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @encryption_free(ptr noundef) #2

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @cache_reset(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @cache_free(ptr noundef) #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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 }

!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 = !{!"EncryptionMgr", !11, i64 0}
!11 = !{!"Cache", !12, i64 0, !14, i64 8, !13, i64 24}
!12 = !{!"Spinlock", !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"List", !6, i64 0, !6, i64 8}
!15 = !{!14, !6, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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: nounwind uwtable
define dso_local void @encryption_mgr_free(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not11 = icmp eq ptr %3, %2
  br i1 %.not11, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %5
  %.012 = phi ptr [ %4, %5 ], [ %3, %1 ]
  %4 = load ptr, ptr %.012, align 8, !tbaa !14
  %.not10 = icmp eq ptr %4, null
  br i1 %.not10, label %.critedge, label %5

.critedge:                                        ; preds = %.lr.ph, %5, %1
  tail call void @cache_reset(ptr noundef %0)
  tail call void @cache_free(ptr noundef %0)
  ret void

5:                                                ; preds = %.lr.ph
  %6 = getelementptr inbounds i8, ptr %.012, i64 -8
  tail call void @encryption_free(ptr noundef nonnull %6)
  %.not = icmp eq ptr %4, %2
  br i1 %.not, label %.critedge, label %.lr.ph, !llvm.loop !15
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @encryption_free(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @cache_reset(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @cache_free(ptr noundef) local_unnamed_addr #1

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 = { inlinehint 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, !13, i64 8}
!6 = !{!"EncryptionMgr", !7, i64 0}
!7 = !{!"Cache", !8, i64 0, !12, i64 8, !9, i64 24}
!8 = !{!"Spinlock", !9, i64 0}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = !{!"List", !13, i64 0, !13, i64 8}
!13 = !{!"any pointer", !10, i64 0}
!14 = !{!12, !13, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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