; LLVM IR from tuplex/tuplex :: tuplex/utils/src (int_hashmap)

; 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._int64_hashmap_map = type { i32, i32, ptr }
%struct._int_hashmap_element = type { i64, i32, ptr }

@.str = external hidden unnamed_addr constant [26 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [79 x i8], align 1
@__PRETTY_FUNCTION__.int64_hashmap_put = external hidden unnamed_addr constant [52 x i8], align 1

; 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: mustprogress uwtable
declare dso_local noundef i32 @_Z12hashmap_hashPvm(ptr noundef, i64 noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z20int64_hashmap_rehashPv(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local i32 @int64_hashmap_put(ptr noundef %0, i64 noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %11, ptr %9, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = call noundef i32 @_Z12hashmap_hashPvm(ptr noundef %12, i64 noundef %13)
  store i32 %14, ptr %8, align 4, !tbaa !11
  br label %15

15:                                               ; preds = %23, %3
  %16 = load i32, ptr %8, align 4, !tbaa !11
  %17 = icmp eq i32 %16, -2
  br i1 %17, label %18, label %27

18:                                               ; preds = %15
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call noundef i32 @_Z20int64_hashmap_rehashPv(ptr noundef %19)
  %21 = icmp eq i32 %20, -1
  br i1 %21, label %22, label %23

22:                                               ; preds = %18
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %81

23:                                               ; preds = %18
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load i64, ptr %6, align 8, !tbaa !9
  %26 = call noundef i32 @_Z12hashmap_hashPvm(ptr noundef %24, i64 noundef %25)
  store i32 %26, ptr %8, align 4, !tbaa !11
  br label %15, !llvm.loop !13

27:                                               ; preds = %15
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct._int64_hashmap_map, ptr %29, i32 0, i32 2
  %31 = load ptr, ptr %30, align 8, !tbaa !15
  %32 = load i32, ptr %8, align 4, !tbaa !11
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds %struct._int_hashmap_element, ptr %31, i64 %33
  %35 = getelementptr inbounds %struct._int_hashmap_element, ptr %34, i32 0, i32 2
  store ptr %28, ptr %35, align 8, !tbaa !17
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._int64_hashmap_map, ptr %36, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !15
  %39 = load i32, ptr %8, align 4, !tbaa !11
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds %struct._int_hashmap_element, ptr %38, i64 %40
  %42 = getelementptr inbounds %struct._int_hashmap_element, ptr %41, i32 0, i32 1
  %43 = load i32, ptr %42, align 8, !tbaa !19
  %44 = icmp eq i32 %43, 0
  br i1 %44, label %45, label %58

45:                                               ; preds = %27
  %46 = load i64, ptr %6, align 8, !tbaa !9
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._int64_hashmap_map, ptr %47, i32 0, i32 2
  %49 = load ptr, ptr %48, align 8, !tbaa !15
  %50 = load i32, ptr %8, align 4, !tbaa !11
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds %struct._int_hashmap_element, ptr %49, i64 %51
  %53 = getelementptr inbounds %struct._int_hashmap_element, ptr %52, i32 0, i32 0
  store i64 %46, ptr %53, align 8, !tbaa !20
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._int64_hashmap_map, ptr %54, i32 0, i32 1
  %56 = load i32, ptr %55, align 4, !tbaa !21
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %55, align 4, !tbaa !21
  br label %73

58:                                               ; preds = %27
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._int64_hashmap_map, ptr %59, i32 0, i32 2
  %61 = load ptr, ptr %60, align 8, !tbaa !15
  %62 = load i32, ptr %8, align 4, !tbaa !11
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds %struct._int_hashmap_element, ptr %61, i64 %63
  %65 = getelementptr inbounds %struct._int_hashmap_element, ptr %64, i32 0, i32 0
  %66 = load i64, ptr %65, align 8, !tbaa !20
  %67 = load i64, ptr %6, align 8, !tbaa !9
  %68 = icmp eq i64 %66, %67
  br i1 %68, label %69, label %70

69:                                               ; preds = %58
  br label %72

70:                                               ; preds = %58
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 177, ptr noundef @__PRETTY_FUNCTION__.int64_hashmap_put) #4
  unreachable

71:                                               ; No predecessors!
  br label %72

72:                                               ; preds = %71, %69
  br label %73

73:                                               ; preds = %72, %45
  %74 = load ptr, ptr %9, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct._int64_hashmap_map, ptr %74, i32 0, i32 2
  %76 = load ptr, ptr %75, align 8, !tbaa !15
  %77 = load i32, ptr %8, align 4, !tbaa !11
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds %struct._int_hashmap_element, ptr %76, i64 %78
  %80 = getelementptr inbounds %struct._int_hashmap_element, ptr %79, i32 0, i32 1
  store i32 1, ptr %80, align 8, !tbaa !19
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %81

81:                                               ; preds = %73, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %82 = load i32, ptr %4, align 4
  ret i32 %82
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 "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 }
attributes #4 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !6, i64 8}
!16 = !{!"_ZTS18_int64_hashmap_map", !12, i64 0, !12, i64 4, !6, i64 8}
!17 = !{!18, !6, i64 16}
!18 = !{!"_ZTS20_int_hashmap_element", !10, i64 0, !12, i64 8, !6, i64 16}
!19 = !{!18, !12, i64 8}
!20 = !{!18, !10, i64 0}
!21 = !{!16, !12, i64 4}


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

@.str = external hidden unnamed_addr constant [26 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [79 x i8], align 1
@__PRETTY_FUNCTION__.int64_hashmap_put = external hidden unnamed_addr constant [52 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z12hashmap_hashPvm(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z20int64_hashmap_rehashPv(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local range(i32 -1, 1) i32 @int64_hashmap_put(ptr noundef %0, i64 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = tail call noundef i32 @_Z12hashmap_hashPvm(ptr noundef %0, i64 noundef %1)
  %5 = icmp eq i32 %4, -2
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3, %8
  %6 = tail call noundef i32 @_Z20int64_hashmap_rehashPv(ptr noundef %0)
  %7 = icmp eq i32 %6, -1
  br i1 %7, label %.loopexit, label %8

8:                                                ; preds = %.lr.ph
  %9 = tail call noundef i32 @_Z12hashmap_hashPvm(ptr noundef %0, i64 noundef %1)
  %10 = icmp eq i32 %9, -2
  br i1 %10, label %.lr.ph, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %8, %3
  %.021.lcssa = phi i32 [ %4, %3 ], [ %9, %8 ]
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !7
  %13 = sext i32 %.021.lcssa to i64
  %14 = getelementptr inbounds %struct._int_hashmap_element, ptr %12, i64 %13, i32 2
  store ptr %2, ptr %14, align 8, !tbaa !13
  %15 = getelementptr inbounds %struct._int_hashmap_element, ptr %12, i64 %13
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  %17 = load i32, ptr %16, align 8, !tbaa !16
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %23

19:                                               ; preds = %._crit_edge
  store i64 %1, ptr %15, align 8, !tbaa !17
  %20 = getelementptr inbounds i8, ptr %0, i64 4
  %21 = load i32, ptr %20, align 4, !tbaa !18
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %20, align 4, !tbaa !18
  br label %27

23:                                               ; preds = %._crit_edge
  %24 = load i64, ptr %15, align 8, !tbaa !17
  %25 = icmp eq i64 %24, %1
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 177, ptr noundef nonnull @__PRETTY_FUNCTION__.int64_hashmap_put) #2
  unreachable

27:                                               ; preds = %23, %19
  %28 = getelementptr inbounds %struct._int_hashmap_element, ptr %12, i64 %13, i32 1
  store i32 1, ptr %28, align 8, !tbaa !16
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %27
  %.0 = phi i32 [ 0, %27 ], [ -1, %.lr.ph ]
  ret i32 %.0
}

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

attributes #0 = { mustprogress 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 #1 = { 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 #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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !12, i64 8}
!8 = !{!"_ZTS18_int64_hashmap_map", !9, i64 0, !9, i64 4, !12, i64 8}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"any pointer", !10, i64 0}
!13 = !{!14, !12, i64 16}
!14 = !{!"_ZTS20_int_hashmap_element", !15, i64 0, !9, i64 8, !12, i64 16}
!15 = !{!"long", !10, i64 0}
!16 = !{!14, !9, i64 8}
!17 = !{!14, !15, i64 0}
!18 = !{!8, !9, i64 4}


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