; 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_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 }

@rl_data_type_header = external dso_local global %struct.rl_data_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
declare void @free(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_get_key_btree(ptr noundef, ptr noundef, i32 noundef) #2

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

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

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

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

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

12:                                               ; preds = %1
  %13 = load i32, ptr %3, align 4, !tbaa !9
  %14 = icmp ne i32 3, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %12
  br label %97

16:                                               ; preds = %12, %1
  %17 = load i32, ptr %3, align 4, !tbaa !9
  %18 = icmp eq i32 %17, 3
  br i1 %18, label %19, label %20

19:                                               ; preds = %16
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %97

20:                                               ; preds = %16
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = call i32 @rl_btree_iterator_create(ptr noundef %21, ptr noundef %22, ptr noundef %5)
  store i32 %23, ptr %3, align 4, !tbaa !9
  %24 = load i32, ptr %3, align 4, !tbaa !9
  %25 = icmp ne i32 0, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %20
  br label %97

27:                                               ; preds = %20
  br label %28

28:                                               ; preds = %54, %27
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = call i32 @rl_btree_iterator_next(ptr noundef %29, ptr noundef null, ptr noundef %7)
  store i32 %30, ptr %3, align 4, !tbaa !9
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %56

32:                                               ; preds = %28
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %33, ptr %6, align 8, !tbaa !5
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.rl_key, ptr %35, i32 0, i32 0
  %37 = load i8, ptr %36, align 8, !tbaa !11
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.rl_key, ptr %38, i32 0, i32 2
  %40 = load i64, ptr %39, align 8, !tbaa !15
  %41 = call i32 @rl_key_delete_value(ptr noundef %34, i8 noundef zeroext %37, i64 noundef %40)
  store i32 %41, ptr %3, align 4, !tbaa !9
  %42 = load i32, ptr %3, align 4, !tbaa !9
  %43 = icmp ne i32 0, %42
  br i1 %43, label %44, label %45

44:                                               ; preds = %32
  br label %97

45:                                               ; preds = %32
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.rl_key, ptr %47, i32 0, i32 1
  %49 = load i64, ptr %48, align 8, !tbaa !16
  %50 = call i32 @rl_multi_string_delete(ptr noundef %46, i64 noundef %49)
  store i32 %50, ptr %3, align 4, !tbaa !9
  %51 = load i32, ptr %3, align 4, !tbaa !9
  %52 = icmp ne i32 0, %51
  br i1 %52, label %53, label %54

53:                                               ; preds = %45
  br label %97

54:                                               ; preds = %45
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %55) #4
  br label %28, !llvm.loop !17

56:                                               ; preds = %28
  %57 = load i32, ptr %3, align 4, !tbaa !9
  %58 = icmp ne i32 %57, 9
  br i1 %58, label %59, label %60

59:                                               ; preds = %56
  br label %97

60:                                               ; preds = %56
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = call i32 @rl_btree_delete(ptr noundef %61, ptr noundef %62)
  store i32 %63, ptr %3, align 4, !tbaa !9
  %64 = load i32, ptr %3, align 4, !tbaa !9
  %65 = icmp ne i32 0, %64
  br i1 %65, label %66, label %67

66:                                               ; preds = %60
  br label %97

67:                                               ; preds = %60
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = load ptr, ptr %2, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.rlite, ptr %69, i32 0, i32 12
  %71 = load ptr, ptr %70, align 8, !tbaa !19
  %72 = load ptr, ptr %2, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.rlite, ptr %72, i32 0, i32 10
  %74 = load i32, ptr %73, align 8, !tbaa !21
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds i64, ptr %71, i64 %75
  %77 = load i64, ptr %76, align 8, !tbaa !22
  %78 = call i32 @rl_delete(ptr noundef %68, i64 noundef %77)
  store i32 %78, ptr %3, align 4, !tbaa !9
  %79 = load i32, ptr %3, align 4, !tbaa !9
  %80 = icmp ne i32 0, %79
  br i1 %80, label %81, label %82

81:                                               ; preds = %67
  br label %97

82:                                               ; preds = %67
  %83 = load ptr, ptr %2, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.rlite, ptr %83, i32 0, i32 12
  %85 = load ptr, ptr %84, align 8, !tbaa !19
  %86 = load ptr, ptr %2, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.rlite, ptr %86, i32 0, i32 10
  %88 = load i32, ptr %87, align 8, !tbaa !21
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds i64, ptr %85, i64 %89
  store i64 0, ptr %90, align 8, !tbaa !22
  %91 = load ptr, ptr %2, align 8, !tbaa !5
  %92 = call i32 @rl_write(ptr noundef %91, ptr noundef @rl_data_type_header, i64 noundef 0, ptr noundef null)
  store i32 %92, ptr %3, align 4, !tbaa !9
  %93 = load i32, ptr %3, align 4, !tbaa !9
  %94 = icmp ne i32 0, %93
  br i1 %94, label %95, label %96

95:                                               ; preds = %82
  br label %97

96:                                               ; preds = %82
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %97

97:                                               ; preds = %96, %95, %81, %66, %59, %53, %44, %26, %19, %15
  %98 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret i32 %98
}

declare i32 @rl_key_delete_value(ptr noundef, i8 noundef zeroext, i64 noundef) #3

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { "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 }

!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, !7, i64 0}
!12 = !{!"rl_key", !7, i64 0, !13, i64 8, !13, i64 16, !14, i64 24, !13, i64 32}
!13 = !{!"long", !7, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = !{!12, !13, i64 16}
!16 = !{!12, !13, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !6, i64 80}
!20 = !{!"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}
!21 = !{!20, !10, i64 72}
!22 = !{!13, !13, i64 0}


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

@rl_data_type_header = external dso_local global %struct.rl_data_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: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_get_key_btree(ptr noundef, ptr noundef, i32 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 #2

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_flushdb(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  store ptr null, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  %5 = call i32 @rl_get_key_btree(ptr noundef %0, ptr noundef nonnull %2, i32 noundef 0)
  switch i32 %5, label %.loopexit [
    i32 3, label %6
    i32 0, label %7
  ]

6:                                                ; preds = %1
  br label %.loopexit

7:                                                ; preds = %1
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = call i32 @rl_btree_iterator_create(ptr noundef %0, ptr noundef %8, ptr noundef nonnull %3) #4
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %7, %22
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = call i32 @rl_btree_iterator_next(ptr noundef %10, ptr noundef null, ptr noundef nonnull %4) #4
  switch i32 %11, label %.loopexit [
    i32 0, label %12
    i32 9, label %23
  ]

12:                                               ; preds = %.preheader
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = load i8, ptr %13, align 8, !tbaa !9
  %15 = getelementptr inbounds i8, ptr %13, i64 16
  %16 = load i64, ptr %15, align 8, !tbaa !13
  %17 = call i32 @rl_key_delete_value(ptr noundef %0, i8 noundef zeroext %14, i64 noundef %16) #4
  %.not36 = icmp eq i32 %17, 0
  br i1 %.not36, label %18, label %.loopexit

18:                                               ; preds = %12
  %19 = getelementptr inbounds i8, ptr %13, i64 8
  %20 = load i64, ptr %19, align 8, !tbaa !14
  %21 = call i32 @rl_multi_string_delete(ptr noundef %0, i64 noundef %20) #4
  %.not37 = icmp eq i32 %21, 0
  br i1 %.not37, label %22, label %.loopexit

22:                                               ; preds = %18
  call void @free(ptr noundef nonnull %13) #4
  br label %.preheader, !llvm.loop !15

23:                                               ; preds = %.preheader
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = call i32 @rl_btree_delete(ptr noundef %0, ptr noundef %24) #4
  %.not34 = icmp eq i32 %25, 0
  br i1 %.not34, label %26, label %.loopexit

26:                                               ; preds = %23
  %27 = getelementptr inbounds i8, ptr %0, i64 80
  %28 = load ptr, ptr %27, align 8, !tbaa !17
  %29 = getelementptr inbounds i8, ptr %0, i64 72
  %30 = load i32, ptr %29, align 8, !tbaa !20
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds i64, ptr %28, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !21
  %34 = call i32 @rl_delete(ptr noundef %0, i64 noundef %33)
  %.not35 = icmp eq i32 %34, 0
  br i1 %.not35, label %35, label %.loopexit

35:                                               ; preds = %26
  %36 = load ptr, ptr %27, align 8, !tbaa !17
  %37 = load i32, ptr %29, align 8, !tbaa !20
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i64, ptr %36, i64 %38
  store i64 0, ptr %39, align 8, !tbaa !21
  %40 = call i32 @rl_write(ptr noundef nonnull %0, ptr noundef nonnull @rl_data_type_header, i64 noundef 0, ptr noundef null)
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader, %18, %12, %1, %35, %26, %23, %7, %6
  %.0 = phi i32 [ %5, %1 ], [ 0, %6 ], [ %9, %7 ], [ %25, %23 ], [ %34, %26 ], [ %40, %35 ], [ %11, %.preheader ], [ %21, %18 ], [ %17, %12 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  ret i32 %.0
}

declare i32 @rl_key_delete_value(ptr noundef, i8 noundef zeroext, i64 noundef) local_unnamed_addr #3

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

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { "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 }

!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, !7, i64 0}
!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 = !{!10, !11, i64 16}
!14 = !{!10, !11, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !6, i64 80}
!18 = !{!"rlite", !11, i64 0, !11, i64 8, !19, i64 16, !6, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !6, i64 56, !19, i64 64, !19, i64 68, !19, i64 72, !19, 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}
!19 = !{!"int", !7, i64 0}
!20 = !{!18, !19, i64 72}
!21 = !{!11, !11, i64 0}


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