; LLVM IR from quantumlib/Stim :: src/stim/diagram (base64)

; 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::basic_string_view" = type { i64, ptr }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef signext i8 @_Z17u6_to_base64_charh(i8 noundef zeroext) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN18stim_draw_internal23write_data_as_base64_toESt17basic_string_viewIcSt11char_traitsIcEERSo(i64 %0, ptr %1, ptr noundef nonnull align 8 dereferenceable(8) %2) #1 {
  %4 = alloca %"class.std::basic_string_view", align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i8, align 1
  %12 = getelementptr inbounds { i64, ptr }, ptr %4, i32 0, i32 0
  store i64 %0, ptr %12, align 8
  %13 = getelementptr inbounds { i64, ptr }, ptr %4, i32 0, i32 1
  store ptr %1, ptr %13, align 8
  store ptr %2, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 0, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store ptr %4, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %14 = load ptr, ptr %8, align 8, !tbaa !5
  %15 = call noundef ptr @_ZNKSt17basic_string_viewIcSt11char_traitsIcEE5beginEv(ptr noundef nonnull align 8 dereferenceable(16) %14) #4
  store ptr %15, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = call noundef ptr @_ZNKSt17basic_string_viewIcSt11char_traitsIcEE3endEv(ptr noundef nonnull align 8 dereferenceable(16) %16) #4
  store ptr %17, ptr %10, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %66, %3
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = load ptr, ptr %10, align 8, !tbaa !5
  %21 = icmp ne ptr %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %69

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #4
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = load i8, ptr %24, align 1, !tbaa !13
  store i8 %25, ptr %11, align 1, !tbaa !13
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = shl i32 %26, 8
  store i32 %27, ptr %6, align 4, !tbaa !9
  %28 = load i8, ptr %11, align 1, !tbaa !13
  %29 = zext i8 %28 to i32
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = or i32 %30, %29
  store i32 %31, ptr %6, align 4, !tbaa !9
  %32 = load i64, ptr %7, align 8, !tbaa !11
  %33 = add i64 %32, 8
  store i64 %33, ptr %7, align 8, !tbaa !11
  %34 = load i64, ptr %7, align 8, !tbaa !11
  %35 = icmp eq i64 %34, 24
  br i1 %35, label %36, label %65

36:                                               ; preds = %23
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = lshr i32 %38, 18
  %40 = and i32 %39, 63
  %41 = trunc i32 %40 to i8
  %42 = call noundef signext i8 @_Z17u6_to_base64_charh(i8 noundef zeroext %41)
  %43 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %37, i8 noundef signext %42)
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = lshr i32 %45, 12
  %47 = and i32 %46, 63
  %48 = trunc i32 %47 to i8
  %49 = call noundef signext i8 @_Z17u6_to_base64_charh(i8 noundef zeroext %48)
  %50 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %44, i8 noundef signext %49)
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = load i32, ptr %6, align 4, !tbaa !9
  %53 = lshr i32 %52, 6
  %54 = and i32 %53, 63
  %55 = trunc i32 %54 to i8
  %56 = call noundef signext i8 @_Z17u6_to_base64_charh(i8 noundef zeroext %55)
  %57 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %51, i8 noundef signext %56)
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = load i32, ptr %6, align 4, !tbaa !9
  %60 = lshr i32 %59, 0
  %61 = and i32 %60, 63
  %62 = trunc i32 %61 to i8
  %63 = call noundef signext i8 @_Z17u6_to_base64_charh(i8 noundef zeroext %62)
  %64 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %58, i8 noundef signext %63)
  store i64 0, ptr %7, align 8, !tbaa !11
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %36, %23
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #4
  br label %66

66:                                               ; preds = %65
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = getelementptr inbounds i8, ptr %67, i32 1
  store ptr %68, ptr %9, align 8, !tbaa !5
  br label %18

69:                                               ; preds = %22
  %70 = load i64, ptr %7, align 8, !tbaa !11
  %71 = icmp ne i64 %70, 0
  br i1 %71, label %72, label %107

72:                                               ; preds = %69
  %73 = load i64, ptr %7, align 8, !tbaa !11
  %74 = sub i64 24, %73
  %75 = load i32, ptr %6, align 4, !tbaa !9
  %76 = trunc i64 %74 to i32
  %77 = shl i32 %75, %76
  store i32 %77, ptr %6, align 4, !tbaa !9
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = load i32, ptr %6, align 4, !tbaa !9
  %80 = lshr i32 %79, 18
  %81 = and i32 %80, 63
  %82 = trunc i32 %81 to i8
  %83 = call noundef signext i8 @_Z17u6_to_base64_charh(i8 noundef zeroext %82)
  %84 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %78, i8 noundef signext %83)
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = load i32, ptr %6, align 4, !tbaa !9
  %87 = lshr i32 %86, 12
  %88 = and i32 %87, 63
  %89 = trunc i32 %88 to i8
  %90 = call noundef signext i8 @_Z17u6_to_base64_charh(i8 noundef zeroext %89)
  %91 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %85, i8 noundef signext %90)
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = load i64, ptr %7, align 8, !tbaa !11
  %94 = icmp eq i64 %93, 8
  br i1 %94, label %95, label %96

95:                                               ; preds = %72
  br label %102

96:                                               ; preds = %72
  %97 = load i32, ptr %6, align 4, !tbaa !9
  %98 = lshr i32 %97, 6
  %99 = and i32 %98, 63
  %100 = trunc i32 %99 to i8
  %101 = call noundef signext i8 @_Z17u6_to_base64_charh(i8 noundef zeroext %100)
  br label %102

