; LLVM IR from pictools/pica :: test/gtest/fused-src/gtest/gtest-all.ll (ZN7testing8internal15CodePointToUtf8EjPc)

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

%"class.testing::internal::String" = type { ptr, i64 }

@.str.81 = external hidden unnamed_addr constant [23 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7testing8internal6StringD2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #0 align 2

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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK7testing8internal6String5c_strEv(ptr noundef nonnull align 8 dereferenceable(16)) #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7testing8internal6String6FormatEPKcz(ptr dead_on_unwind noalias writable sret(%"class.testing::internal::String") align 8, ptr noundef, ...) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN7testing8internal15CodePointToUtf8EjPc(i32 noundef %0, ptr noundef %1) #2 personality ptr @__gxx_personality_v0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca %"class.testing::internal::String", align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = icmp ule i32 %8, 127
  br i1 %9, label %10, label %17

10:                                               ; preds = %2
  %11 = load ptr, ptr %4, align 8, !tbaa !9
  %12 = getelementptr inbounds i8, ptr %11, i64 1
  store i8 0, ptr %12, align 1, !tbaa !11
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = trunc i32 %13 to i8
  %15 = load ptr, ptr %4, align 8, !tbaa !9
  %16 = getelementptr inbounds i8, ptr %15, i64 0
  store i8 %14, ptr %16, align 1, !tbaa !11
  br label %96

17:                                               ; preds = %2
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = icmp ule i32 %18, 2047
  br i1 %19, label %20, label %33

20:                                               ; preds = %17
  %21 = load ptr, ptr %4, align 8, !tbaa !9
  %22 = getelementptr inbounds i8, ptr %21, i64 2
  store i8 0, ptr %22, align 1, !tbaa !11
  %23 = call noundef i32 @_ZN7testing8internal11ChopLowBitsEPji(ptr noundef %3, i32 noundef 6)
  %24 = or i32 128, %23
  %25 = trunc i32 %24 to i8
  %26 = load ptr, ptr %4, align 8, !tbaa !9
  %27 = getelementptr inbounds i8, ptr %26, i64 1
  store i8 %25, ptr %27, align 1, !tbaa !11
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = or i32 192, %28
  %30 = trunc i32 %29 to i8
  %31 = load ptr, ptr %4, align 8, !tbaa !9
  %32 = getelementptr inbounds i8, ptr %31, i64 0
  store i8 %30, ptr %32, align 1, !tbaa !11
  br label %95

33:                                               ; preds = %17
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = icmp ule i32 %34, 65535
  br i1 %35, label %36, label %54

36:                                               ; preds = %33
  %37 = load ptr, ptr %4, align 8, !tbaa !9
  %38 = getelementptr inbounds i8, ptr %37, i64 3
  store i8 0, ptr %38, align 1, !tbaa !11
  %39 = call noundef i32 @_ZN7testing8internal11ChopLowBitsEPji(ptr noundef %3, i32 noundef 6)
  %40 = or i32 128, %39
  %41 = trunc i32 %40 to i8
  %42 = load ptr, ptr %4, align 8, !tbaa !9
  %43 = getelementptr inbounds i8, ptr %42, i64 2
  store i8 %41, ptr %43, align 1, !tbaa !11
  %44 = call noundef i32 @_ZN7testing8internal11ChopLowBitsEPji(ptr noundef %3, i32 noundef 6)
  %45 = or i32 128, %44
  %46 = trunc i32 %45 to i8
  %47 = load ptr, ptr %4, align 8, !tbaa !9
  %48 = getelementptr inbounds i8, ptr %47, i64 1
  store i8 %46, ptr %48, align 1, !tbaa !11
  %49 = load i32, ptr %3, align 4, !tbaa !5
  %50 = or i32 224, %49
  %51 = trunc i32 %50 to i8
  %52 = load ptr, ptr %4, align 8, !tbaa !9
  %53 = getelementptr inbounds i8, ptr %52, i64 0
  store i8 %51, ptr %53, align 1, !tbaa !11
  br label %94

54:                                               ; preds = %33
  %55 = load i32, ptr %3, align 4, !tbaa !5
  %56 = icmp ule i32 %55, 2097151
  br i1 %56, label %57, label %80

57:                                               ; preds = %54
  %58 = load ptr, ptr %4, align 8, !tbaa !9
  %59 = getelementptr inbounds i8, ptr %58, i64 4
  store i8 0, ptr %59, align 1, !tbaa !11
  %60 = call noundef i32 @_ZN7testing8internal11ChopLowBitsEPji(ptr noundef %3, i32 noundef 6)
  %61 = or i32 128, %60
  %62 = trunc i32 %61 to i8
  %63 = load ptr, ptr %4, align 8, !tbaa !9
  %64 = getelementptr inbounds i8, ptr %63, i64 3
  store i8 %62, ptr %64, align 1, !tbaa !11
  %65 = call noundef i32 @_ZN7testing8internal11ChopLowBitsEPji(ptr noundef %3, i32 noundef 6)
  %66 = or i32 128, %65
  %67 = trunc i32 %66 to i8
  %68 = load ptr, ptr %4, align 8, !tbaa !9
  %69 = getelementptr inbounds i8, ptr %68, i64 2
  store i8 %67, ptr %69, align 1, !tbaa !11
  %70 = call noundef i32 @_ZN7testing8internal11ChopLowBitsEPji(ptr noundef %3, i32 noundef 6)
  %71 = or i32 128, %70
  %72 = trunc i32 %71 to i8
  %73 = load ptr, ptr %4, align 8, !tbaa !9
  %74 = getelementptr inbounds i8, ptr %73, i64 1
  store i8 %72, ptr %74, align 1, !tbaa !11
  %75 = load i32, ptr %3, align 4, !tbaa !5
  %76 = or i32 240, %75
  %77 = trunc i32 %76 to i8
  %78 = load ptr, ptr %4, align 8, !tbaa !9
  %79 = getelementptr inbounds i8, ptr %78, i64 0
  store i8 %77, ptr %79, align 1, !tbaa !11
  br label %93

80:                                               ; preds = %54
  %81 = load ptr, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #4
  %82 = load i32, ptr %3, align 4, !tbaa !5
  call void (ptr, ptr, ...) @_ZN7testing8internal6String6FormatEPKcz(ptr dead_on_unwind writable sret(%"class.testing::internal::String") align 8 %5, ptr noundef @.str.81, i32 noundef %82)
  %83 = invoke noundef ptr @_ZNK7testing8internal6String5c_strEv(ptr noundef nonnull align 8 dereferenceable(16) %5)
          to label %84 unwind label %89

84:                                               ; preds = %80
  %85 = invoke noundef ptr @_ZN7testing8internal5posix7StrNCpyEPcPKcm(ptr noundef %81, ptr noundef %83, i64 noundef 32)
          to label %86 unwind label %89

86:                                               ; preds = %84
  call void @_ZN7testing8internal6StringD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %5) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #4
  %87 = load ptr, ptr %4, align 8, !tbaa !9
  %88 = getelementptr inbounds i8, ptr %87, i64 31
  store i8 0, ptr %88, align 1, !tbaa !11
  br label %93

89:                                               ; preds = %84, %80
  %90 = landingpad { ptr, i32 }
          cleanup
  %91 = extractvalue { ptr, i32 } %90, 0
  store ptr %91, ptr %6, align 8
  %92 = extractvalue { ptr, i32 } %90, 1
  store i32 %92, ptr %7, align 4
  call void @_ZN7testing8internal6StringD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %5) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #4
  br label %98

93:                                               ; preds = %86, %57
  br label %94

94:                                               ; preds = %93, %36
  br label %95

95:                                               ; preds = %94, %20
  br label %96

96:                                               ; preds = %95, %10
  %97 = load ptr, ptr %4, align 8, !tbaa !9
  ret ptr %97

98:                                               ; preds = %89
  %99 = load ptr, ptr %6, align 8
  %100 = load i32, ptr %7, align 4
  %101 = insertvalue { ptr, i32 } poison, ptr %99, 0
  %102 = insertvalue { ptr, i32 } %101, i32 %100, 1
  resume { ptr, i32 } %102
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN7testing8internal11ChopLowBitsEPji(ptr noundef, i32 noundef) #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN7testing8internal5posix7StrNCpyEPcPKcm(ptr noundef, ptr noundef, i64 noundef) #3

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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 #3 = { inlinehint 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 #4 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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"

%"class.testing::internal::String" = type { ptr, i64 }

