; LLVM IR from qc-tum/chemtensor :: src/util (hash_table)

; 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.hash_table_iterator = type { ptr, i64, ptr }
%struct.hash_table_entry = type { ptr, ptr, ptr }
%struct.hash_table = type { ptr, ptr, i64, ptr, i64, i64 }

@.str.1 = external hidden unnamed_addr constant [73 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [43 x i8], align 1
@__PRETTY_FUNCTION__.hash_table_iterator_next = external hidden unnamed_addr constant [61 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @hash_table_iterator_next(ptr noundef %0) #1 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = call zeroext i1 @hash_table_iterator_is_valid(ptr noundef %4)
  br i1 %5, label %7, label %6

6:                                                ; preds = %1
  store i1 false, ptr %2, align 1
  br label %101

7:                                                ; preds = %1
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.hash_table_iterator, ptr %8, i32 0, i32 2
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = getelementptr inbounds %struct.hash_table_entry, ptr %10, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !12
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %22

14:                                               ; preds = %7
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.hash_table_iterator, ptr %15, i32 0, i32 2
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.hash_table_entry, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.hash_table_iterator, ptr %20, i32 0, i32 2
  store ptr %19, ptr %21, align 8, !tbaa !9
  store i1 true, ptr %2, align 1
  br label %101

22:                                               ; preds = %7
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.hash_table_iterator, ptr %23, i32 0, i32 1
  %25 = load i64, ptr %24, align 8, !tbaa !14
  %26 = add nsw i64 %25, 1
  store i64 %26, ptr %24, align 8, !tbaa !14
  br label %27

27:                                               ; preds = %51, %22
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.hash_table_iterator, ptr %28, i32 0, i32 1
  %30 = load i64, ptr %29, align 8, !tbaa !14
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.hash_table_iterator, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !15
  %34 = getelementptr inbounds %struct.hash_table, ptr %33, i32 0, i32 4
  %35 = load i64, ptr %34, align 8, !tbaa !16
  %36 = icmp slt i64 %30, %35
  br i1 %36, label %37, label %56

37:                                               ; preds = %27
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.hash_table_iterator, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !15
  %41 = getelementptr inbounds %struct.hash_table, ptr %40, i32 0, i32 3
  %42 = load ptr, ptr %41, align 8, !tbaa !18
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.hash_table_iterator, ptr %43, i32 0, i32 1
  %45 = load i64, ptr %44, align 8, !tbaa !14
  %46 = getelementptr inbounds ptr, ptr %42, i64 %45
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %50

49:                                               ; preds = %37
  br label %56

50:                                               ; preds = %37
  br label %51

51:                                               ; preds = %50
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.hash_table_iterator, ptr %52, i32 0, i32 1
  %54 = load i64, ptr %53, align 8, !tbaa !14
  %55 = add nsw i64 %54, 1
  store i64 %55, ptr %53, align 8, !tbaa !14
  br label %27, !llvm.loop !19

56:                                               ; preds = %49, %27
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.hash_table_iterator, ptr %57, i32 0, i32 1
  %59 = load i64, ptr %58, align 8, !tbaa !14
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.hash_table_iterator, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !15
  %63 = getelementptr inbounds %struct.hash_table, ptr %62, i32 0, i32 4
  %64 = load i64, ptr %63, align 8, !tbaa !16
  %65 = icmp sle i64 %59, %64
  br i1 %65, label %66, label %67

66:                                               ; preds = %56
  br label %68

67:                                               ; preds = %56
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 199, ptr noundef @__PRETTY_FUNCTION__.hash_table_iterator_next) #2
  unreachable

68:                                               ; preds = %66
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.hash_table_iterator, ptr %69, i32 0, i32 1
  %71 = load i64, ptr %70, align 8, !tbaa !14
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.hash_table_iterator, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !15
  %75 = getelementptr inbounds %struct.hash_table, ptr %74, i32 0, i32 4
  %76 = load i64, ptr %75, align 8, !tbaa !16
  %77 = icmp eq i64 %71, %76
  br i1 %77, label %78, label %81

78:                                               ; preds = %68
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.hash_table_iterator, ptr %79, i32 0, i32 2
  store ptr null, ptr %80, align 8, !tbaa !9
  store i1 false, ptr %2, align 1
  br label %101

81:                                               ; preds = %68
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.hash_table_iterator, ptr %82, i32 0, i32 0
  %84 = load ptr, ptr %83, align 8, !tbaa !15
  %85 = getelementptr inbounds %struct.hash_table, ptr %84, i32 0, i32 3
  %86 = load ptr, ptr %85, align 8, !tbaa !18
  %87 = load ptr, ptr %3, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.hash_table_iterator, ptr %87, i32 0, i32 1
  %89 = load i64, ptr %88, align 8, !tbaa !14
  %90 = getelementptr inbounds ptr, ptr %86, i64 %89
  %91 = load ptr, ptr %90, align 8, !tbaa !5
  %92 = load ptr, ptr %3, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.hash_table_iterator, ptr %92, i32 0, i32 2
  store ptr %91, ptr %93, align 8, !tbaa !9
  %94 = load ptr, ptr %3, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.hash_table_iterator, ptr %94, i32 0, i32 2
  %96 = load ptr, ptr %95, align 8, !tbaa !9
  %97 = icmp ne ptr %96, null
  br i1 %97, label %98, label %99

98:                                               ; preds = %81
  br label %100

99:                                               ; preds = %81
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 207, ptr noundef @__PRETTY_FUNCTION__.hash_table_iterator_next) #2
  unreachable

100:                                              ; preds = %98
  store i1 true, ptr %2, align 1
  br label %101

101:                                              ; preds = %100, %78, %14, %6
  %102 = load i1, ptr %2, align 1
  ret i1 %102
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @hash_table_iterator_is_valid(ptr noundef) #1

attributes #0 = { noreturn 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 #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 = { noreturn 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, !6, i64 16}
!10 = !{!"hash_table_iterator", !6, i64 0, !11, i64 8, !6, i64 16}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"hash_table_entry", !6, i64 0, !6, i64 8, !6, i64 16}
!14 = !{!10, !11, i64 8}
!15 = !{!10, !6, i64 0}
!16 = !{!17, !11, i64 32}
!17 = !{!"hash_table", !6, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !11, i64 32, !11, i64 40}
!18 = !{!17, !6, i64 24}
!19 = distinct !{!19, !20}
!20 = !{!"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"

@.str.1 = external hidden unnamed_addr constant [73 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [43 x i8], align 1
@__PRETTY_FUNCTION__.hash_table_iterator_next = external hidden unnamed_addr constant [61 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @hash_table_iterator_next(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call zeroext i1 @hash_table_iterator_is_valid(ptr noundef %0)
  br i1 %2, label %3, label %31

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %5, align 8, !tbaa !11
  %.not = icmp ne ptr %6, null
  br i1 %.not, label %.sink.split, label %7

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !13
  %10 = load ptr, ptr %0, align 8, !tbaa !14
  %11 = getelementptr inbounds i8, ptr %10, i64 32
  %12 = load i64, ptr %11, align 8, !tbaa !15
  %13 = getelementptr inbounds i8, ptr %10, i64 24
  %14 = add nsw i64 %9, 1
  %smax = tail call i64 @llvm.smax.i64(i64 %12, i64 %14)
  %15 = add nsw i64 %smax, -1
  br label %16

16:                                               ; preds = %18, %7
  %storemerge.in = phi i64 [ %9, %7 ], [ %storemerge, %18 ]
  %storemerge = add nsw i64 %storemerge.in, 1
  %17 = icmp slt i64 %storemerge, %12
  br i1 %17, label %18, label %22

18:                                               ; preds = %16
  %19 = load ptr, ptr %13, align 8, !tbaa !17
  %20 = getelementptr inbounds ptr, ptr %19, i64 %storemerge
  %21 = load ptr, ptr %20, align 8, !tbaa !18
  %.not24 = icmp eq ptr %21, null
  br i1 %.not24, label %16, label %22, !llvm.loop !19

22:                                               ; preds = %18, %16
  %storemerge.in.lcssa = phi i64 [ %storemerge.in, %18 ], [ %15, %16 ]
  %storemerge.lcssa = phi i64 [ %storemerge, %18 ], [ %smax, %16 ]
  store i64 %storemerge.lcssa, ptr %8, align 8, !tbaa !13
  %.not25.not = icmp slt i64 %storemerge.in.lcssa, %12
  br i1 %.not25.not, label %24, label %23

23:                                               ; preds = %22
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 199, ptr noundef nonnull @__PRETTY_FUNCTION__.hash_table_iterator_next) #3
  unreachable

24:                                               ; preds = %22
  %25 = icmp eq i64 %storemerge.lcssa, %12
  br i1 %25, label %.sink.split, label %26

26:                                               ; preds = %24
  %27 = load ptr, ptr %13, align 8, !tbaa !17
  %28 = getelementptr inbounds ptr, ptr %27, i64 %storemerge.lcssa
  %29 = load ptr, ptr %28, align 8, !tbaa !18
  store ptr %29, ptr %4, align 8, !tbaa !5
  %.not26 = icmp eq ptr %29, null
  br i1 %.not26, label %30, label %31

30:                                               ; preds = %26
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 207, ptr noundef nonnull @__PRETTY_FUNCTION__.hash_table_iterator_next) #3
  unreachable

.sink.split:                                      ; preds = %24, %3
  %.sink = phi ptr [ %6, %3 ], [ null, %24 ]
  store ptr %.sink, ptr %4, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %.sink.split, %26, %1
  %.0 = phi i1 [ false, %1 ], [ true, %26 ], [ %.not, %.sink.split ]
  ret i1 %.0
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @hash_table_iterator_is_valid(ptr noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #2

attributes #0 = { noreturn 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 #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { noreturn 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, !7, i64 16}
!6 = !{!"hash_table_iterator", !7, i64 0, !10, i64 8, !7, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"hash_table_entry", !7, i64 0, !7, i64 8, !7, i64 16}
!13 = !{!6, !10, i64 8}
!14 = !{!6, !7, i64 0}
!15 = !{!16, !10, i64 32}
!16 = !{!"hash_table", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24, !10, i64 32, !10, i64 40}
!17 = !{!16, !7, i64 24}
!18 = !{!7, !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InstCombinePass,LCSSAPass,LICMPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass