; LLVM IR from m-boutaleb/LZS :: src (hash_service)

; 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"

@collisions = external dso_local global i32, align 4
@history_pos_size = external hidden global i32, align 4
@history_pos = external hidden global [696623 x i32], align 16

; Function Attrs: nounwind uwtable
declare dso_local i32 @is_match_table(ptr noundef, i16 noundef zeroext) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @hash(ptr noundef, i16 noundef zeroext) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

16:                                               ; preds = %3
  store i32 1, ptr %8, align 4
  br label %41

17:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %18 = load i32, ptr %7, align 4, !tbaa !11
  %19 = sub i32 %18, 696623
  store i32 %19, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i16, ptr %5, align 2, !tbaa !9
  %22 = call i32 @hash(ptr noundef %20, i16 noundef zeroext %21)
  %23 = zext i32 %22 to i64
  store i64 %23, ptr %10, align 8, !tbaa !13
  %24 = load i32, ptr %9, align 4, !tbaa !11
  %25 = zext i32 %24 to i64
  %26 = load i64, ptr %10, align 8, !tbaa !13
  %27 = icmp ne i64 %25, %26
  %28 = zext i1 %27 to i64
  %29 = select i1 %27, i32 1, i32 0
  %30 = load i32, ptr @collisions, align 4, !tbaa !11
  %31 = add i32 %30, %29
  store i32 %31, ptr @collisions, align 4, !tbaa !11
  %32 = load i32, ptr %9, align 4, !tbaa !11
  %33 = load i32, ptr @history_pos_size, align 4, !tbaa !11
  %34 = add i32 %33, 1
  store i32 %34, ptr @history_pos_size, align 4, !tbaa !11
  %35 = zext i32 %33 to i64
  %36 = getelementptr inbounds [696623 x i32], ptr @history_pos, i64 0, i64 %35
  store i32 %32, ptr %36, align 4, !tbaa !11
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load i16, ptr %5, align 2, !tbaa !9
  %39 = load i32, ptr %9, align 4, !tbaa !11
  %40 = load i16, ptr %6, align 2, !tbaa !9
  call void @set_value(ptr noundef %37, i16 noundef zeroext %38, i32 noundef %39, i16 noundef zeroext %40)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  store i32 0, ptr %8, align 4
  br label %41

41:                                               ; preds = %17, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %42 = load i32, ptr %8, align 4
  switch i32 %42, label %44 [
    i32 0, label %43
    i32 1, label %43
  ]

43:                                               ; preds = %41, %41
  ret void

44:                                               ; preds = %41
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden void @set_value(ptr noundef, i16 noundef zeroext, i32 noundef, i16 noundef zeroext) #0

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #3 = { 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 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, 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"

@collisions = external dso_local local_unnamed_addr global i32, align 4
@history_pos_size = external hidden local_unnamed_addr global i32, align 4
@history_pos = external hidden local_unnamed_addr global [696623 x i32], align 16

; Function Attrs: nounwind uwtable
declare dso_local i32 @is_match_table(ptr noundef, i16 noundef zeroext) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @hash(ptr noundef, i16 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @add_to_table(ptr noundef %0, i16 noundef zeroext %1, i16 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = tail call i32 @is_match_table(ptr noundef %0, i16 noundef zeroext %1)
  %5 = icmp ult i32 %4, 696623
  br i1 %5, label %16, label %6

6:                                                ; preds = %3
  %7 = add i32 %4, -696623
  %8 = tail call i32 @hash(ptr noundef %0, i16 noundef zeroext %1)
  %.not = icmp ne i32 %7, %8
  %9 = zext i1 %.not to i32
  %10 = load i32, ptr @collisions, align 4, !tbaa !5
  %11 = add i32 %10, %9
  store i32 %11, ptr @collisions, align 4, !tbaa !5
  %12 = load i32, ptr @history_pos_size, align 4, !tbaa !5
  %13 = add i32 %12, 1
  store i32 %13, ptr @history_pos_size, align 4, !tbaa !5
  %14 = zext i32 %12 to i64
  %15 = getelementptr inbounds [696623 x i32], ptr @history_pos, i64 0, i64 %14
  store i32 %7, ptr %15, align 4, !tbaa !5
  tail call void @set_value(ptr noundef %0, i16 noundef zeroext %1, i32 noundef %7, i16 noundef zeroext %2)
  br label %16

16:                                               ; preds = %3, %6
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @set_value(ptr noundef, i16 noundef zeroext, i32 noundef, i16 noundef zeroext) local_unnamed_addr #0

attributes #0 = { 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 #1 = { inlinehint 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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass