; LLVM IR from cashapp/zipline :: zipline/native/quickjs (libunicode)

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

@case_conv_table1 = external hidden constant [361 x i32], align 16
@unicode_prop_Cased1_table = external hidden constant [172 x i8], align 16
@unicode_prop_Cased1_index = external hidden constant [18 x i8], align 16

; 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 i32 @lre_is_cased(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %8, align 4, !tbaa !5
  store i32 360, ptr %9, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %46, %1
  %12 = load i32, ptr %8, align 4, !tbaa !5
  %13 = load i32, ptr %9, align 4, !tbaa !5
  %14 = icmp sle i32 %12, %13
  br i1 %14, label %15, label %47

15:                                               ; preds = %11
  %16 = load i32, ptr %9, align 4, !tbaa !5
  %17 = load i32, ptr %8, align 4, !tbaa !5
  %18 = add nsw i32 %16, %17
  %19 = udiv i32 %18, 2
  store i32 %19, ptr %7, align 4, !tbaa !5
  %20 = load i32, ptr %7, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [361 x i32], ptr @case_conv_table1, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  store i32 %23, ptr %4, align 4, !tbaa !5
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = lshr i32 %24, 15
  store i32 %25, ptr %5, align 4, !tbaa !5
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = lshr i32 %26, 8
  %28 = and i32 %27, 127
  store i32 %28, ptr %6, align 4, !tbaa !5
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = icmp ult i32 %29, %30
  br i1 %31, label %32, label %35

32:                                               ; preds = %15
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = sub nsw i32 %33, 1
  store i32 %34, ptr %9, align 4, !tbaa !5
  br label %46

35:                                               ; preds = %15
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = add i32 %37, %38
  %40 = icmp uge i32 %36, %39
  br i1 %40, label %41, label %44

41:                                               ; preds = %35
  %42 = load i32, ptr %7, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %8, align 4, !tbaa !5
  br label %45

44:                                               ; preds = %35
  store i32 1, ptr %2, align 4
  store i32 1, ptr %10, align 4
  br label %50

45:                                               ; preds = %41
  br label %46

46:                                               ; preds = %45, %32
  br label %11, !llvm.loop !9

47:                                               ; preds = %11
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = call i32 @lre_is_in_table(i32 noundef %48, ptr noundef @unicode_prop_Cased1_table, ptr noundef @unicode_prop_Cased1_index, i32 noundef 6)
  store i32 %49, ptr %2, align 4
  store i32 1, ptr %10, align 4
  br label %50

50:                                               ; preds = %47, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %51 = load i32, ptr %2, align 4
  ret i32 %51
}

; Function Attrs: nounwind uwtable
declare hidden i32 @lre_is_in_table(i32 noundef, ptr noundef, ptr noundef, i32 noundef) #1

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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

@case_conv_table1 = external hidden local_unnamed_addr constant [361 x i32], align 16
@unicode_prop_Cased1_table = external hidden constant [172 x i8], align 16
@unicode_prop_Cased1_index = external hidden constant [18 x i8], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @lre_is_cased(i32 noundef %0) local_unnamed_addr #0 {
  br label %2

2:                                                ; preds = %1, %18
  %.023 = phi i32 [ 360, %1 ], [ %.1, %18 ]
  %.01622 = phi i32 [ 0, %1 ], [ %.117, %18 ]
  %3 = add nsw i32 %.023, %.01622
  %4 = lshr i32 %3, 1
  %5 = zext nneg i32 %4 to i64
  %6 = getelementptr inbounds [361 x i32], ptr @case_conv_table1, i64 0, i64 %5
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = lshr i32 %7, 15
  %9 = icmp ugt i32 %8, %0
  br i1 %9, label %10, label %12

10:                                               ; preds = %2
  %11 = add nsw i32 %4, -1
  br label %18

12:                                               ; preds = %2
  %13 = lshr i32 %7, 8
  %14 = and i32 %13, 127
  %15 = add nuw nsw i32 %14, %8
  %.not21 = icmp ugt i32 %15, %0
  br i1 %.not21, label %.loopexit, label %16

16:                                               ; preds = %12
  %17 = add nuw nsw i32 %4, 1
  br label %18

18:                                               ; preds = %16, %10
  %.117 = phi i32 [ %.01622, %10 ], [ %17, %16 ]
  %.1 = phi i32 [ %11, %10 ], [ %.023, %16 ]
  %.not = icmp sgt i32 %.117, %.1
  br i1 %.not, label %19, label %2, !llvm.loop !9

19:                                               ; preds = %18
  %20 = tail call i32 @lre_is_in_table(i32 noundef %0, ptr noundef nonnull @unicode_prop_Cased1_table, ptr noundef nonnull @unicode_prop_Cased1_index, i32 noundef 6)
  br label %.loopexit

.loopexit:                                        ; preds = %12, %19
  %.018 = phi i32 [ %20, %19 ], [ 1, %12 ]
  ret i32 %.018
}

; Function Attrs: nounwind uwtable
declare hidden i32 @lre_is_in_table(i32 noundef, ptr noundef, ptr noundef, i32 noundef) 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" }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass