; 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

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

; 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) #2

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

declare i32 @rl_btree_iterator_destroy(ptr noundef) #2

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

17:                                               ; preds = %3
  br label %77

18:                                               ; preds = %3
  %19 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %19, ptr %7, align 8, !tbaa !5
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = call i32 @rl_btree_pages(ptr noundef %20, ptr noundef %21, ptr noundef %22)
  store i32 %23, ptr %9, align 4, !tbaa !11
  %24 = load i32, ptr %9, align 4, !tbaa !11
  %25 = icmp ne i32 0, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %18
  br label %77

27:                                               ; preds = %18
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = call i32 @rl_btree_iterator_create(ptr noundef %28, ptr noundef %29, ptr noundef %8)
  store i32 %30, ptr %9, align 4, !tbaa !11
  %31 = load i32, ptr %9, align 4, !tbaa !11
  %32 = icmp ne i32 0, %31
  br i1 %32, label %33, label %34

33:                                               ; preds = %27
  br label %77

34:                                               ; preds = %27
  br label %35

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

39:                                               ; preds = %35
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %40, ptr %11, align 8, !tbaa !5
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load ptr, ptr %11, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.rl_hashkey, ptr %42, i32 0, i32 1
  %44 = load i64, ptr %43, align 8, !tbaa !13
  %45 = getelementptr inbounds i16, ptr %41, i64 %44
  store i16 1, ptr %45, align 2, !tbaa !15
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.rl_hashkey, ptr %47, i32 0, i32 1
  %49 = load i64, ptr %48, align 8, !tbaa !13
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = call i32 @rl_multi_string_pages(ptr noundef %46, i64 noundef %49, ptr noundef %50)
  store i32 %51, ptr %9, align 4, !tbaa !11
  %52 = load i32, ptr %9, align 4, !tbaa !11
  %53 = icmp ne i32 0, %52
  br i1 %53, label %54, label %55

54:                                               ; preds = %39
  br label %77

55:                                               ; preds = %39
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = load ptr, ptr %11, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.rl_hashkey, ptr %57, i32 0, i32 0
  %59 = load i64, ptr %58, align 8, !tbaa !17
  %60 = getelementptr inbounds i16, ptr %56, i64 %59
  store i16 1, ptr %60, align 2, !tbaa !15
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = load ptr, ptr %11, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.rl_hashkey, ptr %62, i32 0, i32 0
  %64 = load i64, ptr %63, align 8, !tbaa !17
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = call i32 @rl_multi_string_pages(ptr noundef %61, i64 noundef %64, ptr noundef %65)
  store i32 %66, ptr %9, align 4, !tbaa !11
  %67 = load i32, ptr %9, align 4, !tbaa !11
  %68 = icmp ne i32 0, %67
  br i1 %68, label %69, label %70

69:                                               ; preds = %55
  br label %77

70:                                               ; preds = %55
  %71 = load ptr, ptr %11, align 8, !tbaa !5
  call void @free(ptr noundef %71) #4
  br label %35, !llvm.loop !18

72:                                               ; preds = %35
  store ptr null, ptr %8, align 8, !tbaa !5
  %73 = load i32, ptr %9, align 4, !tbaa !11
  %74 = icmp ne i32 %73, 9
  br i1 %74, label %75, label %76

75:                                               ; preds = %72
  br label %77

76:                                               ; preds = %72
  store i32 0, ptr %9, align 4, !tbaa !11
  br label %77

77:                                               ; preds = %76, %75, %69, %54, %33, %26, %17
  %78 = load i32, ptr %9, align 4, !tbaa !11
  %79 = icmp ne i32 %78, 0
  br i1 %79, label %80, label %87

80:                                               ; preds = %77
  %81 = load ptr, ptr %8, align 8, !tbaa !5
  %82 = icmp ne ptr %81, null
  br i1 %82, label %83, label %86

83:                                               ; preds = %80
  %84 = load ptr, ptr %8, align 8, !tbaa !5
  %85 = call i32 @rl_btree_iterator_destroy(ptr noundef %84)
  br label %86

86:                                               ; preds = %83, %80
  br label %87

