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

25:                                               ; preds = %7
  %26 = load i32, ptr %15, align 4, !tbaa !14
  %27 = icmp ne i32 3, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %25
  br label %97

29:                                               ; preds = %25, %7
  %30 = call noalias ptr @malloc(i64 noundef 20) #6
  store ptr %30, ptr %17, align 8, !tbaa !5
  %31 = load ptr, ptr %17, align 8, !tbaa !5
  %32 = icmp ne ptr %31, null
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  store i32 4, ptr %15, align 4, !tbaa !14
  br label %97

34:                                               ; preds = %29
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = load i64, ptr %10, align 8, !tbaa !9
  %37 = load ptr, ptr %17, align 8, !tbaa !5
  %38 = call i32 @sha1(ptr noundef %35, i64 noundef %36, ptr noundef %37)
  store i32 %38, ptr %15, align 4, !tbaa !14
  %39 = load i32, ptr %15, align 4, !tbaa !14
  %40 = icmp ne i32 0, %39
  br i1 %40, label %41, label %42

41:                                               ; preds = %34
  br label %97

42:                                               ; preds = %34
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = call i32 @rl_get_key_btree(ptr noundef %43, ptr noundef %18, i32 noundef 1)
  store i32 %44, ptr %15, align 4, !tbaa !14
  %45 = load i32, ptr %15, align 4, !tbaa !14
  %46 = icmp ne i32 0, %45
  br i1 %46, label %47, label %48

47:                                               ; preds = %42
  br label %97

48:                                               ; preds = %42
  %49 = call noalias ptr @malloc(i64 noundef 40) #6
  store ptr %49, ptr %16, align 8, !tbaa !5
  %50 = load ptr, ptr %16, align 8, !tbaa !5
  %51 = icmp ne ptr %50, null
  br i1 %51, label %53, label %52

52:                                               ; preds = %48
  store i32 4, ptr %15, align 4, !tbaa !14
  br label %97

53:                                               ; preds = %48
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = load ptr, ptr %16, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.rl_key, ptr %55, i32 0, i32 1
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = load i64, ptr %10, align 8, !tbaa !9
  %59 = call i32 @rl_multi_string_set(ptr noundef %54, ptr noundef %56, ptr noundef %57, i64 noundef %58)
  store i32 %59, ptr %15, align 4, !tbaa !14
  %60 = load i32, ptr %15, align 4, !tbaa !14
  %61 = icmp ne i32 0, %60
  br i1 %61, label %62, label %63

62:                                               ; preds = %53
  br label %97

63:                                               ; preds = %53
  %64 = load i8, ptr %11, align 1, !tbaa !11
  %65 = load ptr, ptr %16, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.rl_key, ptr %65, i32 0, i32 0
  store i8 %64, ptr %66, align 8, !tbaa !16
  %67 = load i64, ptr %12, align 8, !tbaa !9
  %68 = load ptr, ptr %16, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.rl_key, ptr %68, i32 0, i32 2
  store i64 %67, ptr %69, align 8, !tbaa !18
  %70 = load i64, ptr %13, align 8, !tbaa !12
  %71 = load ptr, ptr %16, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.rl_key, ptr %71, i32 0, i32 3
  store i64 %70, ptr %72, align 8, !tbaa !19
  %73 = load i64, ptr %14, align 8, !tbaa !9
  %74 = icmp eq i64 %73, 0
  br i1 %74, label %75, label %76

75:                                               ; preds = %63
  store i64 1, ptr %14, align 8, !tbaa !9
  br label %76

76:                                               ; preds = %75, %63
  %77 = load i64, ptr %14, align 8, !tbaa !9
  %78 = load ptr, ptr %16, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.rl_key, ptr %78, i32 0, i32 4
  store i64 %77, ptr %79, align 8, !tbaa !20
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = load ptr, ptr %18, align 8, !tbaa !5
  %82 = load ptr, ptr %8, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.rlite, ptr %82, i32 0, i32 12
  %84 = load ptr, ptr %83, align 8, !tbaa !21
  %85 = load ptr, ptr %8, align 8, !tbaa !5
  %86 = call i32 @rl_get_selected_db(ptr noundef %85)
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds i64, ptr %84, i64 %87
  %89 = load i64, ptr %88, align 8, !tbaa !9
  %90 = load ptr, ptr %17, align 8, !tbaa !5
  %91 = load ptr, ptr %16, align 8, !tbaa !5
  %92 = call i32 @rl_btree_add_element(ptr noundef %80, ptr noundef %81, i64 noundef %89, ptr noundef %90, ptr noundef %91)
  store i32 %92, ptr %15, align 4, !tbaa !14
  %93 = load i32, ptr %15, align 4, !tbaa !14
  %94 = icmp ne i32 0, %93
  br i1 %94, label %95, label %96

95:                                               ; preds = %76
  br label %97

96:                                               ; preds = %76
  store i32 0, ptr %15, align 4, !tbaa !14
  br label %97

97:                                               ; preds = %96, %95, %62, %52, %47, %41, %33, %28
  %98 = load i32, ptr %15, align 4, !tbaa !14
  %99 = icmp ne i32 %98, 0
  br i1 %99, label %100, label %103

