; LLVM IR from fcimeson/cbTSP :: cbLKH/SRC (Hashing)

; 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.HashTable = type { [65521 x %struct.HashTableEntry], i32 }
%struct.HashTableEntry = type { i32, i64 }

; 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 uwtable
define dso_local void @HashInsert(ptr noundef %0, i32 noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = urem i32 %10, 65521
  store i32 %11, ptr %7, align 4, !tbaa !9
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.HashTable, ptr %12, i32 0, i32 1
  %14 = load i32, ptr %13, align 8, !tbaa !13
  %15 = sitofp i32 %14 to double
  %16 = fcmp oge double %15, 0x40E7FE9800000000
  br i1 %16, label %17, label %29

17:                                               ; preds = %3
  %18 = load i64, ptr %6, align 8, !tbaa !11
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.HashTable, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [65521 x %struct.HashTableEntry], ptr %20, i64 0, i64 %22
  %24 = getelementptr inbounds %struct.HashTableEntry, ptr %23, i32 0, i32 1
  %25 = load i64, ptr %24, align 8, !tbaa !15
  %26 = icmp sgt i64 %18, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %17
  store i32 1, ptr %8, align 4
  br label %71

28:                                               ; preds = %17
  br label %56

29:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = urem i32 %30, 97
  %32 = add i32 %31, 1
  store i32 %32, ptr %9, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %50, %29
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.HashTable, ptr %34, i32 0, i32 0
  %36 = load i32, ptr %7, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [65521 x %struct.HashTableEntry], ptr %35, i64 0, i64 %37
  %39 = getelementptr inbounds %struct.HashTableEntry, ptr %38, i32 0, i32 1
  %40 = load i64, ptr %39, align 8, !tbaa !15
  %41 = icmp ne i64 %40, -9223372036854775808
  br i1 %41, label %42, label %51

42:                                               ; preds = %33
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = load i32, ptr %7, align 4, !tbaa !9
  %45 = sub nsw i32 %44, %43
  store i32 %45, ptr %7, align 4, !tbaa !9
  %46 = icmp slt i32 %45, 0
  br i1 %46, label %47, label %50

47:                                               ; preds = %42
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = add nsw i32 %48, 65521
  store i32 %49, ptr %7, align 4, !tbaa !9
  br label %50

50:                                               ; preds = %47, %42
  br label %33, !llvm.loop !17

51:                                               ; preds = %33
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.HashTable, ptr %52, i32 0, i32 1
  %54 = load i32, ptr %53, align 8, !tbaa !13
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %53, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %56

56:                                               ; preds = %51, %28
  %57 = load i32, ptr %5, align 4, !tbaa !9
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.HashTable, ptr %58, i32 0, i32 0
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [65521 x %struct.HashTableEntry], ptr %59, i64 0, i64 %61
  %63 = getelementptr inbounds %struct.HashTableEntry, ptr %62, i32 0, i32 0
  store i32 %57, ptr %63, align 8, !tbaa !19
  %64 = load i64, ptr %6, align 8, !tbaa !11
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.HashTable, ptr %65, i32 0, i32 0
  %67 = load i32, ptr %7, align 4, !tbaa !9
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [65521 x %struct.HashTableEntry], ptr %66, i64 0, i64 %68
  %70 = getelementptr inbounds %struct.HashTableEntry, ptr %69, i32 0, i32 1
  store i64 %64, ptr %70, align 8, !tbaa !15
  store i32 0, ptr %8, align 4
  br label %71

71:                                               ; preds = %56, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  %72 = load i32, ptr %8, align 4
  switch i32 %72, label %74 [
    i32 0, label %73
    i32 1, label %73
  ]

73:                                               ; preds = %71, %71
  ret void

74:                                               ; preds = %71
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !10, i64 1048336}
!14 = !{!"HashTable", !7, i64 0, !10, i64 1048336}
!15 = !{!16, !12, i64 8}
!16 = !{!"HashTableEntry", !10, i64 0, !12, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!16, !10, i64 0}


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

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @HashInsert(ptr nocapture noundef %0, i32 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = urem i32 %1, 65521
  %5 = getelementptr inbounds i8, ptr %0, i64 1048336
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = icmp sgt i32 %6, 49140
  br i1 %7, label %8, label %13

8:                                                ; preds = %3
  %9 = zext nneg i32 %4 to i64
  %10 = getelementptr inbounds [65521 x %struct.HashTableEntry], ptr %0, i64 0, i64 %9, i32 1
  %11 = load i64, ptr %10, align 8, !tbaa !10
  %12 = icmp slt i64 %11, %2
  br i1 %12, label %28, label %25

13:                                               ; preds = %3
  %14 = urem i32 %1, 97
  %.neg = xor i32 %14, -1
  %15 = zext nneg i32 %4 to i64
  %16 = getelementptr inbounds [65521 x %struct.HashTableEntry], ptr %0, i64 0, i64 %15, i32 1
  %17 = load i64, ptr %16, align 8, !tbaa !10
  %.not19 = icmp eq i64 %17, -9223372036854775808
  br i1 %.not19, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %13, %.lr.ph
  %.020 = phi i32 [ %spec.select, %.lr.ph ], [ %4, %13 ]
  %18 = add i32 %.020, %.neg
  %19 = icmp slt i32 %18, 0
  %20 = add nsw i32 %18, 65521
  %spec.select = select i1 %19, i32 %20, i32 %18
  %21 = zext nneg i32 %spec.select to i64
  %22 = getelementptr inbounds [65521 x %struct.HashTableEntry], ptr %0, i64 0, i64 %21, i32 1
  %23 = load i64, ptr %22, align 8, !tbaa !10
  %.not = icmp eq i64 %23, -9223372036854775808
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %13
  %.pre.pre-phi = phi i64 [ %15, %13 ], [ %21, %.lr.ph ]
  %24 = add nsw i32 %6, 1
  store i32 %24, ptr %5, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %8, %._crit_edge
  %.pre-phi = phi i64 [ %9, %8 ], [ %.pre.pre-phi, %._crit_edge ]
  %26 = getelementptr inbounds [65521 x %struct.HashTableEntry], ptr %0, i64 0, i64 %.pre-phi
  store i32 %1, ptr %26, align 8, !tbaa !15
  %27 = getelementptr inbounds i8, ptr %26, i64 8
  store i64 %2, ptr %27, align 8, !tbaa !10
  br label %28

28:                                               ; preds = %8, %25
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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" }

!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, !9, i64 1048336}
!6 = !{!"HashTable", !7, i64 0, !9, i64 1048336}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!11, !12, i64 8}
!11 = !{!"HashTableEntry", !9, i64 0, !12, i64 8}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!11, !9, i64 0}


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