; LLVM IR from musetronstar/tagd :: tagd/src (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"

@_ZN4tagdL17sqlite3Utf8Trans1E = external hidden constant [64 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: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN4tagd9utf8_readERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPm(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = call noundef zeroext i1 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(32) %7) #2
  br i1 %8, label %9, label %11

9:                                                ; preds = %2
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 0, ptr %10, align 8, !tbaa !9
  store i32 0, ptr %3, align 4
  br label %64

11:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = load i64, ptr %13, align 8, !tbaa !9
  %15 = add i64 %14, 1
  store i64 %15, ptr %13, align 8, !tbaa !9
  %16 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %12, i64 noundef %14) #2
  %17 = load i8, ptr %16, align 1, !tbaa !11
  %18 = zext i8 %17 to i32
  store i32 %18, ptr %6, align 4, !tbaa !12
  %19 = load i32, ptr %6, align 4, !tbaa !12
  %20 = icmp uge i32 %19, 192
  br i1 %20, label %21, label %62

21:                                               ; preds = %11
  %22 = load i32, ptr %6, align 4, !tbaa !12
  %23 = sub i32 %22, 192
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds [64 x i8], ptr @_ZN4tagdL17sqlite3Utf8Trans1E, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !11
  %27 = zext i8 %26 to i32
  store i32 %27, ptr %6, align 4, !tbaa !12
  br label %28

28:                                               ; preds = %37, %21
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i64, ptr %30, align 8, !tbaa !9
  %32 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %29, i64 noundef %31) #2
  %33 = load i8, ptr %32, align 1, !tbaa !11
  %34 = sext i8 %33 to i32
  %35 = and i32 %34, 192
  %36 = icmp eq i32 %35, 128
  br i1 %36, label %37, label %49

37:                                               ; preds = %28
  %38 = load i32, ptr %6, align 4, !tbaa !12
  %39 = shl i32 %38, 6
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load i64, ptr %41, align 8, !tbaa !9
  %43 = add i64 %42, 1
  store i64 %43, ptr %41, align 8, !tbaa !9
  %44 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %40, i64 noundef %42) #2
  %45 = load i8, ptr %44, align 1, !tbaa !11
  %46 = sext i8 %45 to i32
  %47 = and i32 63, %46
  %48 = add i32 %39, %47
  store i32 %48, ptr %6, align 4, !tbaa !12
  br label %28, !llvm.loop !14

49:                                               ; preds = %28
  %50 = load i32, ptr %6, align 4, !tbaa !12
  %51 = icmp ult i32 %50, 128
  br i1 %51, label %60, label %52

52:                                               ; preds = %49
  %53 = load i32, ptr %6, align 4, !tbaa !12
  %54 = and i32 %53, -2048
  %55 = icmp eq i32 %54, 55296
  br i1 %55, label %60, label %56

56:                                               ; preds = %52
  %57 = load i32, ptr %6, align 4, !tbaa !12
  %58 = and i32 %57, -2
  %59 = icmp eq i32 %58, 65534
  br i1 %59, label %60, label %61

60:                                               ; preds = %56, %52, %49
  store i32 65533, ptr %6, align 4, !tbaa !12
  br label %61

61:                                               ; preds = %60, %56
  br label %62

62:                                               ; preds = %61, %11
  %63 = load i32, ptr %6, align 4, !tbaa !12
  store i32 %63, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %64

64:                                               ; preds = %62, %9
  %65 = load i32, ptr %3, align 4
  ret i32 %65
}

; Function Attrs: mustprogress nounwind uwtable
declare noundef zeroext i1 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(32)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@_ZN4tagdL17sqlite3Utf8Trans1E = external hidden local_unnamed_addr constant [64 x i8], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN4tagd9utf8_readERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPm(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %3 = tail call noundef zeroext i1 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #1
  br i1 %3, label %4, label %5

4:                                                ; preds = %2
  store i64 0, ptr %1, align 8, !tbaa !5
  br label %41

5:                                                ; preds = %2
  %6 = load i64, ptr %1, align 8, !tbaa !5
  %7 = add i64 %6, 1
  store i64 %7, ptr %1, align 8, !tbaa !5
  %8 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %6) #1
  %9 = load i8, ptr %8, align 1, !tbaa !9
  %10 = zext i8 %9 to i32
  %11 = icmp ugt i8 %9, -65
  br i1 %11, label %12, label %41

12:                                               ; preds = %5
  %13 = add nsw i32 %10, -192
  %14 = zext nneg i32 %13 to i64
  %15 = getelementptr inbounds [64 x i8], ptr @_ZN4tagdL17sqlite3Utf8Trans1E, i64 0, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !9
  %17 = zext i8 %16 to i32
  %18 = load i64, ptr %1, align 8, !tbaa !5
  %19 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %18) #1
  %20 = load i8, ptr %19, align 1, !tbaa !9
  %21 = and i8 %20, -64
  %22 = icmp eq i8 %21, -128
  br i1 %22, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %12, %.lr.ph
  %.021 = phi i32 [ %30, %.lr.ph ], [ %17, %12 ]
  %23 = shl i32 %.021, 6
  %24 = load i64, ptr %1, align 8, !tbaa !5
  %25 = add i64 %24, 1
  store i64 %25, ptr %1, align 8, !tbaa !5
  %26 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %24) #1
  %27 = load i8, ptr %26, align 1, !tbaa !9
  %28 = and i8 %27, 63
  %29 = zext nneg i8 %28 to i32
  %30 = or disjoint i32 %23, %29
  %31 = load i64, ptr %1, align 8, !tbaa !5
  %32 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %31) #1
  %33 = load i8, ptr %32, align 1, !tbaa !9
  %34 = and i8 %33, -64
  %35 = icmp eq i8 %34, -128
  br i1 %35, label %.lr.ph, label %._crit_edge, !llvm.loop !10

._crit_edge:                                      ; preds = %.lr.ph, %12
  %.0.lcssa = phi i32 [ %17, %12 ], [ %30, %.lr.ph ]
  %36 = icmp ult i32 %.0.lcssa, 128
  %37 = and i32 %.0.lcssa, -2048
  %38 = icmp eq i32 %37, 55296
  %or.cond = or i1 %36, %38
  %39 = and i32 %.0.lcssa, -2
  %40 = icmp eq i32 %39, 65534
  %or.cond20 = or i1 %40, %or.cond
  %spec.select = select i1 %or.cond20, i32 65533, i32 %.0.lcssa
  br label %41

41:                                               ; preds = %._crit_edge, %5, %4
  %.015 = phi i32 [ 0, %4 ], [ %10, %5 ], [ %spec.select, %._crit_edge ]
  ret i32 %.015
}

; Function Attrs: mustprogress nounwind uwtable
declare noundef zeroext i1 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) local_unnamed_addr #0 align 2

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


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