; LLVM IR from facebook/redex :: libresource (Unicode)

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

@stderr = external global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [21 x i8], align 1

; 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: inlinehint mustprogress nounwind uwtable
declare hidden noundef i64 @_ZL27utf32_codepoint_utf8_lengthDi(i32 noundef zeroext) #1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: mustprogress uwtable
define dso_local void @utf32_to_utf8(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) #3 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i64 %3, ptr %8, align 8, !tbaa !9
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %21, label %15

15:                                               ; preds = %4
  %16 = load i64, ptr %6, align 8, !tbaa !9
  %17 = icmp eq i64 %16, 0
  br i1 %17, label %21, label %18

18:                                               ; preds = %15
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %18, %15, %4
  br label %103

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %23, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load i64, ptr %6, align 8, !tbaa !9
  %26 = getelementptr inbounds i32, ptr %24, i64 %25
  store ptr %26, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %27, ptr %11, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %63, %22
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = icmp ult ptr %29, %30
  br i1 %31, label %32, label %75

32:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = load i32, ptr %33, align 4, !tbaa !11
  %35 = call noundef i64 @_ZL27utf32_codepoint_utf8_lengthDi(i32 noundef zeroext %34)
  store i64 %35, ptr %12, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %32
  %37 = load i64, ptr %8, align 8, !tbaa !9
  %38 = load i64, ptr %12, align 8, !tbaa !9
  %39 = icmp ult i64 %37, %38
  br i1 %39, label %40, label %61

40:                                               ; preds = %36
  br label %41

41:                                               ; preds = %40
  %42 = load ptr, ptr @stderr, align 8, !tbaa !5
  %43 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %42, ptr noundef @.str.4) #5
  %44 = load ptr, ptr @stderr, align 8, !tbaa !5
  %45 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %44, ptr noundef @.str.5) #5
  %46 = load ptr, ptr @stderr, align 8, !tbaa !5
  %47 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %46, ptr noundef @.str.3) #5
  br label %48

48:                                               ; preds = %41
  br label %49

49:                                               ; preds = %48
  br label %50

50:                                               ; preds = %49
  %51 = load ptr, ptr @stderr, align 8, !tbaa !5
  %52 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %51, ptr noundef @.str.4) #5
  %53 = load ptr, ptr @stderr, align 8, !tbaa !5
  %54 = load i64, ptr %8, align 8, !tbaa !9
  %55 = load i64, ptr %12, align 8, !tbaa !9
  %56 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %53, ptr noundef @.str.6, i64 noundef %54, i64 noundef %55) #5
  %57 = load ptr, ptr @stderr, align 8, !tbaa !5
  %58 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %57, ptr noundef @.str.3) #5
  br label %59

59:                                               ; preds = %50
  br label %60

60:                                               ; preds = %59
  call void @abort() #6
  unreachable

61:                                               ; preds = %36
  br label %62

62:                                               ; preds = %61
  br label %63

63:                                               ; preds = %62
  %64 = load ptr, ptr %11, align 8, !tbaa !5
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  %66 = getelementptr inbounds i32, ptr %65, i32 1
  store ptr %66, ptr %9, align 8, !tbaa !5
  %67 = load i32, ptr %65, align 4, !tbaa !11
  %68 = load i64, ptr %12, align 8, !tbaa !9
  call void @_ZL23utf32_codepoint_to_utf8PhDim(ptr noundef %64, i32 noundef zeroext %67, i64 noundef %68)
  %69 = load i64, ptr %12, align 8, !tbaa !9
  %70 = load ptr, ptr %11, align 8, !tbaa !5
  %71 = getelementptr inbounds i8, ptr %70, i64 %69
  store ptr %71, ptr %11, align 8, !tbaa !5
  %72 = load i64, ptr %12, align 8, !tbaa !9
  %73 = load i64, ptr %8, align 8, !tbaa !9
  %74 = sub i64 %73, %72
  store i64 %74, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %28, !llvm.loop !13

75:                                               ; preds = %28
  br label %76

76:                                               ; preds = %75
  %77 = load i64, ptr %8, align 8, !tbaa !9
  %78 = icmp ult i64 %77, 1
  br i1 %78, label %79, label %99

79:                                               ; preds = %76
  br label %80

80:                                               ; preds = %79
  %81 = load ptr, ptr @stderr, align 8, !tbaa !5
  %82 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %81, ptr noundef @.str.4) #5
  %83 = load ptr, ptr @stderr, align 8, !tbaa !5
  %84 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %83, ptr noundef @.str.7) #5
  %85 = load ptr, ptr @stderr, align 8, !tbaa !5
  %86 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %85, ptr noundef @.str.3) #5
  br label %87

87:                                               ; preds = %80
  br label %88

88:                                               ; preds = %87
  br label %89

89:                                               ; preds = %88
  %90 = load ptr, ptr @stderr, align 8, !tbaa !5
  %91 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %90, ptr noundef @.str.4) #5
  %92 = load ptr, ptr @stderr, align 8, !tbaa !5
  %93 = load i64, ptr %8, align 8, !tbaa !9
  %94 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %92, ptr noundef @.str.8, i64 noundef %93) #5
  %95 = load ptr, ptr @stderr, align 8, !tbaa !5
  %96 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %95, ptr noundef @.str.3) #5
  br label %97

97:                                               ; preds = %89
  br label %98

98:                                               ; preds = %97
  call void @abort() #6
  unreachable

99:                                               ; preds = %76
  br label %100

100:                                              ; preds = %99
  br label %101

101:                                              ; preds = %100
  %102 = load ptr, ptr %11, align 8, !tbaa !5
  store i8 0, ptr %102, align 1, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %103

103:                                              ; preds = %101, %21
  ret void
}

; Function Attrs: noreturn nounwind
declare void @abort() #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden void @_ZL23utf32_codepoint_to_utf8PhDim(ptr noundef, i32 noundef zeroext, i64 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nounwind "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 = { 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 = { noreturn nounwind "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 #5 = { nounwind }
attributes #6 = { noreturn 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 = !{!12, !12, i64 0}
!12 = !{!"char32_t", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i64 @_ZL27utf32_codepoint_utf8_lengthDi(i32 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @utf32_to_utf8(ptr noundef readonly %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #2 {
  %5 = icmp eq ptr %0, null
  %6 = icmp eq i64 %1, 0
  %or.cond = or i1 %5, %6
  %7 = icmp eq ptr %2, null
  %or.cond3 = or i1 %or.cond, %7
  br i1 %or.cond3, label %48, label %8

8:                                                ; preds = %4
  %9 = getelementptr inbounds i32, ptr %0, i64 %1
  %10 = icmp sgt i64 %1, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %8, %27
  %.036 = phi i64 [ %31, %27 ], [ %3, %8 ]
  %.02635 = phi ptr [ %30, %27 ], [ %2, %8 ]
  %.02734 = phi ptr [ %28, %27 ], [ %0, %8 ]
  %11 = load i32, ptr %.02734, align 4, !tbaa !5
  %12 = tail call noundef i64 @_ZL27utf32_codepoint_utf8_lengthDi(i32 noundef zeroext %11)
  %13 = icmp ult i64 %.036, %12
  br i1 %13, label %14, label %27

14:                                               ; preds = %.lr.ph
  %15 = load ptr, ptr @stderr, align 8, !tbaa !9
  %16 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef nonnull @.str.4) #4
  %17 = load ptr, ptr @stderr, align 8, !tbaa !9
  %18 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %17, ptr noundef nonnull @.str.5) #4
  %19 = load ptr, ptr @stderr, align 8, !tbaa !9
  %20 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef nonnull @.str.3) #4
  %21 = load ptr, ptr @stderr, align 8, !tbaa !9
  %22 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str.4) #4
  %23 = load ptr, ptr @stderr, align 8, !tbaa !9
  %24 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef nonnull @.str.6, i64 noundef %.036, i64 noundef %12) #4
  %25 = load ptr, ptr @stderr, align 8, !tbaa !9
  %26 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef nonnull @.str.3) #4
  tail call void @abort() #5
  unreachable

27:                                               ; preds = %.lr.ph
  %28 = getelementptr inbounds i8, ptr %.02734, i64 4
  %29 = load i32, ptr %.02734, align 4, !tbaa !5
  tail call void @_ZL23utf32_codepoint_to_utf8PhDim(ptr noundef %.02635, i32 noundef zeroext %29, i64 noundef %12)
  %30 = getelementptr inbounds i8, ptr %.02635, i64 %12
  %31 = sub i64 %.036, %12
  %32 = icmp ult ptr %28, %9
  br i1 %32, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %27, %8
  %.026.lcssa = phi ptr [ %2, %8 ], [ %30, %27 ]
  %.0.lcssa = phi i64 [ %3, %8 ], [ %31, %27 ]
  %33 = icmp eq i64 %.0.lcssa, 0
  br i1 %33, label %34, label %47

34:                                               ; preds = %._crit_edge
  %35 = load ptr, ptr @stderr, align 8, !tbaa !9
  %36 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef nonnull @.str.4) #4
  %37 = load ptr, ptr @stderr, align 8, !tbaa !9
  %38 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %37, ptr noundef nonnull @.str.7) #4
  %39 = load ptr, ptr @stderr, align 8, !tbaa !9
  %40 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %39, ptr noundef nonnull @.str.3) #4
  %41 = load ptr, ptr @stderr, align 8, !tbaa !9
  %42 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %41, ptr noundef nonnull @.str.4) #4
  %43 = load ptr, ptr @stderr, align 8, !tbaa !9
  %44 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %43, ptr noundef nonnull @.str.8, i64 noundef 0) #4
  %45 = load ptr, ptr @stderr, align 8, !tbaa !9
  %46 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef nonnull @.str.3) #4
  tail call void @abort() #5
  unreachable

47:                                               ; preds = %._crit_edge
  store i8 0, ptr %.026.lcssa, align 1, !tbaa !13
  br label %48

48:                                               ; preds = %4, %47
  ret void
}

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden void @_ZL23utf32_codepoint_to_utf8PhDim(ptr noundef, i32 noundef zeroext, i64 noundef) local_unnamed_addr #0

attributes #0 = { 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 #1 = { nofree nounwind "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 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 #3 = { noreturn nounwind "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 = { cold nounwind }
attributes #5 = { noreturn 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 = !{!"char32_t", !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!7, !7, i64 0}


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