; LLVM IR from chdb-io/chdb :: src/Functions/HTMLCharacterReference.generated.ll (ZN17HTMLCharacterHash6LookupEPKcm)

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

@_ZZN17HTMLCharacterHash6LookupEPKcmE8wordlist = external hidden constant [15512 x %struct.NameAndGlyph], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN17HTMLCharacterHash6LookupEPKcm(ptr noundef %0, i64 noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %9 = load i64, ptr %5, align 8, !tbaa !9
  %10 = icmp ule i64 %9, 32
  br i1 %10, label %11, label %61

11:                                               ; preds = %2
  %12 = load i64, ptr %5, align 8, !tbaa !9
  %13 = icmp uge i64 %12, 2
  br i1 %13, label %14, label %61

14:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load i64, ptr %5, align 8, !tbaa !9
  %17 = call noundef i32 @_ZN17HTMLCharacterHash4hashEPKcm(ptr noundef %15, i64 noundef %16)
  store i32 %17, ptr %6, align 4, !tbaa !11
  %18 = load i32, ptr %6, align 4, !tbaa !11
  %19 = icmp ule i32 %18, 15511
  br i1 %19, label %20, label %57

20:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %21 = load i32, ptr %6, align 4, !tbaa !11
  %22 = zext i32 %21 to i64
  %23 = getelementptr inbounds [15512 x %struct.NameAndGlyph], ptr @_ZZN17HTMLCharacterHash6LookupEPKcmE8wordlist, i64 0, i64 %22
  %24 = getelementptr inbounds %struct.NameAndGlyph, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 16, !tbaa !13
  store ptr %25, ptr %7, align 8, !tbaa !5
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = load i8, ptr %26, align 1, !tbaa !15
  %28 = sext i8 %27 to i32
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = load i8, ptr %29, align 1, !tbaa !15
  %31 = sext i8 %30 to i32
  %32 = icmp eq i32 %28, %31
  br i1 %32, label %33, label %53

33:                                               ; preds = %20
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i64 1
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 1
  %38 = load i64, ptr %5, align 8, !tbaa !9
  %39 = sub i64 %38, 1
  %40 = call i32 @strncmp(ptr noundef %35, ptr noundef %37, i64 noundef %39) #5
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %53, label %42

42:                                               ; preds = %33
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = load i64, ptr %5, align 8, !tbaa !9
  %45 = getelementptr inbounds i8, ptr %43, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !15
  %47 = sext i8 %46 to i32
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %53

49:                                               ; preds = %42
  %50 = load i32, ptr %6, align 4, !tbaa !11
  %51 = zext i32 %50 to i64
  %52 = getelementptr inbounds [15512 x %struct.NameAndGlyph], ptr @_ZZN17HTMLCharacterHash6LookupEPKcmE8wordlist, i64 0, i64 %51
  store ptr %52, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %54

53:                                               ; preds = %42, %33, %20
  store i32 0, ptr %8, align 4
  br label %54

54:                                               ; preds = %53, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %55 = load i32, ptr %8, align 4
  switch i32 %55, label %58 [
    i32 0, label %56
  ]

56:                                               ; preds = %54
  br label %57

57:                                               ; preds = %56, %14
  store i32 0, ptr %8, align 4
  br label %58

58:                                               ; preds = %57, %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %59 = load i32, ptr %8, align 4
  switch i32 %59, label %64 [
    i32 0, label %60
    i32 1, label %62
  ]

60:                                               ; preds = %58
  br label %61

61:                                               ; preds = %60, %11, %2
  store ptr null, ptr %3, align 8
  br label %62

62:                                               ; preds = %61, %58
  %63 = load ptr, ptr %3, align 8
  ret ptr %63

64:                                               ; preds = %58
  unreachable
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN17HTMLCharacterHash4hashEPKcm(ptr noundef, i64 noundef) #2 align 2

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strncmp(ptr noundef, ptr noundef, i64 noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint mustprogress 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 willreturn memory(read) "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 }
attributes #5 = { nounwind willreturn memory(read) }

!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 = !{!14, !6, i64 0}
!14 = !{!"_ZTS12NameAndGlyph", !6, i64 0, !6, i64 8}
!15 = !{!7, !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"

%struct.NameAndGlyph = type { ptr, ptr }

@_ZZN17HTMLCharacterHash6LookupEPKcmE8wordlist = external hidden constant [15512 x %struct.NameAndGlyph], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN17HTMLCharacterHash6LookupEPKcm(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = add i64 %1, -2
  %or.cond = icmp ult i64 %3, 31
  br i1 %or.cond, label %4, label %23

4:                                                ; preds = %2
  %5 = tail call noundef i32 @_ZN17HTMLCharacterHash4hashEPKcm(ptr noundef %0, i64 noundef %1)
  %6 = icmp ult i32 %5, 15512
  br i1 %6, label %7, label %.thread

7:                                                ; preds = %4
  %8 = zext nneg i32 %5 to i64
  %9 = getelementptr inbounds [15512 x %struct.NameAndGlyph], ptr @_ZZN17HTMLCharacterHash6LookupEPKcmE8wordlist, i64 0, i64 %8
  %10 = load ptr, ptr %9, align 16, !tbaa !5
  %11 = load i8, ptr %0, align 1, !tbaa !10
  %12 = load i8, ptr %10, align 1, !tbaa !10
  %13 = icmp eq i8 %11, %12
  br i1 %13, label %14, label %.thread

14:                                               ; preds = %7
  %15 = getelementptr inbounds i8, ptr %0, i64 1
  %16 = getelementptr inbounds i8, ptr %10, i64 1
  %17 = add nsw i64 %1, -1
  %18 = tail call i32 @strncmp(ptr noundef nonnull %15, ptr noundef nonnull %16, i64 noundef %17) #3
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %19, label %.thread

19:                                               ; preds = %14
  %20 = getelementptr inbounds i8, ptr %10, i64 %1
  %21 = load i8, ptr %20, align 1, !tbaa !10
  %22 = icmp eq i8 %21, 0
  br i1 %22, label %23, label %.thread

.thread:                                          ; preds = %4, %19, %14, %7
  br label %23

23:                                               ; preds = %2, %.thread, %19
  %.3 = phi ptr [ %9, %19 ], [ null, %.thread ], [ null, %2 ]
  ret ptr %.3
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN17HTMLCharacterHash4hashEPKcm(ptr noundef, i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strncmp(ptr nocapture noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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 mustprogress 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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 willreturn memory(read) }

!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 0}
!6 = !{!"_ZTS12NameAndGlyph", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!8, !8, i64 0}


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