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

; 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.rl_btree = type { ptr, i64, i64, ptr, i64, i64 }

@rl_data_type_btree_hash_sha1_long = external global %struct.rl_data_type, align 8
@rl_btree_type_hash_sha1_long = 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
declare void @free(ptr noundef) #1

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

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

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

declare i32 @rl_read(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_set_delete(ptr noundef %0, i64 noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %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
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = load i64, ptr %4, align 8, !tbaa !9
  %12 = call i32 @rl_read(ptr noundef %10, ptr noundef @rl_data_type_btree_hash_sha1_long, i64 noundef %11, ptr noundef @rl_btree_type_hash_sha1_long, ptr noundef %9, i32 noundef 1)
  store i32 %12, ptr %8, align 4, !tbaa !11
  %13 = load i32, ptr %8, align 4, !tbaa !11
  %14 = icmp ne i32 2, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  br label %68

16:                                               ; preds = %2
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %17, ptr %5, align 8, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.rl_btree, ptr %18, i32 0, i32 5
  %20 = load i64, ptr %19, align 8, !tbaa !13
  %21 = icmp ne i64 %20, 0
  br i1 %21, label %22, label %53

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

28:                                               ; preds = %22
  %29 = load i32, ptr %8, align 4, !tbaa !11
  %30 = icmp ne i32 3, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %28
  br label %68

32:                                               ; preds = %28, %22
  %33 = load i32, ptr %8, align 4, !tbaa !11
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %52

35:                                               ; preds = %32
  br label %36

36:                                               ; preds = %40, %35
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = call i32 @rl_btree_iterator_next(ptr noundef %37, ptr noundef null, ptr noundef %9)
  store i32 %38, ptr %8, align 4, !tbaa !11
  %39 = icmp eq i32 %38, 0
  br i1 %39, label %40, label %47

40:                                               ; preds = %36
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = load i64, ptr %41, align 8, !tbaa !9
  store i64 %42, ptr %7, align 8, !tbaa !9
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = load i64, ptr %7, align 8, !tbaa !9
  %45 = call i32 @rl_multi_string_delete(ptr noundef %43, i64 noundef %44)
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  call void @free(ptr noundef %46) #4
  br label %36, !llvm.loop !15

47:                                               ; preds = %36
  store ptr null, ptr %6, align 8, !tbaa !5
  %48 = load i32, ptr %8, align 4, !tbaa !11
  %49 = icmp ne i32 %48, 9
  br i1 %49, label %50, label %51

50:                                               ; preds = %47
  br label %68

51:                                               ; preds = %47
  br label %52

52:                                               ; preds = %51, %32
  br label %53

53:                                               ; preds = %52, %16
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = call i32 @rl_btree_delete(ptr noundef %54, ptr noundef %55)
  store i32 %56, ptr %8, align 4, !tbaa !11
  %57 = load i32, ptr %8, align 4, !tbaa !11
  %58 = icmp ne i32 0, %57
  br i1 %58, label %59, label %60

59:                                               ; preds = %53
  br label %68

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

66:                                               ; preds = %60
  br label %68

67:                                               ; preds = %60
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %68

68:                                               ; preds = %67, %66, %59, %50, %31, %15
  %69 = load i32, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  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
  ret i32 %69
}

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

declare i32 @rl_delete(ptr noundef, i64 noundef) #2

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 = { "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 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 #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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 40}
!14 = !{!"rl_btree", !6, i64 0, !10, i64 8, !10, i64 16, !6, i64 24, !10, i64 32, !10, i64 40}
!15 = distinct !{!15, !16}
!16 = !{!"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"

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_set_delete(ptr noundef %0, i64 noundef %1) local_unnamed_addr #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  %5 = call i32 @rl_read(ptr noundef %0, ptr noundef nonnull @rl_data_type_btree_hash_sha1_long, i64 noundef %1, ptr noundef nonnull @rl_btree_type_hash_sha1_long, ptr noundef nonnull %4, i32 noundef 1) #4
  %.not = icmp eq i32 %5, 2
  br i1 %.not, label %6, label %26

6:                                                ; preds = %2
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 40
  %9 = load i64, ptr %8, align 8, !tbaa !9
  %.not23 = icmp eq i64 %9, 0
  br i1 %.not23, label %22, label %10

10:                                               ; preds = %6
  %11 = call i32 @rl_btree_iterator_create(ptr noundef %0, ptr noundef nonnull %7, ptr noundef nonnull %3) #4
  switch i32 %11, label %26 [
    i32 0, label %.preheader
    i32 3, label %22
  ]

.preheader:                                       ; preds = %10
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = call i32 @rl_btree_iterator_next(ptr noundef %12, ptr noundef null, ptr noundef nonnull %4) #4
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load i64, ptr %15, align 8, !tbaa !12
  %17 = call i32 @rl_multi_string_delete(ptr noundef %0, i64 noundef %16) #4
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %18) #4
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = call i32 @rl_btree_iterator_next(ptr noundef %19, ptr noundef null, ptr noundef nonnull %4) #4
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.lcssa = phi i32 [ %13, %.preheader ], [ %20, %.lr.ph ]
  store ptr null, ptr %3, align 8, !tbaa !5
  %.not24 = icmp eq i32 %.lcssa, 9
  br i1 %.not24, label %22, label %26

22:                                               ; preds = %10, %._crit_edge, %6
  %23 = call i32 @rl_btree_delete(ptr noundef %0, ptr noundef %7) #4
  %.not25 = icmp eq i32 %23, 0
  br i1 %.not25, label %24, label %26

24:                                               ; preds = %22
  %25 = call i32 @rl_delete(ptr noundef %0, i64 noundef %1) #4
  br label %26

26:                                               ; preds = %10, %24, %22, %._crit_edge, %2
  %.0 = phi i32 [ %5, %2 ], [ %11, %10 ], [ %.lcssa, %._crit_edge ], [ %23, %22 ], [ %25, %24 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  ret i32 %.0
}

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

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

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 = { "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 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 #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, !11, i64 40}
!10 = !{!"rl_btree", !6, i64 0, !11, i64 8, !11, i64 16, !6, i64 24, !11, i64 32, !11, i64 40}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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