102:                                              ; preds = %96, %95
  %103 = phi i8 [ 61, %95 ], [ %101, %96 ]
  %104 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %92, i8 noundef signext %103)
  %105 = load ptr, ptr %5, align 8, !tbaa !5
  %106 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %105, i8 noundef signext 61)
  br label %107

107:                                              ; preds = %102, %69
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  ret void
}

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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8), i8 noundef signext) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!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::basic_string_view" = type { i64, ptr }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef signext i8 @_Z17u6_to_base64_charh(i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN18stim_draw_internal23write_data_as_base64_toESt17basic_string_viewIcSt11char_traitsIcEERSo(i64 %0, ptr %1, ptr noundef nonnull align 8 dereferenceable(8) %2) local_unnamed_addr #1 {
  %4 = alloca %"class.std::basic_string_view", align 8
  store i64 %0, ptr %4, align 8
  %5 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr %1, ptr %5, align 8
  %6 = call noundef ptr @_ZNKSt17basic_string_viewIcSt11char_traitsIcEE5beginEv(ptr noundef nonnull align 8 dereferenceable(16) %4) #3
  %7 = call noundef ptr @_ZNKSt17basic_string_viewIcSt11char_traitsIcEE3endEv(ptr noundef nonnull align 8 dereferenceable(16) %4) #3
  %.not34 = icmp eq ptr %6, %7
  br i1 %.not34, label %._crit_edge.thread, label %.lr.ph

._crit_edge:                                      ; preds = %33
  %.not33 = icmp eq i64 %.130, 0
  br i1 %.not33, label %._crit_edge.thread, label %35

.lr.ph:                                           ; preds = %3, %33
  %.037 = phi i32 [ %.1, %33 ], [ 0, %3 ]
  %.02936 = phi i64 [ %.130, %33 ], [ 0, %3 ]
  %.03135 = phi ptr [ %34, %33 ], [ %6, %3 ]
  %8 = load i8, ptr %.03135, align 1, !tbaa !5
  %9 = shl i32 %.037, 8
  %10 = zext i8 %8 to i32
  %11 = or disjoint i32 %9, %10
  %12 = add i64 %.02936, 8
  %13 = icmp eq i64 %12, 24
  br i1 %13, label %14, label %33

14:                                               ; preds = %.lr.ph
  %15 = lshr i32 %9, 18
  %16 = trunc i32 %15 to i8
  %17 = and i8 %16, 63
  %18 = call noundef signext i8 @_Z17u6_to_base64_charh(i8 noundef zeroext %17)
  %19 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %2, i8 noundef signext %18)
  %20 = lshr i32 %9, 12
  %21 = trunc i32 %20 to i8
  %22 = and i8 %21, 63
  %23 = call noundef signext i8 @_Z17u6_to_base64_charh(i8 noundef zeroext %22)
  %24 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %2, i8 noundef signext %23)
  %25 = lshr i32 %11, 6
  %26 = trunc i32 %25 to i8
  %27 = and i8 %26, 63
  %28 = call noundef signext i8 @_Z17u6_to_base64_charh(i8 noundef zeroext %27)
  %29 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %2, i8 noundef signext %28)
  %30 = and i8 %8, 63
  %31 = call noundef signext i8 @_Z17u6_to_base64_charh(i8 noundef zeroext %30)
  %32 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %2, i8 noundef signext %31)
  br label %33

33:                                               ; preds = %14, %.lr.ph
  %.130 = phi i64 [ 0, %14 ], [ %12, %.lr.ph ]
  %.1 = phi i32 [ 0, %14 ], [ %11, %.lr.ph ]
  %34 = getelementptr inbounds i8, ptr %.03135, i64 1
  %.not = icmp eq ptr %34, %7
  br i1 %.not, label %._crit_edge, label %.lr.ph

35:                                               ; preds = %._crit_edge
  %36 = trunc i64 %.130 to i32
  %37 = sub i32 24, %36
  %38 = shl i32 %.1, %37
  %39 = lshr i32 %38, 18
  %40 = trunc i32 %39 to i8
  %41 = and i8 %40, 63
  %42 = call noundef signext i8 @_Z17u6_to_base64_charh(i8 noundef zeroext %41)
  %43 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %2, i8 noundef signext %42)
  %44 = lshr i32 %38, 12
  %45 = trunc i32 %44 to i8
  %46 = and i8 %45, 63
  %47 = call noundef signext i8 @_Z17u6_to_base64_charh(i8 noundef zeroext %46)
  %48 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %2, i8 noundef signext %47)
  %49 = icmp eq i64 %.130, 8
  br i1 %49, label %55, label %50

50:                                               ; preds = %35
  %51 = lshr i32 %38, 6
  %52 = trunc i32 %51 to i8
  %53 = and i8 %52, 63
  %54 = call noundef signext i8 @_Z17u6_to_base64_charh(i8 noundef zeroext %53)
  br label %55

55:                                               ; preds = %35, %50
  %56 = phi i8 [ %54, %50 ], [ 61, %35 ]
  %57 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %2, i8 noundef signext %56)
  %58 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %2, i8 noundef signext 61)
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %3, %55, %._crit_edge
  ret void
}

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8), i8 noundef signext) local_unnamed_addr #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 = { 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 = { inlinehint 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 = { 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,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass