; LLVM IR from chdb-io/chdb :: base/poco/Foundation/src (Unicode)

; 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.ucd_record = type { i8, i8, i8, i8, i32 }
%"struct.Poco::Unicode::CharacterProperties" = type { i32, i32, i32 }

@_pcre_ucd_records = external global [0 x %struct.ucd_record], align 4
@_pcre_ucd_stage2 = external constant [0 x i16], align 2
@_pcre_ucd_stage1 = external constant [0 x i8], align 1
@_pcre_ucp_gentype = external constant [0 x i32], align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4Poco7Unicode10propertiesEiRNS0_19CharacterPropertiesE(i32 noundef %0, ptr noundef nonnull align 4 dereferenceable(12) %1) #0 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 0
  br i1 %7, label %11, label %8

8:                                                ; preds = %2
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = icmp sgt i32 %9, 1114111
  br i1 %10, label %11, label %12

11:                                               ; preds = %8, %2
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %11, %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = sdiv i32 %13, 128
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [0 x i8], ptr @_pcre_ucd_stage1, i64 0, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !11
  %18 = zext i8 %17 to i32
  %19 = mul nsw i32 %18, 128
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = srem i32 %20, 128
  %22 = add nsw i32 %19, %21
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [0 x i16], ptr @_pcre_ucd_stage2, i64 0, i64 %23
  %25 = load i16, ptr %24, align 2, !tbaa !12
  %26 = zext i16 %25 to i32
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds %struct.ucd_record, ptr @_pcre_ucd_records, i64 %27
  store ptr %28, ptr %5, align 8, !tbaa !9
  %29 = load ptr, ptr %5, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.ucd_record, ptr %29, i32 0, i32 1
  %31 = load i8, ptr %30, align 1, !tbaa !14
  %32 = zext i8 %31 to i64
  %33 = getelementptr inbounds [0 x i32], ptr @_pcre_ucp_gentype, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = load ptr, ptr %4, align 8, !tbaa !9
  %36 = getelementptr inbounds %"struct.Poco::Unicode::CharacterProperties", ptr %35, i32 0, i32 0
  store i32 %34, ptr %36, align 4, !tbaa !16
  %37 = load ptr, ptr %5, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.ucd_record, ptr %37, i32 0, i32 1
  %39 = load i8, ptr %38, align 1, !tbaa !14
  %40 = zext i8 %39 to i32
  %41 = load ptr, ptr %4, align 8, !tbaa !9
  %42 = getelementptr inbounds %"struct.Poco::Unicode::CharacterProperties", ptr %41, i32 0, i32 1
  store i32 %40, ptr %42, align 4, !tbaa !21
  %43 = load ptr, ptr %5, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.ucd_record, ptr %43, i32 0, i32 0
  %45 = load i8, ptr %44, align 4, !tbaa !22
  %46 = zext i8 %45 to i32
  %47 = load ptr, ptr %4, align 8, !tbaa !9
  %48 = getelementptr inbounds %"struct.Poco::Unicode::CharacterProperties", ptr %47, i32 0, i32 2
  store i32 %46, ptr %48, align 4, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret void
}

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !7, i64 1}
!15 = !{!"_ZTS10ucd_record", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !6, i64 4}
!16 = !{!17, !18, i64 0}
!17 = !{!"_ZTSN4Poco7Unicode19CharacterPropertiesE", !18, i64 0, !19, i64 4, !20, i64 8}
!18 = !{!"_ZTSN4Poco7Unicode17CharacterCategoryE", !7, i64 0}
!19 = !{!"_ZTSN4Poco7Unicode13CharacterTypeE", !7, i64 0}
!20 = !{!"_ZTSN4Poco7Unicode6ScriptE", !7, i64 0}
!21 = !{!17, !19, i64 4}
!22 = !{!15, !7, i64 0}
!23 = !{!17, !20, i64 8}


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

@_pcre_ucd_records = external local_unnamed_addr global [0 x %struct.ucd_record], align 4
@_pcre_ucd_stage2 = external local_unnamed_addr constant [0 x i16], align 2
@_pcre_ucd_stage1 = external local_unnamed_addr constant [0 x i8], align 1
@_pcre_ucp_gentype = external local_unnamed_addr constant [0 x i32], align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: write, inaccessiblemem: none) uwtable
define dso_local void @_ZN4Poco7Unicode10propertiesEiRNS0_19CharacterPropertiesE(i32 noundef %0, ptr nocapture noundef nonnull writeonly align 4 dereferenceable(12) %1) local_unnamed_addr #0 align 2 {
  %or.cond = icmp ugt i32 %0, 1114111
  %spec.store.select = select i1 %or.cond, i32 0, i32 %0
  %3 = lshr i32 %spec.store.select, 7
  %4 = zext nneg i32 %3 to i64
  %5 = getelementptr inbounds [0 x i8], ptr @_pcre_ucd_stage1, i64 0, i64 %4
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %7 = zext i8 %6 to i32
  %8 = shl nuw nsw i32 %7, 7
  %9 = and i32 %spec.store.select, 127
  %10 = or disjoint i32 %8, %9
  %11 = zext nneg i32 %10 to i64
  %12 = getelementptr inbounds [0 x i16], ptr @_pcre_ucd_stage2, i64 0, i64 %11
  %13 = load i16, ptr %12, align 2, !tbaa !8
  %14 = zext i16 %13 to i64
  %15 = getelementptr inbounds %struct.ucd_record, ptr @_pcre_ucd_records, i64 %14
  %16 = getelementptr inbounds i8, ptr %15, i64 1
  %17 = load i8, ptr %16, align 1, !tbaa !10
  %18 = zext i8 %17 to i64
  %19 = getelementptr inbounds [0 x i32], ptr @_pcre_ucp_gentype, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !13
  store i32 %20, ptr %1, align 4, !tbaa !14
  %21 = zext i8 %17 to i32
  %22 = getelementptr inbounds i8, ptr %1, i64 4
  store i32 %21, ptr %22, align 4, !tbaa !19
  %23 = load i8, ptr %15, align 4, !tbaa !20
  %24 = zext i8 %23 to i32
  %25 = getelementptr inbounds i8, ptr %1, i64 8
  store i32 %24, ptr %25, align 4, !tbaa !21
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: write, inaccessiblemem: none) 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"short", !6, i64 0}
!10 = !{!11, !6, i64 1}
!11 = !{!"_ZTS10ucd_record", !6, i64 0, !6, i64 1, !6, i64 2, !6, i64 3, !12, i64 4}
!12 = !{!"int", !6, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!15, !16, i64 0}
!15 = !{!"_ZTSN4Poco7Unicode19CharacterPropertiesE", !16, i64 0, !17, i64 4, !18, i64 8}
!16 = !{!"_ZTSN4Poco7Unicode17CharacterCategoryE", !6, i64 0}
!17 = !{!"_ZTSN4Poco7Unicode13CharacterTypeE", !6, i64 0}
!18 = !{!"_ZTSN4Poco7Unicode6ScriptE", !6, i64 0}
!19 = !{!15, !17, i64 4}
!20 = !{!11, !6, i64 0}
!21 = !{!15, !18, i64 8}


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