; LLVM IR from lionsoul2014/friso :: src (friso_UTF8)

; 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: nounwind uwtable
declare dso_local i32 @get_utf8_bytes(i8 noundef signext) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @get_utf8_unicode(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  %8 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = load i8, ptr %9, align 1, !tbaa !11
  %11 = call i32 @get_utf8_bytes(i8 noundef signext %10)
  store i32 %11, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store ptr %3, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #2
  %12 = load i32, ptr %4, align 4, !tbaa !9
  switch i32 %12, label %68 [
    i32 1, label %13
    i32 2, label %17
    i32 3, label %39
  ]

13:                                               ; preds = %1
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = load i8, ptr %14, align 1, !tbaa !11
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 %15, ptr %16, align 1, !tbaa !11
  br label %68

17:                                               ; preds = %1
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = load i8, ptr %18, align 1, !tbaa !11
  store i8 %19, ptr %6, align 1, !tbaa !11
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 1
  %22 = load i8, ptr %21, align 1, !tbaa !11
  store i8 %22, ptr %7, align 1, !tbaa !11
  %23 = load i8, ptr %6, align 1, !tbaa !11
  %24 = sext i8 %23 to i32
  %25 = shl i32 %24, 6
  %26 = load i8, ptr %7, align 1, !tbaa !11
  %27 = sext i8 %26 to i32
  %28 = and i32 %27, 63
  %29 = add nsw i32 %25, %28
  %30 = trunc i32 %29 to i8
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 %30, ptr %31, align 1, !tbaa !11
  %32 = load i8, ptr %6, align 1, !tbaa !11
  %33 = sext i8 %32 to i32
  %34 = ashr i32 %33, 2
  %35 = and i32 %34, 7
  %36 = trunc i32 %35 to i8
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i64 1
  store i8 %36, ptr %38, align 1, !tbaa !11
  br label %68

39:                                               ; preds = %1
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = load i8, ptr %40, align 1, !tbaa !11
  store i8 %41, ptr %6, align 1, !tbaa !11
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %42, i64 1
  %44 = load i8, ptr %43, align 1, !tbaa !11
  store i8 %44, ptr %7, align 1, !tbaa !11
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i64 2
  %47 = load i8, ptr %46, align 1, !tbaa !11
  store i8 %47, ptr %8, align 1, !tbaa !11
  %48 = load i8, ptr %7, align 1, !tbaa !11
  %49 = sext i8 %48 to i32
  %50 = shl i32 %49, 6
  %51 = load i8, ptr %8, align 1, !tbaa !11
  %52 = sext i8 %51 to i32
  %53 = and i32 %52, 63
  %54 = add nsw i32 %50, %53
  %55 = trunc i32 %54 to i8
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 %55, ptr %56, align 1, !tbaa !11
  %57 = load i8, ptr %6, align 1, !tbaa !11
  %58 = sext i8 %57 to i32
  %59 = shl i32 %58, 4
  %60 = load i8, ptr %7, align 1, !tbaa !11
  %61 = sext i8 %60 to i32
  %62 = ashr i32 %61, 2
  %63 = and i32 %62, 15
  %64 = add nsw i32 %59, %63
  %65 = trunc i32 %64 to i8
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds i8, ptr %66, i64 1
  store i8 %65, ptr %67, align 1, !tbaa !11
  br label %68

68:                                               ; preds = %39, %17, %13, %1
  %69 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %69
}

; 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 = !{!"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: nounwind uwtable
declare dso_local i32 @get_utf8_bytes(i8 noundef signext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 65536) i32 @get_utf8_unicode(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = load i8, ptr %0, align 1, !tbaa !5
  %3 = tail call i32 @get_utf8_bytes(i8 noundef signext %2)
  switch i32 %3, label %28 [
    i32 1, label %4
    i32 2, label %6
    i32 3, label %15
  ]

4:                                                ; preds = %1
  %5 = load i8, ptr %0, align 1, !tbaa !5
  br label %28

6:                                                ; preds = %1
  %7 = load i8, ptr %0, align 1, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 1
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %10 = shl i8 %7, 6
  %11 = and i8 %9, 63
  %12 = or disjoint i8 %11, %10
  %13 = lshr i8 %7, 2
  %14 = and i8 %13, 7
  br label %28

15:                                               ; preds = %1
  %16 = load i8, ptr %0, align 1, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %0, i64 1
  %18 = load i8, ptr %17, align 1, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %0, i64 2
  %20 = load i8, ptr %19, align 1, !tbaa !5
  %21 = shl i8 %18, 6
  %22 = and i8 %20, 63
  %23 = or disjoint i8 %22, %21
  %24 = shl i8 %16, 4
  %25 = lshr i8 %18, 2
  %26 = and i8 %25, 15
  %27 = or disjoint i8 %26, %24
  br label %28

28:                                               ; preds = %15, %6, %4, %1
  %.sroa.7.0 = phi i8 [ 0, %1 ], [ %27, %15 ], [ %14, %6 ], [ 0, %4 ]
  %.sroa.0.0 = phi i8 [ 0, %1 ], [ %23, %15 ], [ %12, %6 ], [ %5, %4 ]
  %.sroa.7.0.insert.ext = zext i8 %.sroa.7.0 to i32
  %.sroa.7.0.insert.shift = shl nuw nsw i32 %.sroa.7.0.insert.ext, 8
  %.sroa.0.0.insert.ext = zext i8 %.sroa.0.0 to i32
  %.sroa.0.0.insert.insert = or disjoint i32 %.sroa.7.0.insert.shift, %.sroa.0.0.insert.ext
  ret i32 %.sroa.0.0.insert.insert
}

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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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