; LLVM IR from marcj/TypeRunner :: src/utf.ll (ZN2tr3utf12fromCharCodeB5cxx11Ei)

; 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.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }
%"class.std::allocator" = type { i8 }

; 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 uwtable
define dso_local void @_ZN2tr3utf12fromCharCodeB5cxx11Ei(ptr dead_on_unwind noalias writable sret(%"class.std::__cxx11::basic_string") align 8 %0, i32 noundef %1) #1 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca [5 x i8], align 1
  %6 = alloca %"class.std::allocator", align 1
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 5, ptr %5) #4
  call void @llvm.memset.p0.i64(ptr align 1 %5, i8 0, i64 5, i1 false)
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = icmp sle i32 %9, 127
  br i1 %10, label %11, label %15

11:                                               ; preds = %2
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = trunc i32 %12 to i8
  %14 = getelementptr inbounds [5 x i8], ptr %5, i64 0, i64 0
  store i8 %13, ptr %14, align 1, !tbaa !9
  br label %86

15:                                               ; preds = %2
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = icmp sle i32 %16, 2047
  br i1 %17, label %18, label %29

18:                                               ; preds = %15
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = ashr i32 %19, 6
  %21 = add nsw i32 %20, 192
  %22 = trunc i32 %21 to i8
  %23 = getelementptr inbounds [5 x i8], ptr %5, i64 0, i64 0
  store i8 %22, ptr %23, align 1, !tbaa !9
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = and i32 %24, 63
  %26 = add nsw i32 %25, 128
  %27 = trunc i32 %26 to i8
  %28 = getelementptr inbounds [5 x i8], ptr %5, i64 0, i64 1
  store i8 %27, ptr %28, align 1, !tbaa !9
  br label %85

29:                                               ; preds = %15
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = icmp sle i32 55296, %30
  br i1 %31, label %32, label %36

32:                                               ; preds = %29
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = icmp sle i32 %33, 57343
  br i1 %34, label %35, label %36

35:                                               ; preds = %32
  br label %84

36:                                               ; preds = %32, %29
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = icmp sle i32 %37, 65535
  br i1 %38, label %39, label %56

39:                                               ; preds = %36
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = ashr i32 %40, 12
  %42 = add nsw i32 %41, 224
  %43 = trunc i32 %42 to i8
  %44 = getelementptr inbounds [5 x i8], ptr %5, i64 0, i64 0
  store i8 %43, ptr %44, align 1, !tbaa !9
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = ashr i32 %45, 6
  %47 = and i32 %46, 63
  %48 = add nsw i32 %47, 128
  %49 = trunc i32 %48 to i8
  %50 = getelementptr inbounds [5 x i8], ptr %5, i64 0, i64 1
  store i8 %49, ptr %50, align 1, !tbaa !9
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = and i32 %51, 63
  %53 = add nsw i32 %52, 128
  %54 = trunc i32 %53 to i8
  %55 = getelementptr inbounds [5 x i8], ptr %5, i64 0, i64 2
  store i8 %54, ptr %55, align 1, !tbaa !9
  br label %83

56:                                               ; preds = %36
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = icmp sle i32 %57, 1114111
  br i1 %58, label %59, label %82

59:                                               ; preds = %56
  %60 = load i32, ptr %4, align 4, !tbaa !5
  %61 = ashr i32 %60, 18
  %62 = add nsw i32 %61, 240
  %63 = trunc i32 %62 to i8
  %64 = getelementptr inbounds [5 x i8], ptr %5, i64 0, i64 0
  store i8 %63, ptr %64, align 1, !tbaa !9
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = ashr i32 %65, 12
  %67 = and i32 %66, 63
  %68 = add nsw i32 %67, 128
  %69 = trunc i32 %68 to i8
  %70 = getelementptr inbounds [5 x i8], ptr %5, i64 0, i64 1
  store i8 %69, ptr %70, align 1, !tbaa !9
  %71 = load i32, ptr %4, align 4, !tbaa !5
  %72 = ashr i32 %71, 6
  %73 = and i32 %72, 63
  %74 = add nsw i32 %73, 128
  %75 = trunc i32 %74 to i8
  %76 = getelementptr inbounds [5 x i8], ptr %5, i64 0, i64 2
  store i8 %75, ptr %76, align 1, !tbaa !9
  %77 = load i32, ptr %4, align 4, !tbaa !5
  %78 = and i32 %77, 63
  %79 = add nsw i32 %78, 128
  %80 = trunc i32 %79 to i8
  %81 = getelementptr inbounds [5 x i8], ptr %5, i64 0, i64 3
  store i8 %80, ptr %81, align 1, !tbaa !9
  br label %82

82:                                               ; preds = %59, %56
  br label %83

83:                                               ; preds = %82, %39
  br label %84

84:                                               ; preds = %83, %35
  br label %85

85:                                               ; preds = %84, %18
  br label %86

86:                                               ; preds = %85, %11
  %87 = getelementptr inbounds [5 x i8], ptr %5, i64 0, i64 0
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #4
  call void @_ZNSaIcEC2Ev(ptr noundef nonnull align 1 dereferenceable(1) %6) #4
  invoke void @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef %87, ptr noundef nonnull align 1 dereferenceable(1) %6)
          to label %88 unwind label %89

88:                                               ; preds = %86
  call void @_ZNSt15__new_allocatorIcED2Ev(ptr noundef nonnull align 1 dereferenceable(1) %6) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 5, ptr %5) #4
  ret void

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

93:                                               ; preds = %89
  %94 = load ptr, ptr %7, align 8
  %95 = load i32, ptr %8, align 4
  %96 = insertvalue { ptr, i32 } poison, ptr %94, 0
  %97 = insertvalue { ptr, i32 } %96, i32 %95, 1
  resume { ptr, i32 } %97
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: mustprogress nounwind uwtable
declare void @_ZNSaIcEC2Ev(ptr noundef nonnull align 1 dereferenceable(1)) unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef, ptr noundef nonnull align 1 dereferenceable(1)) unnamed_addr #1 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt15__new_allocatorIcED2Ev(ptr noundef nonnull align 1 dereferenceable(1)) unnamed_addr #3 align 2

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


; 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.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }
%"class.std::allocator" = type { i8 }

; 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: mustprogress uwtable
define dso_local void @_ZN2tr3utf12fromCharCodeB5cxx11Ei(ptr dead_on_unwind noalias writable sret(%"class.std::__cxx11::basic_string") align 8 %0, i32 noundef %1) local_unnamed_addr #1 personality ptr @__gxx_personality_v0 {
  %3 = alloca [5 x i8], align 1
  %4 = alloca %"class.std::allocator", align 1
  call void @llvm.lifetime.start.p0(i64 5, ptr nonnull %3) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(5) %3, i8 0, i64 5, i1 false)
  %5 = icmp slt i32 %1, 128
  br i1 %5, label %6, label %8

6:                                                ; preds = %2
  %7 = trunc i32 %1 to i8
  store i8 %7, ptr %3, align 1, !tbaa !5
  br label %55

8:                                                ; preds = %2
  %9 = icmp ult i32 %1, 2048
  br i1 %9, label %10, label %18

10:                                               ; preds = %8
  %11 = lshr i32 %1, 6
  %12 = trunc nuw i32 %11 to i8
  %13 = or disjoint i8 %12, -64
  store i8 %13, ptr %3, align 1, !tbaa !5
  %14 = trunc i32 %1 to i8
  %15 = and i8 %14, 63
  %16 = or disjoint i8 %15, -128
  %17 = getelementptr inbounds i8, ptr %3, i64 1
  store i8 %16, ptr %17, align 1, !tbaa !5
  br label %55

18:                                               ; preds = %8
  %19 = and i32 %1, 2147481600
  %or.cond = icmp eq i32 %19, 55296
  br i1 %or.cond, label %55, label %20

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

22:                                               ; preds = %20
  %23 = lshr i32 %1, 12
  %24 = trunc nuw i32 %23 to i8
  %25 = or disjoint i8 %24, -32
  store i8 %25, ptr %3, align 1, !tbaa !5
  %26 = lshr i32 %1, 6
  %27 = trunc i32 %26 to i8
  %28 = and i8 %27, 63
  %29 = or disjoint i8 %28, -128
  %30 = getelementptr inbounds i8, ptr %3, i64 1
  store i8 %29, ptr %30, align 1, !tbaa !5
  %31 = trunc i32 %1 to i8
  %32 = and i8 %31, 63
  %33 = or disjoint i8 %32, -128
  %34 = getelementptr inbounds i8, ptr %3, i64 2
  store i8 %33, ptr %34, align 1, !tbaa !5
  br label %55

35:                                               ; preds = %20
  %36 = icmp ult i32 %1, 1114112
  br i1 %36, label %37, label %55

37:                                               ; preds = %35
  %38 = lshr i32 %1, 18
  %39 = trunc nuw i32 %38 to i8
  %40 = or disjoint i8 %39, -16
  store i8 %40, ptr %3, align 1, !tbaa !5
  %41 = lshr i32 %1, 12
  %42 = trunc i32 %41 to i8
  %43 = and i8 %42, 63
  %44 = or disjoint i8 %43, -128
  %45 = getelementptr inbounds i8, ptr %3, i64 1
  store i8 %44, ptr %45, align 1, !tbaa !5
  %46 = lshr i32 %1, 6
  %47 = trunc i32 %46 to i8
  %48 = and i8 %47, 63
  %49 = or disjoint i8 %48, -128
  %50 = getelementptr inbounds i8, ptr %3, i64 2
  store i8 %49, ptr %50, align 1, !tbaa !5
  %51 = trunc i32 %1 to i8
  %52 = and i8 %51, 63
  %53 = or disjoint i8 %52, -128
  %54 = getelementptr inbounds i8, ptr %3, i64 3
  store i8 %53, ptr %54, align 1, !tbaa !5
  br label %55

55:                                               ; preds = %10, %22, %37, %35, %18, %6
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #4
  call void @_ZNSaIcEC2Ev(ptr noundef nonnull align 1 dereferenceable(1) %4) #4
  invoke void @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull %3, ptr noundef nonnull align 1 dereferenceable(1) %4)
          to label %56 unwind label %57

56:                                               ; preds = %55
  call void @_ZNSt15__new_allocatorIcED2Ev(ptr noundef nonnull align 1 dereferenceable(1) %4) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 5, ptr nonnull %3) #4
  ret void

57:                                               ; preds = %55
  %58 = landingpad { ptr, i32 }
          cleanup
  call void @_ZNSt15__new_allocatorIcED2Ev(ptr noundef nonnull align 1 dereferenceable(1) %4) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 5, ptr nonnull %3) #4
  resume { ptr, i32 } %58
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: mustprogress nounwind uwtable
declare void @_ZNSaIcEC2Ev(ptr noundef nonnull align 1 dereferenceable(1)) unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef, ptr noundef nonnull align 1 dereferenceable(1)) unnamed_addr #1 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt15__new_allocatorIcED2Ev(ptr noundef nonnull align 1 dereferenceable(1)) unnamed_addr #3 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}


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