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

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

@rl_data_type_btree_hash_sha1_key = external dso_local global %struct.rl_data_type, align 8
@rl_btree_type_hash_sha1_key = external global %struct.rl_btree_type, align 8

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_get_key_btree(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = call i32 @rl_get_selected_db(ptr noundef %13)
  store i32 %14, ptr %10, align 4, !tbaa !9
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.rlite, ptr %15, i32 0, i32 12
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  %18 = load i32, ptr %10, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i64, ptr %17, i64 %19
  %21 = load i64, ptr %20, align 8, !tbaa !14
  %22 = icmp ne i64 %21, 0
  br i1 %22, label %60, label %23

23:                                               ; preds = %3
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  store i32 3, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %78

27:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = call i32 @rl_btree_create(ptr noundef %28, ptr noundef %12, ptr noundef @rl_btree_type_hash_sha1_key)
  store i32 %29, ptr %9, align 4, !tbaa !9
  %30 = load i32, ptr %9, align 4, !tbaa !9
  %31 = icmp ne i32 0, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %27
  store i32 2, ptr %11, align 4
  br label %57

33:                                               ; preds = %27
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.rlite, ptr %34, i32 0, i32 5
  %36 = load i64, ptr %35, align 8, !tbaa !15
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.rlite, ptr %37, i32 0, i32 12
  %39 = load ptr, ptr %38, align 8, !tbaa !11
  %40 = load i32, ptr %10, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i64, ptr %39, i64 %41
  store i64 %36, ptr %42, align 8, !tbaa !14
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.rlite, ptr %44, i32 0, i32 12
  %46 = load ptr, ptr %45, align 8, !tbaa !11
  %47 = load i32, ptr %10, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i64, ptr %46, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !14
  %51 = load ptr, ptr %12, align 8, !tbaa !5
  %52 = call i32 @rl_write(ptr noundef %43, ptr noundef @rl_data_type_btree_hash_sha1_key, i64 noundef %50, ptr noundef %51)
  store i32 %52, ptr %9, align 4, !tbaa !9
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = icmp ne i32 0, %53
  br i1 %54, label %55, label %56

55:                                               ; preds = %33
  store i32 2, ptr %11, align 4
  br label %57

56:                                               ; preds = %33
  store i32 0, ptr %11, align 4
  br label %57

57:                                               ; preds = %56, %55, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %58 = load i32, ptr %11, align 4
  switch i32 %58, label %78 [
    i32 0, label %59
    i32 2, label %76
  ]

59:                                               ; preds = %57
  br label %60

60:                                               ; preds = %59, %3
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.rlite, ptr %62, i32 0, i32 12
  %64 = load ptr, ptr %63, align 8, !tbaa !11
  %65 = load i32, ptr %10, align 4, !tbaa !9
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds i64, ptr %64, i64 %66
  %68 = load i64, ptr %67, align 8, !tbaa !14
  %69 = call i32 @rl_read(ptr noundef %61, ptr noundef @rl_data_type_btree_hash_sha1_key, i64 noundef %68, ptr noundef @rl_btree_type_hash_sha1_key, ptr noundef %8, i32 noundef 1)
  store i32 %69, ptr %9, align 4, !tbaa !9
  %70 = load i32, ptr %9, align 4, !tbaa !9
  %71 = icmp ne i32 2, %70
  br i1 %71, label %72, label %73

72:                                               ; preds = %60
  br label %76

73:                                               ; preds = %60
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %74, ptr %75, align 8, !tbaa !5
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %76

76:                                               ; preds = %73, %72, %57
  %77 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %77, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %78

78:                                               ; preds = %76, %57, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %79 = load i32, ptr %4, align 4
  ret i32 %79
}

declare i32 @rl_btree_create(ptr noundef, ptr noundef, ptr noundef) #2

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

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

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 = { "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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 80}
!12 = !{!"rlite", !13, i64 0, !13, i64 8, !10, i64 16, !6, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !6, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !6, i64 80, !13, i64 88, !13, i64 96, !6, i64 104, !13, i64 112, !13, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152}
!13 = !{!"long", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !13, i64 40}


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

%struct.rl_data_type = type { ptr, ptr, ptr, ptr }
%struct.rl_btree_type = type { ptr, ptr, i32, i32, ptr }

@rl_data_type_btree_hash_sha1_key = external dso_local global %struct.rl_data_type, align 8
@rl_btree_type_hash_sha1_key = external global %struct.rl_btree_type, align 8

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_get_key_btree(ptr noundef %0, ptr nocapture noundef writeonly %1, i32 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) #3
  %6 = tail call i32 @rl_get_selected_db(ptr noundef %0)
  %7 = getelementptr inbounds i8, ptr %0, i64 80
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = sext i32 %6 to i64
  %10 = getelementptr inbounds i64, ptr %8, i64 %9
  %11 = load i64, ptr %10, align 8, !tbaa !12
  %.not = icmp eq i64 %11, 0
  br i1 %.not, label %12, label %23

12:                                               ; preds = %3
  %.not26 = icmp eq i32 %2, 0
  br i1 %.not26, label %28, label %13

13:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  %14 = call i32 @rl_btree_create(ptr noundef nonnull %0, ptr noundef nonnull %5, ptr noundef nonnull @rl_btree_type_hash_sha1_key) #3
  %.not27 = icmp eq i32 %14, 0
  br i1 %.not27, label %15, label %.thread

15:                                               ; preds = %13
  %16 = getelementptr inbounds i8, ptr %0, i64 40
  %17 = load i64, ptr %16, align 8, !tbaa !13
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds i64, ptr %18, i64 %9
  store i64 %17, ptr %19, align 8, !tbaa !12
  %20 = load ptr, ptr %5, align 8, !tbaa !14
  %21 = call i32 @rl_write(ptr noundef nonnull %0, ptr noundef nonnull @rl_data_type_btree_hash_sha1_key, i64 noundef %17, ptr noundef %20)
  %.not28 = icmp eq i32 %21, 0
  br i1 %.not28, label %22, label %.thread

.thread:                                          ; preds = %13, %15
  %.021.ph = phi i32 [ %21, %15 ], [ %14, %13 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  br label %28

22:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  %.pre = load ptr, ptr %7, align 8, !tbaa !5
  %.phi.trans.insert = getelementptr inbounds i64, ptr %.pre, i64 %9
  %.pre35 = load i64, ptr %.phi.trans.insert, align 8, !tbaa !12
  br label %23

23:                                               ; preds = %22, %3
  %24 = phi i64 [ %.pre35, %22 ], [ %11, %3 ]
  %25 = call i32 @rl_read(ptr noundef nonnull %0, ptr noundef nonnull @rl_data_type_btree_hash_sha1_key, i64 noundef %24, ptr noundef nonnull @rl_btree_type_hash_sha1_key, ptr noundef nonnull %4, i32 noundef 1)
  %.not29 = icmp eq i32 %25, 2
  br i1 %.not29, label %26, label %28

26:                                               ; preds = %23
  %27 = load ptr, ptr %4, align 8, !tbaa !14
  store ptr %27, ptr %1, align 8, !tbaa !14
  br label %28

28:                                               ; preds = %.thread, %26, %23, %12
  %.020 = phi i32 [ 3, %12 ], [ %25, %23 ], [ 0, %26 ], [ %.021.ph, %.thread ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  ret i32 %.020
}

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

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

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

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


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