; LLVM IR from seppo0010/rlite :: src (page_key)

; 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.rl_key = type { i8, i64, i64, i64, i64 }
%struct.rlite = type { i64, i64, i32, ptr, i64, i64, i64, ptr, i32, i32, i32, i32, ptr, i64, i64, ptr, i64, i64, ptr, 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: nounwind uwtable
define dso_local i32 @rl_key_delete(ptr noundef %0, ptr noundef %1, i64 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  store ptr null, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  store ptr null, ptr %12, align 8, !tbaa !5
  %15 = call noalias ptr @malloc(i64 noundef 20) #6
  store ptr %15, ptr %10, align 8, !tbaa !5
  %16 = load ptr, ptr %10, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %19, label %18

18:                                               ; preds = %3
  store i32 4, ptr %8, align 4, !tbaa !11
  br label %83

19:                                               ; preds = %3
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load i64, ptr %7, align 8, !tbaa !9
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  %23 = call i32 @sha1(ptr noundef %20, i64 noundef %21, ptr noundef %22)
  store i32 %23, ptr %8, align 4, !tbaa !11
  %24 = load i32, ptr %8, align 4, !tbaa !11
  %25 = icmp ne i32 0, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %19
  br label %83

27:                                               ; preds = %19
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = call i32 @rl_get_key_btree(ptr noundef %28, ptr noundef %11, i32 noundef 0)
  store i32 %29, ptr %8, align 4, !tbaa !11
  %30 = load i32, ptr %8, align 4, !tbaa !11
  %31 = icmp ne i32 0, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %27
  br label %83

33:                                               ; preds = %27
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = call i32 @rl_btree_find_score(ptr noundef %34, ptr noundef %35, ptr noundef %36, ptr noundef %9, ptr noundef null, ptr noundef null)
  store i32 %37, ptr %8, align 4, !tbaa !11
  %38 = load i32, ptr %8, align 4, !tbaa !11
  %39 = icmp eq i32 %38, 2
  br i1 %39, label %40, label %82

40:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = call i32 @rl_get_selected_db(ptr noundef %41)
  store i32 %42, ptr %13, align 4, !tbaa !11
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %43, ptr %12, align 8, !tbaa !5
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load ptr, ptr %12, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.rl_key, ptr %45, i32 0, i32 1
  %47 = load i64, ptr %46, align 8, !tbaa !13
  %48 = call i32 @rl_multi_string_delete(ptr noundef %44, i64 noundef %47)
  store i32 %48, ptr %8, align 4, !tbaa !11
  %49 = load i32, ptr %8, align 4, !tbaa !11
  %50 = icmp ne i32 0, %49
  br i1 %50, label %51, label %52

51:                                               ; preds = %40
  store i32 2, ptr %14, align 4
  br label %79

52:                                               ; preds = %40
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.rlite, ptr %55, i32 0, i32 12
  %57 = load ptr, ptr %56, align 8, !tbaa !16
  %58 = load i32, ptr %13, align 4, !tbaa !11
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i64, ptr %57, i64 %59
  %61 = load i64, ptr %60, align 8, !tbaa !9
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = call i32 @rl_btree_remove_element(ptr noundef %53, ptr noundef %54, i64 noundef %61, ptr noundef %62)
  store i32 %63, ptr %8, align 4, !tbaa !11
  %64 = load i32, ptr %8, align 4, !tbaa !11
  %65 = icmp eq i32 %64, 10
  br i1 %65, label %66, label %73

66:                                               ; preds = %52
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.rlite, ptr %67, i32 0, i32 12
  %69 = load ptr, ptr %68, align 8, !tbaa !16
  %70 = load i32, ptr %13, align 4, !tbaa !11
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds i64, ptr %69, i64 %71
  store i64 0, ptr %72, align 8, !tbaa !9
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %78

73:                                               ; preds = %52
  %74 = load i32, ptr %8, align 4, !tbaa !11
  %75 = icmp ne i32 %74, 0
  br i1 %75, label %76, label %77

76:                                               ; preds = %73
  store i32 2, ptr %14, align 4
  br label %79

77:                                               ; preds = %73
  br label %78

78:                                               ; preds = %77, %66
  store i32 0, ptr %14, align 4
  br label %79

79:                                               ; preds = %78, %76, %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  %80 = load i32, ptr %14, align 4
  switch i32 %80, label %86 [
    i32 0, label %81
    i32 2, label %83
  ]

81:                                               ; preds = %79
  br label %82

82:                                               ; preds = %81, %33
  br label %83

83:                                               ; preds = %82, %79, %32, %26, %18
  %84 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %84) #5
  %85 = load i32, ptr %8, align 4, !tbaa !11
  store i32 %85, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %86

86:                                               ; preds = %83, %79
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  %87 = load i32, ptr %4, align 4
  ret i32 %87
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

declare i32 @sha1(ptr noundef, i64 noundef, ptr noundef) #3

declare i32 @rl_get_key_btree(ptr noundef, ptr noundef, i32 noundef) #3

declare i32 @rl_get_selected_db(ptr noundef) #3

; Function Attrs: nounwind
declare void @free(ptr noundef) #4

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

declare i32 @rl_btree_find_score(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #3

declare i32 @rl_multi_string_delete(ptr noundef, i64 noundef) #3

declare i32 @rl_btree_remove_element(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #3

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 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 #3 = { "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 #4 = { 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" }
attributes #5 = { nounwind }
attributes #6 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"rl_key", !7, i64 0, !10, i64 8, !10, i64 16, !15, i64 24, !10, i64 32}
!15 = !{!"long long", !7, i64 0}
!16 = !{!17, !6, i64 80}
!17 = !{!"rlite", !10, i64 0, !10, i64 8, !12, i64 16, !6, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !6, i64 56, !12, i64 64, !12, i64 68, !12, i64 72, !12, i64 76, !6, i64 80, !10, i64 88, !10, i64 96, !6, i64 104, !10, i64 112, !10, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152}


; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_key_delete(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #5
  store ptr null, ptr %5, align 8, !tbaa !5
  %6 = tail call noalias dereferenceable_or_null(20) ptr @malloc(i64 noundef 20) #6
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %33, label %7

7:                                                ; preds = %3
  %8 = tail call i32 @sha1(ptr noundef %1, i64 noundef %2, ptr noundef nonnull %6) #5
  %.not33 = icmp eq i32 %8, 0
  br i1 %.not33, label %9, label %33

9:                                                ; preds = %7
  %10 = call i32 @rl_get_key_btree(ptr noundef %0, ptr noundef nonnull %5, i32 noundef 0) #5
  %.not34 = icmp eq i32 %10, 0
  br i1 %.not34, label %11, label %33

11:                                               ; preds = %9
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = call i32 @rl_btree_find_score(ptr noundef %0, ptr noundef %12, ptr noundef nonnull %6, ptr noundef nonnull %4, ptr noundef null, ptr noundef null) #5
  %14 = icmp eq i32 %13, 2
  br i1 %14, label %15, label %33

15:                                               ; preds = %11
  %16 = call i32 @rl_get_selected_db(ptr noundef %0) #5
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 8
  %19 = load i64, ptr %18, align 8, !tbaa !9
  %20 = call i32 @rl_multi_string_delete(ptr noundef %0, i64 noundef %19) #5
  %.not35 = icmp eq i32 %20, 0
  br i1 %.not35, label %21, label %33

21:                                               ; preds = %15
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %0, i64 80
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = sext i32 %16 to i64
  %26 = getelementptr inbounds i64, ptr %24, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !16
  %28 = call i32 @rl_btree_remove_element(ptr noundef %0, ptr noundef %22, i64 noundef %27, ptr noundef nonnull %6) #5
  switch i32 %28, label %33 [
    i32 10, label %29
    i32 0, label %32
  ]

29:                                               ; preds = %21
  %30 = load ptr, ptr %23, align 8, !tbaa !13
  %31 = getelementptr inbounds i64, ptr %30, i64 %25
  store i64 0, ptr %31, align 8, !tbaa !16
  br label %32

32:                                               ; preds = %21, %29
  br label %33

33:                                               ; preds = %32, %15, %21, %3, %11, %9, %7
  %.2 = phi i32 [ %8, %7 ], [ %10, %9 ], [ %13, %11 ], [ 4, %3 ], [ 0, %32 ], [ %20, %15 ], [ %28, %21 ]
  call void @free(ptr noundef %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  ret i32 %.2
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

declare i32 @sha1(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #3

declare i32 @rl_get_key_btree(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

declare i32 @rl_get_selected_db(ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #4

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

declare i32 @rl_btree_find_score(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @rl_multi_string_delete(ptr noundef, i64 noundef) local_unnamed_addr #3

declare i32 @rl_btree_remove_element(ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress 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 = { 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 #3 = { "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 #4 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #5 = { nounwind }
attributes #6 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"rl_key", !7, i64 0, !11, i64 8, !11, i64 16, !12, i64 24, !11, i64 32}
!11 = !{!"long", !7, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !6, i64 80}
!14 = !{!"rlite", !11, i64 0, !11, i64 8, !15, i64 16, !6, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !6, i64 56, !15, i64 64, !15, i64 68, !15, i64 72, !15, i64 76, !6, i64 80, !11, i64 88, !11, i64 96, !6, i64 104, !11, i64 112, !11, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152}
!15 = !{!"int", !7, i64 0}
!16 = !{!11, !11, i64 0}


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