; LLVM IR from aagdev/mlimgsynth :: src/ccommon (unicode_data)

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

@g_unicode_cat1 = external hidden constant [1176 x %struct.UnicodeCat1Entry], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @unicode_category_major(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i8, align 1
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #2
  store i8 0, ptr %3, align 1, !tbaa !9
  %9 = load i8, ptr %3, align 1, !tbaa !9, !range !11, !noundef !12
  %10 = trunc i8 %9 to i1
  %11 = zext i1 %10 to i8
  store i8 %11, ptr %3, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  store i64 0, ptr %4, align 8, !tbaa !13
  %12 = load i64, ptr %4, align 8, !tbaa !13
  store i64 %12, ptr %4, align 8, !tbaa !13
  br label %13

13:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i64 1176, ptr %7, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 -1, ptr %8, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %42, %13
  %15 = load i64, ptr %6, align 8, !tbaa !13
  %16 = load i64, ptr %7, align 8, !tbaa !13
  %17 = icmp ult i64 %15, %16
  br i1 %17, label %18, label %43

18:                                               ; preds = %14
  %19 = load i64, ptr %6, align 8, !tbaa !13
  %20 = load i64, ptr %7, align 8, !tbaa !13
  %21 = add i64 %19, %20
  %22 = udiv i64 %21, 2
  store i64 %22, ptr %5, align 8, !tbaa !13
  %23 = load i64, ptr %5, align 8, !tbaa !13
  %24 = getelementptr inbounds [1176 x %struct.UnicodeCat1Entry], ptr @g_unicode_cat1, i64 0, i64 %23
  %25 = getelementptr inbounds %struct.UnicodeCat1Entry, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !15
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = sub i32 %26, %27
  store i32 %28, ptr %8, align 4, !tbaa !5
  %29 = load i32, ptr %8, align 4, !tbaa !5
  %30 = icmp slt i32 %29, 0
  br i1 %30, label %31, label %34

31:                                               ; preds = %18
  %32 = load i64, ptr %5, align 8, !tbaa !13
  %33 = add i64 %32, 1
  store i64 %33, ptr %6, align 8, !tbaa !13
  br label %42

34:                                               ; preds = %18
  %35 = load i32, ptr %8, align 4, !tbaa !5
  %36 = icmp sgt i32 %35, 0
  br i1 %36, label %37, label %39

37:                                               ; preds = %34
  %38 = load i64, ptr %5, align 8, !tbaa !13
  store i64 %38, ptr %7, align 8, !tbaa !13
  br label %41

39:                                               ; preds = %34
  %40 = load i64, ptr %5, align 8, !tbaa !13
  store i64 %40, ptr %6, align 8, !tbaa !13
  br label %43

41:                                               ; preds = %37
  br label %42

42:                                               ; preds = %41, %31
  br label %14, !llvm.loop !17

43:                                               ; preds = %39, %14
  %44 = load i32, ptr %8, align 4, !tbaa !5
  %45 = icmp eq i32 %44, 0
  %46 = zext i1 %45 to i8
  store i8 %46, ptr %3, align 1, !tbaa !9
  %47 = load i64, ptr %6, align 8, !tbaa !13
  store i64 %47, ptr %4, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %48

48:                                               ; preds = %43
  br label %49

49:                                               ; preds = %48
  %50 = load i64, ptr %4, align 8, !tbaa !13
  %51 = icmp ult i64 %50, 1176
  br i1 %51, label %52, label %57

52:                                               ; preds = %49
  %53 = load i64, ptr %4, align 8, !tbaa !13
  %54 = getelementptr inbounds [1176 x %struct.UnicodeCat1Entry], ptr @g_unicode_cat1, i64 0, i64 %53
  %55 = getelementptr inbounds %struct.UnicodeCat1Entry, ptr %54, i32 0, i32 2
  %56 = load i32, ptr %55, align 4, !tbaa !19
  br label %58

57:                                               ; preds = %49
  br label %58

58:                                               ; preds = %57, %52
  %59 = phi i32 [ %56, %52 ], [ 0, %57 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #2
  ret i32 %59
}

; 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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !6, i64 4}
!16 = !{!"UnicodeCat1Entry", !6, i64 0, !6, i64 4, !6, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!16, !6, 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.UnicodeCat1Entry = type { i32, i32, i32 }

@g_unicode_cat1 = external hidden local_unnamed_addr constant [1176 x %struct.UnicodeCat1Entry], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(none) uwtable
define dso_local i32 @unicode_category_major(i32 noundef %0) local_unnamed_addr #0 {
  br label %2

2:                                                ; preds = %1, %12
  %.01723 = phi i64 [ 1176, %1 ], [ %.118, %12 ]
  %.01922 = phi i64 [ 0, %1 ], [ %.120, %12 ]
  %3 = add i64 %.01723, %.01922
  %4 = lshr i64 %3, 1
  %5 = getelementptr inbounds [1176 x %struct.UnicodeCat1Entry], ptr @g_unicode_cat1, i64 0, i64 %4, i32 1
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = sub i32 %6, %0
  %8 = icmp slt i32 %7, 0
  br i1 %8, label %9, label %11

9:                                                ; preds = %2
  %10 = add nuw i64 %4, 1
  br label %12

11:                                               ; preds = %2
  %.not = icmp eq i32 %6, %0
  br i1 %.not, label %14, label %12

12:                                               ; preds = %11, %9
  %.120 = phi i64 [ %10, %9 ], [ %.01922, %11 ]
  %.118 = phi i64 [ %.01723, %9 ], [ %4, %11 ]
  %13 = icmp ult i64 %.120, %.118
  br i1 %13, label %2, label %14, !llvm.loop !10

14:                                               ; preds = %11, %12
  %.2 = phi i64 [ %.120, %12 ], [ %4, %11 ]
  %15 = icmp ult i64 %.2, 1176
  br i1 %15, label %16, label %19

16:                                               ; preds = %14
  %17 = getelementptr inbounds [1176 x %struct.UnicodeCat1Entry], ptr @g_unicode_cat1, i64 0, i64 %.2, i32 2
  %18 = load i32, ptr %17, align 4, !tbaa !12
  br label %19

19:                                               ; preds = %14, %16
  %20 = phi i32 [ %18, %16 ], [ 0, %14 ]
  ret i32 %20
}

attributes #0 = { nofree norecurse nosync nounwind memory(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, !7, i64 4}
!6 = !{!"UnicodeCat1Entry", !7, i64 0, !7, i64 4, !7, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!6, !7, i64 8}


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