; LLVM IR from snowballstem/snowball :: runtime (utilities)

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

; 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 @in_grouping_U(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %62, %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.SN_env, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.SN_env, ptr %19, i32 0, i32 1
  %21 = load i32, ptr %20, align 8, !tbaa !13
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.SN_env, ptr %22, i32 0, i32 2
  %24 = load i32, ptr %23, align 4, !tbaa !14
  %25 = call i32 @get_utf8(ptr noundef %18, i32 noundef %21, i32 noundef %24, ptr noundef %12)
  store i32 %25, ptr %13, align 4, !tbaa !9
  %26 = load i32, ptr %13, align 4, !tbaa !9
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %29, label %28

28:                                               ; preds = %15
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %59

29:                                               ; preds = %15
  %30 = load i32, ptr %12, align 4, !tbaa !9
  %31 = load i32, ptr %10, align 4, !tbaa !9
  %32 = icmp sgt i32 %30, %31
  br i1 %32, label %51, label %33

33:                                               ; preds = %29
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = load i32, ptr %12, align 4, !tbaa !9
  %36 = sub nsw i32 %35, %34
  store i32 %36, ptr %12, align 4, !tbaa !9
  %37 = icmp slt i32 %36, 0
  br i1 %37, label %51, label %38

38:                                               ; preds = %33
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = load i32, ptr %12, align 4, !tbaa !9
  %41 = ashr i32 %40, 3
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i8, ptr %39, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !15
  %45 = zext i8 %44 to i32
  %46 = load i32, ptr %12, align 4, !tbaa !9
  %47 = and i32 %46, 7
  %48 = shl i32 1, %47
  %49 = and i32 %45, %48
  %50 = icmp eq i32 %49, 0
  br i1 %50, label %51, label %53

51:                                               ; preds = %38, %33, %29
  %52 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %52, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %59

53:                                               ; preds = %38
  %54 = load i32, ptr %13, align 4, !tbaa !9
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.SN_env, ptr %55, i32 0, i32 1
  %57 = load i32, ptr %56, align 8, !tbaa !13
  %58 = add nsw i32 %57, %54
  store i32 %58, ptr %56, align 8, !tbaa !13
  store i32 0, ptr %14, align 4
  br label %59

59:                                               ; preds = %53, %51, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  %60 = load i32, ptr %14, align 4
  switch i32 %60, label %68 [
    i32 0, label %61
    i32 1, label %66
  ]

61:                                               ; preds = %59
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %11, align 4, !tbaa !9
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %15, label %65, !llvm.loop !16

65:                                               ; preds = %62
  store i32 0, ptr %6, align 4
  br label %66

66:                                               ; preds = %65, %59
  %67 = load i32, ptr %6, align 4
  ret i32 %67

68:                                               ; preds = %59
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden i32 @get_utf8(ptr noundef, i32 noundef, i32 noundef, ptr 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"SN_env", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !6, i64 32, !6, i64 40}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !10, i64 12}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

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

; Function Attrs: mustprogress 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 @in_grouping_U(ptr nocapture noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #1 {
  %6 = alloca i32, align 4
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = getelementptr inbounds i8, ptr %0, i64 12
  %.not16 = icmp eq i32 %4, 0
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #2
  %9 = load ptr, ptr %0, align 8, !tbaa !5
  %10 = load i32, ptr %7, align 8, !tbaa !11
  %11 = load i32, ptr %8, align 4, !tbaa !12
  %12 = call i32 @get_utf8(ptr noundef %9, i32 noundef %10, i32 noundef %11, ptr noundef nonnull %6)
  %.not.us = icmp eq i32 %12, 0
  br i1 %.not16, label %.split.us, label %.split, !llvm.loop !13

.split.us:                                        ; preds = %5
  br i1 %.not.us, label %.thread, label %13

13:                                               ; preds = %.split.us
  %14 = load i32, ptr %6, align 4, !tbaa !15
  %15 = icmp sgt i32 %14, %3
  br i1 %15, label %.thread, label %16

16:                                               ; preds = %13
  %17 = sub nsw i32 %14, %2
  %18 = icmp slt i32 %17, 0
  br i1 %18, label %.thread, label %19

19:                                               ; preds = %16
  %20 = lshr i32 %17, 3
  %21 = zext nneg i32 %20 to i64
  %22 = getelementptr inbounds i8, ptr %1, i64 %21
  %23 = load i8, ptr %22, align 1, !tbaa !16
  %24 = zext i8 %23 to i32
  %25 = and i32 %17, 7
  %26 = shl nuw nsw i32 1, %25
  %27 = and i32 %26, %24
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %.thread, label %.loopexit.split.us

.loopexit.split.us:                               ; preds = %19
  %29 = load i32, ptr %7, align 8, !tbaa !11
  %30 = add nsw i32 %29, %12
  store i32 %30, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #2
  br label %53

.split:                                           ; preds = %5
  br i1 %.not.us, label %.thread, label %.lr.ph

.lr.ph:                                           ; preds = %.split, %47
  %31 = phi i32 [ %52, %47 ], [ %12, %.split ]
  %32 = load i32, ptr %6, align 4, !tbaa !15
  %33 = icmp sgt i32 %32, %3
  br i1 %33, label %.thread, label %34

34:                                               ; preds = %.lr.ph
  %35 = sub nsw i32 %32, %2
  %36 = icmp slt i32 %35, 0
  br i1 %36, label %.thread, label %37

37:                                               ; preds = %34
  %38 = lshr i32 %35, 3
  %39 = zext nneg i32 %38 to i64
  %40 = getelementptr inbounds i8, ptr %1, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !16
  %42 = zext i8 %41 to i32
  %43 = and i32 %35, 7
  %44 = shl nuw nsw i32 1, %43
  %45 = and i32 %44, %42
  %46 = icmp eq i32 %45, 0
  br i1 %46, label %.thread, label %47

.thread:                                          ; preds = %47, %37, %34, %.lr.ph, %.split, %.split.us, %13, %16, %19
  %.us-phi = phi i32 [ %12, %13 ], [ %12, %16 ], [ %12, %19 ], [ -1, %.split.us ], [ -1, %.split ], [ -1, %47 ], [ %31, %37 ], [ %31, %34 ], [ %31, %.lr.ph ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #2
  br label %53

47:                                               ; preds = %37
  %48 = load i32, ptr %7, align 8, !tbaa !11
  %49 = add nsw i32 %48, %31
  store i32 %49, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #2
  %50 = load ptr, ptr %0, align 8, !tbaa !5
  %51 = load i32, ptr %8, align 4, !tbaa !12
  %52 = call i32 @get_utf8(ptr noundef %50, i32 noundef %49, i32 noundef %51, ptr noundef nonnull %6)
  %.not = icmp eq i32 %52, 0
  br i1 %.not, label %.thread, label %.lr.ph

53:                                               ; preds = %.loopexit.split.us, %.thread
  %.2 = phi i32 [ %.us-phi, %.thread ], [ 0, %.loopexit.split.us ]
  ret i32 %.2
}

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

attributes #0 = { mustprogress 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, !7, i64 0}
!6 = !{!"SN_env", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !7, i64 32, !7, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!6, !10, i64 12}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!10, !10, i64 0}
!16 = !{!8, !8, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass