; LLVM IR from kparc/ksimple :: a (Ovr)

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

@F = external dso_local global [12 x ptr], align 16

; 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: nounwind uwtable
declare dso_local i64 @_r(i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @Ovr(i64 noundef %0, i64 noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !5
  %12 = load i64, ptr %4, align 8, !tbaa !5
  %13 = icmp ugt i64 256, %12
  br i1 %13, label %14, label %16

14:                                               ; preds = %2
  %15 = load i64, ptr %4, align 8, !tbaa !5
  br label %55

16:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %17 = load i64, ptr %4, align 8, !tbaa !5
  %18 = inttoptr i64 %17 to ptr
  %19 = load i8, ptr %18, align 1, !tbaa !9
  %20 = zext i8 %19 to i64
  store i64 %20, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %21 = load i64, ptr %4, align 8, !tbaa !5
  %22 = inttoptr i64 %21 to ptr
  %23 = getelementptr inbounds i8, ptr %22, i64 -1
  %24 = load i8, ptr %23, align 1, !tbaa !9
  %25 = zext i8 %24 to i32
  %26 = sub nsw i32 %25, 1
  store i32 %26, ptr %8, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !10
  br label %27

27:                                               ; preds = %45, %16
  %28 = load i32, ptr %9, align 4, !tbaa !10
  %29 = load i32, ptr %8, align 4, !tbaa !10
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %31, label %48

31:                                               ; preds = %27
  %32 = load i64, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds [12 x ptr], ptr @F, i64 0, i64 %32
  %34 = load ptr, ptr %33, align 8, !tbaa !12
  %35 = load i64, ptr %7, align 8, !tbaa !5
  %36 = load i64, ptr %4, align 8, !tbaa !5
  %37 = inttoptr i64 %36 to ptr
  %38 = load i32, ptr %9, align 4, !tbaa !10
  %39 = add nsw i32 %38, 1
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds i8, ptr %37, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !9
  %43 = zext i8 %42 to i64
  %44 = call i64 %34(i64 noundef %35, i64 noundef %43)
  store i64 %44, ptr %7, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %31
  %46 = load i32, ptr %9, align 4, !tbaa !10
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %9, align 4, !tbaa !10
  br label %27, !llvm.loop !14

48:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %49 = load i64, ptr %7, align 8, !tbaa !5
  store i64 %49, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  %50 = load i64, ptr %10, align 8, !tbaa !5
  store i64 %50, ptr %6, align 8, !tbaa !5
  %51 = load i64, ptr %4, align 8, !tbaa !5
  %52 = call i64 @_r(i64 noundef %51)
  %53 = load i64, ptr %6, align 8, !tbaa !5
  store i64 %53, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %54 = load i64, ptr %11, align 8, !tbaa !5
  br label %55

55:                                               ; preds = %48, %14
  %56 = phi i64 [ %15, %14 ], [ %54, %48 ]
  store i64 %56, ptr %5, align 8, !tbaa !5
  %57 = load i64, ptr %5, align 8, !tbaa !5
  ret i64 %57
}

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

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@F = external dso_local local_unnamed_addr global [12 x ptr], align 16

; Function Attrs: nounwind uwtable
declare dso_local i64 @_r(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i64 @Ovr(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = icmp ult i64 %1, 256
  br i1 %3, label %21, label %4

4:                                                ; preds = %2
  %5 = inttoptr i64 %1 to ptr
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %7 = zext i8 %6 to i64
  %8 = getelementptr inbounds i8, ptr %5, i64 -1
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %10 = icmp ugt i8 %9, 1
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %11 = zext i8 %9 to i64
  %12 = add nuw nsw i64 %11, 4294967295
  %13 = getelementptr inbounds [12 x ptr], ptr @F, i64 0, i64 %0
  %wide.trip.count = and i64 %12, 4294967295
  br label %14

14:                                               ; preds = %.lr.ph, %14
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %14 ]
  %.020 = phi i64 [ %7, %.lr.ph ], [ %19, %14 ]
  %15 = load ptr, ptr %13, align 8, !tbaa !8
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %16 = getelementptr inbounds i8, ptr %5, i64 %indvars.iv.next
  %17 = load i8, ptr %16, align 1, !tbaa !5
  %18 = zext i8 %17 to i64
  %19 = tail call i64 %15(i64 noundef %.020, i64 noundef %18) #1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %14, !llvm.loop !10

._crit_edge:                                      ; preds = %14, %4
  %.0.lcssa = phi i64 [ %7, %4 ], [ %19, %14 ]
  %20 = tail call i64 @_r(i64 noundef %1)
  br label %21

21:                                               ; preds = %2, %._crit_edge
  %22 = phi i64 [ %.0.lcssa, %._crit_edge ], [ %1, %2 ]
  ret i64 %22
}

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 = { 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/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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