100:                                              ; preds = %97
  %101 = load ptr, ptr %17, align 8, !tbaa !5
  call void @free(ptr noundef %101) #5
  %102 = load ptr, ptr %16, align 8, !tbaa !5
  call void @free(ptr noundef %102) #5
  br label %103

103:                                              ; preds = %100, %97
  %104 = load i32, ptr %15, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  ret i32 %104
}

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_key_delete(ptr noundef, ptr noundef, i64 noundef) #0

; 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_multi_string_set(ptr noundef, ptr noundef, ptr noundef, i64 noundef) #3

declare i32 @rl_btree_add_element(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr 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) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!17, !7, i64 0}
!17 = !{!"rl_key", !7, i64 0, !10, i64 8, !10, i64 16, !13, i64 24, !10, i64 32}
!18 = !{!17, !10, i64 16}
!19 = !{!17, !13, i64 24}
!20 = !{!17, !10, i64 32}
!21 = !{!22, !6, i64 80}
!22 = !{!"rlite", !10, i64 0, !10, i64 8, !15, i64 16, !6, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !6, i64 56, !15, i64 64, !15, i64 68, !15, i64 72, !15, 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: nounwind uwtable
define dso_local i32 @rl_key_set(ptr noundef %0, ptr noundef %1, i64 noundef %2, i8 noundef zeroext %3, i64 noundef %4, i64 noundef %5, i64 noundef %6) local_unnamed_addr #0 {
  %8 = alloca ptr, align 8
  %9 = tail call i32 @rl_key_delete(ptr noundef %0, ptr noundef %1, i64 noundef %2)
  switch i32 %9, label %.thread [
    i32 3, label %10
    i32 0, label %10
  ]

10:                                               ; preds = %7, %7
  %11 = tail call noalias dereferenceable_or_null(20) ptr @malloc(i64 noundef 20) #5
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %.thread, label %12

12:                                               ; preds = %10
  %13 = tail call i32 @sha1(ptr noundef %1, i64 noundef %2, ptr noundef nonnull %11) #6
  %.not47 = icmp eq i32 %13, 0
  br i1 %.not47, label %14, label %.thread

14:                                               ; preds = %12
  %15 = call i32 @rl_get_key_btree(ptr noundef %0, ptr noundef nonnull %8, i32 noundef 1) #6
  %.not48 = icmp eq i32 %15, 0
  br i1 %.not48, label %16, label %.thread

16:                                               ; preds = %14
  %17 = call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40) #5
  %.not49 = icmp eq ptr %17, null
  br i1 %.not49, label %.thread, label %18

18:                                               ; preds = %16
  %19 = getelementptr inbounds i8, ptr %17, i64 8
  %20 = call i32 @rl_multi_string_set(ptr noundef %0, ptr noundef nonnull %19, ptr noundef %1, i64 noundef %2) #6
  %.not50 = icmp eq i32 %20, 0
  br i1 %.not50, label %21, label %.thread

21:                                               ; preds = %18
  store i8 %3, ptr %17, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %17, i64 16
  store i64 %4, ptr %22, align 8, !tbaa !11
  %23 = getelementptr inbounds i8, ptr %17, i64 24
  store i64 %5, ptr %23, align 8, !tbaa !12
  %spec.store.select = call i64 @llvm.umax.i64(i64 %6, i64 1)
  %24 = getelementptr inbounds i8, ptr %17, i64 32
  store i64 %spec.store.select, ptr %24, align 8, !tbaa !13
  %25 = load ptr, ptr %8, align 8, !tbaa !14
  %26 = getelementptr inbounds i8, ptr %0, i64 80
  %27 = load ptr, ptr %26, align 8, !tbaa !16
  %28 = call i32 @rl_get_selected_db(ptr noundef %0) #6
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i64, ptr %27, i64 %29
  %31 = load i64, ptr %30, align 8, !tbaa !19
  %32 = call i32 @rl_btree_add_element(ptr noundef %0, ptr noundef %25, i64 noundef %31, ptr noundef nonnull %11, ptr noundef nonnull %17) #6
  %.not51 = icmp eq i32 %32, 0
  br i1 %.not51, label %33, label %.thread

.thread:                                          ; preds = %16, %10, %18, %14, %12, %7, %21
  %.059 = phi ptr [ %11, %21 ], [ %11, %16 ], [ null, %10 ], [ %11, %18 ], [ %11, %14 ], [ %11, %12 ], [ null, %7 ]
  %.03858 = phi ptr [ %17, %21 ], [ null, %16 ], [ null, %10 ], [ %17, %18 ], [ null, %14 ], [ null, %12 ], [ null, %7 ]
  %.03956 = phi i32 [ %32, %21 ], [ 4, %16 ], [ 4, %10 ], [ %20, %18 ], [ %15, %14 ], [ %13, %12 ], [ %9, %7 ]
  call void @free(ptr noundef %.059) #6
  call void @free(ptr noundef %.03858) #6
  br label %33

33:                                               ; preds = %.thread, %21
  %.03957 = phi i32 [ %.03956, %.thread ], [ 0, %21 ]
  ret i32 %.03957
}

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

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

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

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

declare i32 @rl_multi_string_set(ptr noundef, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare i32 @rl_btree_add_element(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @rl_get_selected_db(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #4

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


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