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

; 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 @utfrrune(ptr noundef %0, i64 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %10 = load i64, ptr %5, align 8, !tbaa !9
  %11 = icmp slt i64 %10, 128
  br i1 %11, label %12, label %17

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = load i64, ptr %5, align 8, !tbaa !9
  %15 = trunc i64 %14 to i32
  %16 = call ptr @strrchr(ptr noundef %13, i32 noundef %15) #5
  store ptr %16, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %52

17:                                               ; preds = %2
  store ptr null, ptr %8, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %48, %35, %17
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = load i8, ptr %19, align 1, !tbaa !11
  %21 = zext i8 %20 to i64
  store i64 %21, ptr %6, align 8, !tbaa !9
  %22 = load i64, ptr %6, align 8, !tbaa !9
  %23 = icmp slt i64 %22, 128
  br i1 %23, label %24, label %38

24:                                               ; preds = %18
  %25 = load i64, ptr %6, align 8, !tbaa !9
  %26 = icmp eq i64 %25, 0
  br i1 %26, label %27, label %29

27:                                               ; preds = %24
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %28, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %52

29:                                               ; preds = %24
  %30 = load i64, ptr %6, align 8, !tbaa !9
  %31 = load i64, ptr %5, align 8, !tbaa !9
  %32 = icmp eq i64 %30, %31
  br i1 %32, label %33, label %35

33:                                               ; preds = %29
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %34, ptr %8, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %33, %29
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i32 1
  store ptr %37, ptr %4, align 8, !tbaa !5
  br label %18

38:                                               ; preds = %18
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = call i32 @chartorune(ptr noundef %7, ptr noundef %39)
  %41 = sext i32 %40 to i64
  store i64 %41, ptr %6, align 8, !tbaa !9
  %42 = load i32, ptr %7, align 4, !tbaa !12
  %43 = zext i32 %42 to i64
  %44 = load i64, ptr %5, align 8, !tbaa !9
  %45 = icmp eq i64 %43, %44
  br i1 %45, label %46, label %48

46:                                               ; preds = %38
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %47, ptr %8, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %46, %38
  %49 = load i64, ptr %6, align 8, !tbaa !9
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %50, i64 %49
  store ptr %51, ptr %4, align 8, !tbaa !5
  br label %18

52:                                               ; preds = %27, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %53 = load ptr, ptr %3, align 8
  ret ptr %53
}

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

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strrchr(ptr noundef, i32 noundef) #2

declare i32 @chartorune(ptr noundef, ptr noundef) #3

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

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

!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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !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"

; Function Attrs: nounwind uwtable
define dso_local ptr @utfrrune(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  %4 = icmp slt i64 %1, 128
  br i1 %4, label %5, label %.outer

5:                                                ; preds = %2
  %6 = trunc i64 %1 to i32
  %7 = tail call ptr @strrchr(ptr noundef nonnull dereferenceable(1) %0, i32 noundef %6) #5
  br label %.loopexit

.lr.ph:                                           ; preds = %.outer, %10
  %8 = phi i8 [ %12, %10 ], [ %20, %.outer ]
  %.01722 = phi ptr [ %11, %10 ], [ %.017.ph, %.outer ]
  %9 = icmp eq i8 %8, 0
  br i1 %9, label %.loopexit, label %10

10:                                               ; preds = %.lr.ph
  %11 = getelementptr inbounds i8, ptr %.01722, i64 1
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %13 = icmp sgt i8 %12, -1
  br i1 %13, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %10, %.outer
  %.017.lcssa = phi ptr [ %.017.ph, %.outer ], [ %11, %10 ]
  %14 = call i32 @chartorune(ptr noundef nonnull %3, ptr noundef nonnull %.017.lcssa) #4
  %15 = sext i32 %14 to i64
  %16 = load i32, ptr %3, align 4, !tbaa !8
  %17 = zext i32 %16 to i64
  %18 = icmp eq i64 %17, %1
  %spec.select = select i1 %18, ptr %.017.lcssa, ptr %.0.ph
  %19 = getelementptr inbounds i8, ptr %.017.lcssa, i64 %15
  br label %.outer

.outer:                                           ; preds = %2, %._crit_edge
  %.017.ph = phi ptr [ %19, %._crit_edge ], [ %0, %2 ]
  %.0.ph = phi ptr [ %spec.select, %._crit_edge ], [ null, %2 ]
  %20 = load i8, ptr %.017.ph, align 1, !tbaa !5
  %21 = icmp sgt i8 %20, -1
  br i1 %21, label %.lr.ph, label %._crit_edge

.loopexit:                                        ; preds = %.lr.ph, %5
  %.016 = phi ptr [ %7, %5 ], [ %.0.ph, %.lr.ph ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  ret ptr %.016
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare ptr @strrchr(ptr noundef, i32 noundef) local_unnamed_addr #2

declare i32 @chartorune(ptr noundef, ptr noundef) local_unnamed_addr #3

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

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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { "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 }
attributes #5 = { nounwind willreturn memory(read) }

!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/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}


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