@.str.81 = external hidden unnamed_addr constant [23 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7testing8internal6StringD2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #0 align 2

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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK7testing8internal6String5c_strEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7testing8internal6String6FormatEPKcz(ptr dead_on_unwind noalias writable sret(%"class.testing::internal::String") align 8, ptr noundef, ...) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN7testing8internal15CodePointToUtf8EjPc(i32 noundef %0, ptr noundef returned %1) local_unnamed_addr #2 personality ptr @__gxx_personality_v0 {
  %3 = alloca i32, align 4
  %4 = alloca %"class.testing::internal::String", align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  %5 = icmp ult i32 %0, 128
  br i1 %5, label %6, label %9

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %1, i64 1
  store i8 0, ptr %7, align 1, !tbaa !9
  %8 = trunc nuw i32 %0 to i8
  store i8 %8, ptr %1, align 1, !tbaa !9
  br label %58

9:                                                ; preds = %2
  %10 = icmp ult i32 %0, 2048
  br i1 %10, label %11, label %20

11:                                               ; preds = %9
  %12 = getelementptr inbounds i8, ptr %1, i64 2
  store i8 0, ptr %12, align 1, !tbaa !9
  %13 = call noundef i32 @_ZN7testing8internal11ChopLowBitsEPji(ptr noundef nonnull %3, i32 noundef 6)
  %14 = trunc i32 %13 to i8
  %15 = or i8 %14, -128
  %16 = getelementptr inbounds i8, ptr %1, i64 1
  store i8 %15, ptr %16, align 1, !tbaa !9
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = trunc i32 %17 to i8
  %19 = or i8 %18, -64
  store i8 %19, ptr %1, align 1, !tbaa !9
  br label %58

20:                                               ; preds = %9
  %21 = icmp ult i32 %0, 65536
  br i1 %21, label %22, label %35

22:                                               ; preds = %20
  %23 = getelementptr inbounds i8, ptr %1, i64 3
  store i8 0, ptr %23, align 1, !tbaa !9
  %24 = call noundef i32 @_ZN7testing8internal11ChopLowBitsEPji(ptr noundef nonnull %3, i32 noundef 6)
  %25 = trunc i32 %24 to i8
  %26 = or i8 %25, -128
  %27 = getelementptr inbounds i8, ptr %1, i64 2
  store i8 %26, ptr %27, align 1, !tbaa !9
  %28 = call noundef i32 @_ZN7testing8internal11ChopLowBitsEPji(ptr noundef nonnull %3, i32 noundef 6)
  %29 = trunc i32 %28 to i8
  %30 = or i8 %29, -128
  %31 = getelementptr inbounds i8, ptr %1, i64 1
  store i8 %30, ptr %31, align 1, !tbaa !9
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = trunc i32 %32 to i8
  %34 = or i8 %33, -32
  store i8 %34, ptr %1, align 1, !tbaa !9
  br label %58

35:                                               ; preds = %20
  %36 = icmp ult i32 %0, 2097152
  br i1 %36, label %37, label %54

37:                                               ; preds = %35
  %38 = getelementptr inbounds i8, ptr %1, i64 4
  store i8 0, ptr %38, align 1, !tbaa !9
  %39 = call noundef i32 @_ZN7testing8internal11ChopLowBitsEPji(ptr noundef nonnull %3, i32 noundef 6)
  %40 = trunc i32 %39 to i8
  %41 = or i8 %40, -128
  %42 = getelementptr inbounds i8, ptr %1, i64 3
  store i8 %41, ptr %42, align 1, !tbaa !9
  %43 = call noundef i32 @_ZN7testing8internal11ChopLowBitsEPji(ptr noundef nonnull %3, i32 noundef 6)
  %44 = trunc i32 %43 to i8
  %45 = or i8 %44, -128
  %46 = getelementptr inbounds i8, ptr %1, i64 2
  store i8 %45, ptr %46, align 1, !tbaa !9
  %47 = call noundef i32 @_ZN7testing8internal11ChopLowBitsEPji(ptr noundef nonnull %3, i32 noundef 6)
  %48 = trunc i32 %47 to i8
  %49 = or i8 %48, -128
  %50 = getelementptr inbounds i8, ptr %1, i64 1
  store i8 %49, ptr %50, align 1, !tbaa !9
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = trunc i32 %51 to i8
  %53 = or i8 %52, -16
  store i8 %53, ptr %1, align 1, !tbaa !9
  br label %58

54:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #4
  call void (ptr, ptr, ...) @_ZN7testing8internal6String6FormatEPKcz(ptr dead_on_unwind nonnull writable sret(%"class.testing::internal::String") align 8 %4, ptr noundef nonnull @.str.81, i32 noundef %0)
  %55 = call noundef ptr @_ZNK7testing8internal6String5c_strEv(ptr noundef nonnull align 8 dereferenceable(16) %4)
  %56 = call noundef ptr @_ZN7testing8internal5posix7StrNCpyEPcPKcm(ptr noundef %1, ptr noundef %55, i64 noundef 32)
  call void @_ZN7testing8internal6StringD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %4) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #4
  %57 = getelementptr inbounds i8, ptr %1, i64 31
  store i8 0, ptr %57, align 1, !tbaa !9
  br label %58

58:                                               ; preds = %11, %37, %54, %22, %6
  ret ptr %1
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN7testing8internal11ChopLowBitsEPji(ptr noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN7testing8internal5posix7StrNCpyEPcPKcm(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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 #3 = { inlinehint 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 #4 = { 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++ TBAA"}
!9 = !{!7, !7, i64 0}


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