; LLVM IR from marcobambini/gravity :: src/utils (gravity_utils)

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

; 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: inlinehint nounwind uwtable
define dso_local i32 @utf8_charbytes(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #2
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = zext i32 %9 to i64
  %11 = getelementptr inbounds i8, ptr %8, i64 %10
  %12 = load i8, ptr %11, align 1, !tbaa !11
  store i8 %12, ptr %6, align 1, !tbaa !11
  %13 = load i8, ptr %6, align 1, !tbaa !11
  %14 = zext i8 %13 to i32
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %16, label %21

16:                                               ; preds = %2
  %17 = load i8, ptr %6, align 1, !tbaa !11
  %18 = zext i8 %17 to i32
  %19 = icmp sle i32 %18, 127
  br i1 %19, label %20, label %21

20:                                               ; preds = %16
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %49

21:                                               ; preds = %16, %2
  %22 = load i8, ptr %6, align 1, !tbaa !11
  %23 = zext i8 %22 to i32
  %24 = icmp sge i32 %23, 194
  br i1 %24, label %25, label %30

25:                                               ; preds = %21
  %26 = load i8, ptr %6, align 1, !tbaa !11
  %27 = zext i8 %26 to i32
  %28 = icmp sle i32 %27, 223
  br i1 %28, label %29, label %30

29:                                               ; preds = %25
  store i32 2, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %49

30:                                               ; preds = %25, %21
  %31 = load i8, ptr %6, align 1, !tbaa !11
  %32 = zext i8 %31 to i32
  %33 = icmp sge i32 %32, 224
  br i1 %33, label %34, label %39

34:                                               ; preds = %30
  %35 = load i8, ptr %6, align 1, !tbaa !11
  %36 = zext i8 %35 to i32
  %37 = icmp sle i32 %36, 239
  br i1 %37, label %38, label %39

38:                                               ; preds = %34
  store i32 3, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %49

39:                                               ; preds = %34, %30
  %40 = load i8, ptr %6, align 1, !tbaa !11
  %41 = zext i8 %40 to i32
  %42 = icmp sge i32 %41, 240
  br i1 %42, label %43, label %48

43:                                               ; preds = %39
  %44 = load i8, ptr %6, align 1, !tbaa !11
  %45 = zext i8 %44 to i32
  %46 = icmp sle i32 %45, 244
  br i1 %46, label %47, label %48

47:                                               ; preds = %43
  store i32 4, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %49

48:                                               ; preds = %43, %39
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %49

49:                                               ; preds = %48, %47, %38, %29, %20
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #2
  %50 = load i32, ptr %3, align 4
  ret i32 %50
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = !{!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"

; Function Attrs: inlinehint mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local range(i32 0, 5) i32 @utf8_charbytes(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = zext i32 %1 to i64
  %4 = getelementptr inbounds i8, ptr %0, i64 %3
  %5 = load i8, ptr %4, align 1, !tbaa !5
  %or.cond = icmp sgt i8 %5, 0
  br i1 %or.cond, label %12, label %6

6:                                                ; preds = %2
  %7 = add nsw i8 %5, 62
  %or.cond5 = icmp ult i8 %7, 30
  br i1 %or.cond5, label %12, label %8

8:                                                ; preds = %6
  %9 = and i8 %5, -16
  %or.cond8 = icmp eq i8 %9, -32
  br i1 %or.cond8, label %12, label %10

10:                                               ; preds = %8
  %11 = add nsw i8 %5, 16
  %or.cond11 = icmp ult i8 %11, 5
  %. = select i1 %or.cond11, i32 4, i32 0
  br label %12

12:                                               ; preds = %10, %8, %6, %2
  %.0 = phi i32 [ 1, %2 ], [ 2, %6 ], [ 3, %8 ], [ %., %10 ]
  ret i32 %.0
}

attributes #0 = { inlinehint mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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/C++ TBAA"}


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