; LLVM IR from 0intro/wmii :: lib/libutf (runestrecpy)

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

; Function Attrs: nounwind uwtable
define dso_local ptr @runestrecpy(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %6, align 8, !tbaa !5
  %10 = icmp uge ptr %8, %9
  br i1 %10, label %11, label %13

11:                                               ; preds = %3
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %12, ptr %4, align 8
  br label %31

13:                                               ; preds = %3
  br label %14

14:                                               ; preds = %28, %13
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = getelementptr inbounds i32, ptr %15, i32 1
  store ptr %16, ptr %7, align 8, !tbaa !5
  %17 = load i32, ptr %15, align 4, !tbaa !9
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds i32, ptr %18, i32 1
  store ptr %19, ptr %5, align 8, !tbaa !5
  store i32 %17, ptr %18, align 4, !tbaa !9
  %20 = icmp ne i32 %17, 0
  br i1 %20, label %21, label %29

21:                                               ; preds = %14
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = icmp eq ptr %22, %23
  br i1 %24, label %25, label %28

25:                                               ; preds = %21
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds i32, ptr %26, i32 -1
  store ptr %27, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %27, align 4, !tbaa !9
  br label %29

28:                                               ; preds = %21
  br label %14, !llvm.loop !11

29:                                               ; preds = %25, %14
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %30, ptr %4, align 8
  br label %31

31:                                               ; preds = %29, %11
  %32 = load ptr, ptr %4, align 8
  ret ptr %32
}

attributes #0 = { 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" }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local ptr @runestrecpy(ptr noundef writeonly %0, ptr noundef readnone %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %.not = icmp ult ptr %0, %1
  br i1 %.not, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %3, %6
  %.011 = phi ptr [ %5, %6 ], [ %0, %3 ]
  %.0 = phi ptr [ %7, %6 ], [ %2, %3 ]
  %4 = load i32, ptr %.0, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %.011, i64 4
  store i32 %4, ptr %.011, align 4, !tbaa !5
  %.not16 = icmp eq i32 %4, 0
  br i1 %.not16, label %.loopexit, label %6

6:                                                ; preds = %.preheader
  %7 = getelementptr inbounds i8, ptr %.0, i64 4
  %8 = icmp eq ptr %5, %1
  br i1 %8, label %9, label %.preheader, !llvm.loop !9

9:                                                ; preds = %6
  store i32 0, ptr %.011, align 4, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader, %9, %3
  %.010 = phi ptr [ %0, %3 ], [ %.011, %9 ], [ %5, %.preheader ]
  ret ptr %.010
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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" }

!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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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