87:                                               ; preds = %86, %77
  %88 = load i32, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret i32 %88
}

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

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

declare i32 @rl_multi_string_pages(ptr noundef, i64 noundef, ptr 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 8}
!14 = !{!"rl_hashkey", !10, i64 0, !10, i64 8}
!15 = !{!16, !16, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = !{!14, !10, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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

; 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: 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 #2

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

declare i32 @rl_btree_iterator_destroy(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_hash_pages(ptr noundef %0, i64 noundef %1, ptr noundef %2) local_unnamed_addr #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  store ptr null, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  %6 = 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 %5, i32 noundef 1) #4
  %.not = icmp eq i32 %6, 2
  br i1 %.not, label %7, label %.loopexit.thread

7:                                                ; preds = %3
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = call i32 @rl_btree_pages(ptr noundef %0, ptr noundef %8, ptr noundef %2) #4
  %.not33 = icmp eq i32 %9, 0
  br i1 %.not33, label %10, label %.loopexit.thread

10:                                               ; preds = %7
  %11 = call i32 @rl_btree_iterator_create(ptr noundef %0, ptr noundef %8, ptr noundef nonnull %4) #4
  %.not34 = icmp eq i32 %11, 0
  %.pre40 = load ptr, ptr %4, align 8
  br i1 %.not34, label %.preheader, label %.loopexit

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

.lr.ph:                                           ; preds = %.preheader, %23
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 8
  %16 = load i64, ptr %15, align 8, !tbaa !9
  %17 = getelementptr inbounds i16, ptr %2, i64 %16
  store i16 1, ptr %17, align 2, !tbaa !12
  %18 = call i32 @rl_multi_string_pages(ptr noundef %0, i64 noundef %16, ptr noundef %2) #4
  %.not36 = icmp eq i32 %18, 0
  br i1 %.not36, label %19, label %.loopexit.loopexit

19:                                               ; preds = %.lr.ph
  %20 = load i64, ptr %14, align 8, !tbaa !14
  %21 = getelementptr inbounds i16, ptr %2, i64 %20
  store i16 1, ptr %21, align 2, !tbaa !12
  %22 = call i32 @rl_multi_string_pages(ptr noundef %0, i64 noundef %20, ptr noundef nonnull %2) #4
  %.not37 = icmp eq i32 %22, 0
  br i1 %.not37, label %23, label %.loopexit.loopexit

23:                                               ; preds = %19
  call void @free(ptr noundef nonnull %14) #4
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = call i32 @rl_btree_iterator_next(ptr noundef %24, ptr noundef null, ptr noundef nonnull %5) #4
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %.lr.ph, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %23, %.preheader
  %.lcssa = phi i32 [ %12, %.preheader ], [ %25, %23 ]
  %.not35 = icmp eq i32 %.lcssa, 9
  %spec.store.select = select i1 %.not35, i32 0, i32 %.lcssa
  br label %.loopexit.thread

.loopexit.loopexit:                               ; preds = %.lr.ph, %19
  %.0.ph = phi i32 [ %18, %.lr.ph ], [ %22, %19 ]
  %.pre = load ptr, ptr %4, align 8
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %10
  %27 = phi ptr [ %.pre40, %10 ], [ %.pre, %.loopexit.loopexit ]
  %.0 = phi i32 [ %11, %10 ], [ %.0.ph, %.loopexit.loopexit ]
  %.not46 = icmp eq ptr %27, null
  br i1 %.not46, label %.loopexit.thread, label %28

28:                                               ; preds = %.loopexit
  %29 = call i32 @rl_btree_iterator_destroy(ptr noundef nonnull %27) #4
  br label %.loopexit.thread

.loopexit.thread:                                 ; preds = %._crit_edge, %7, %3, %28, %.loopexit
  %.044 = phi i32 [ %.0, %28 ], [ %.0, %.loopexit ], [ %spec.store.select, %._crit_edge ], [ %9, %7 ], [ %6, %3 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  ret i32 %.044
}

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

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

declare i32 @rl_multi_string_pages(ptr noundef, i64 noundef, ptr 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 8}
!10 = !{!"rl_hashkey", !11, i64 0, !11, i64 8}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!10, !11, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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