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

; 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_hashkey = type { i64, i64 }

@rl_data_type_btree_hash_sha1_hashkey = external global %struct.rl_data_type, align 8
@rl_btree_type_hash_sha1_hashkey = 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

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

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

; 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_iterator_create(ptr noundef, ptr noundef, ptr noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_hash_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 ptr, 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
  store ptr null, ptr %7, align 8, !tbaa !5
  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_hashkey, i64 noundef %11, ptr noundef @rl_btree_type_hash_sha1_hashkey, 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 %61

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 %3, align 8, !tbaa !5
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call i32 @rl_btree_iterator_create(ptr noundef %18, ptr noundef %19, ptr noundef %6)
  store i32 %20, ptr %8, align 4, !tbaa !11
  %21 = load i32, ptr %8, align 4, !tbaa !11
  %22 = icmp ne i32 0, %21
  br i1 %22, label %23, label %24

23:                                               ; preds = %16
  br label %61

24:                                               ; preds = %16
  br label %25

25:                                               ; preds = %29, %24
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = call i32 @rl_btree_iterator_next(ptr noundef %26, ptr noundef null, ptr noundef %9)
  store i32 %27, ptr %8, align 4, !tbaa !11
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %42

29:                                               ; preds = %25
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %30, ptr %7, align 8, !tbaa !5
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.rl_hashkey, ptr %32, i32 0, i32 0
  %34 = load i64, ptr %33, align 8, !tbaa !13
  %35 = call i32 @rl_multi_string_delete(ptr noundef %31, i64 noundef %34)
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.rl_hashkey, ptr %37, i32 0, i32 1
  %39 = load i64, ptr %38, align 8, !tbaa !15
  %40 = call i32 @rl_multi_string_delete(ptr noundef %36, i64 noundef %39)
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  call void @free(ptr noundef %41) #4
  br label %25, !llvm.loop !16

42:                                               ; preds = %25
  store ptr null, ptr %6, align 8, !tbaa !5
  %43 = load i32, ptr %8, align 4, !tbaa !11
  %44 = icmp ne i32 %43, 9
  br i1 %44, label %45, label %46

45:                                               ; preds = %42
  br label %61

46:                                               ; preds = %42
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = call i32 @rl_btree_delete(ptr noundef %47, ptr noundef %48)
  store i32 %49, ptr %8, align 4, !tbaa !11
  %50 = load i32, ptr %8, align 4, !tbaa !11
  %51 = icmp ne i32 0, %50
  br i1 %51, label %52, label %53

52:                                               ; preds = %46
  br label %61

53:                                               ; preds = %46
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = load i64, ptr %4, align 8, !tbaa !9
  %56 = call i32 @rl_delete(ptr noundef %54, i64 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 %61

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

61:                                               ; preds = %60, %59, %52, %45, %23, %15
  %62 = 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 %62
}

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 "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 0}
!14 = !{!"rl_hashkey", !10, i64 0, !10, i64 8}
!15 = !{!14, !10, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"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_hashkey = external global %struct.rl_data_type, align 8
@rl_btree_type_hash_sha1_hashkey = 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

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

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

; 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_iterator_create(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_hash_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_hashkey, i64 noundef %1, ptr noundef nonnull @rl_btree_type_hash_sha1_hashkey, ptr noundef nonnull %4, i32 noundef 1) #4
  %.not = icmp eq i32 %5, 2
  br i1 %.not, label %6, label %25

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

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

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

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.lcssa = phi i32 [ %10, %.preheader ], [ %19, %.lr.ph ]
  store ptr null, ptr %3, align 8, !tbaa !5
  %.not23 = icmp eq i32 %.lcssa, 9
  br i1 %.not23, label %21, label %25

21:                                               ; preds = %._crit_edge
  %22 = call i32 @rl_btree_delete(ptr noundef %0, ptr noundef %7) #4
  %.not24 = icmp eq i32 %22, 0
  br i1 %.not24, label %23, label %25

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

25:                                               ; preds = %23, %21, %._crit_edge, %6, %2
  %.0 = phi i32 [ %5, %2 ], [ %8, %6 ], [ %.lcssa, %._crit_edge ], [ %22, %21 ], [ %24, %23 ]
  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 #1

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #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 0}
!10 = !{!"rl_hashkey", !11, i64 0, !11, i64 8}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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