; LLVM IR from sslab-gatech/janus :: lkl/lib (rational)

; 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 void @rational_best_approximation(i64 noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4, ptr noundef %5) #0 {
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  %18 = alloca i64, align 8
  %19 = alloca i64, align 8
  %20 = alloca i64, align 8
  %21 = alloca i32, align 4
  store i64 %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !5
  store i64 %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !9
  store ptr %5, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #2
  %22 = load i64, ptr %7, align 8, !tbaa !5
  store i64 %22, ptr %13, align 8, !tbaa !5
  %23 = load i64, ptr %8, align 8, !tbaa !5
  store i64 %23, ptr %14, align 8, !tbaa !5
  store i64 0, ptr %18, align 8, !tbaa !5
  store i64 0, ptr %15, align 8, !tbaa !5
  store i64 1, ptr %16, align 8, !tbaa !5
  store i64 1, ptr %17, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %64, %6
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #2
  %25 = load i64, ptr %17, align 8, !tbaa !5
  %26 = load i64, ptr %9, align 8, !tbaa !5
  %27 = icmp ugt i64 %25, %26
  br i1 %27, label %32, label %28

28:                                               ; preds = %24
  %29 = load i64, ptr %18, align 8, !tbaa !5
  %30 = load i64, ptr %10, align 8, !tbaa !5
  %31 = icmp ugt i64 %29, %30
  br i1 %31, label %32, label %35

32:                                               ; preds = %28, %24
  %33 = load i64, ptr %15, align 8, !tbaa !5
  store i64 %33, ptr %17, align 8, !tbaa !5
  %34 = load i64, ptr %16, align 8, !tbaa !5
  store i64 %34, ptr %18, align 8, !tbaa !5
  store i32 2, ptr %21, align 4
  br label %62

35:                                               ; preds = %28
  %36 = load i64, ptr %14, align 8, !tbaa !5
  %37 = icmp eq i64 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %35
  store i32 2, ptr %21, align 4
  br label %62

39:                                               ; preds = %35
  %40 = load i64, ptr %14, align 8, !tbaa !5
  store i64 %40, ptr %19, align 8, !tbaa !5
  %41 = load i64, ptr %13, align 8, !tbaa !5
  %42 = load i64, ptr %14, align 8, !tbaa !5
  %43 = udiv i64 %41, %42
  store i64 %43, ptr %20, align 8, !tbaa !5
  %44 = load i64, ptr %13, align 8, !tbaa !5
  %45 = load i64, ptr %14, align 8, !tbaa !5
  %46 = urem i64 %44, %45
  store i64 %46, ptr %14, align 8, !tbaa !5
  %47 = load i64, ptr %19, align 8, !tbaa !5
  store i64 %47, ptr %13, align 8, !tbaa !5
  %48 = load i64, ptr %15, align 8, !tbaa !5
  %49 = load i64, ptr %20, align 8, !tbaa !5
  %50 = load i64, ptr %17, align 8, !tbaa !5
  %51 = mul i64 %49, %50
  %52 = add i64 %48, %51
  store i64 %52, ptr %19, align 8, !tbaa !5
  %53 = load i64, ptr %17, align 8, !tbaa !5
  store i64 %53, ptr %15, align 8, !tbaa !5
  %54 = load i64, ptr %19, align 8, !tbaa !5
  store i64 %54, ptr %17, align 8, !tbaa !5
  %55 = load i64, ptr %16, align 8, !tbaa !5
  %56 = load i64, ptr %20, align 8, !tbaa !5
  %57 = load i64, ptr %18, align 8, !tbaa !5
  %58 = mul i64 %56, %57
  %59 = add i64 %55, %58
  store i64 %59, ptr %19, align 8, !tbaa !5
  %60 = load i64, ptr %18, align 8, !tbaa !5
  store i64 %60, ptr %16, align 8, !tbaa !5
  %61 = load i64, ptr %19, align 8, !tbaa !5
  store i64 %61, ptr %18, align 8, !tbaa !5
  store i32 0, ptr %21, align 4
  br label %62

62:                                               ; preds = %39, %38, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #2
  %63 = load i32, ptr %21, align 4
  switch i32 %63, label %70 [
    i32 0, label %64
    i32 2, label %65
  ]

64:                                               ; preds = %62
  br label %24

65:                                               ; preds = %62
  %66 = load i64, ptr %17, align 8, !tbaa !5
  %67 = load ptr, ptr %11, align 8, !tbaa !9
  store i64 %66, ptr %67, align 8, !tbaa !5
  %68 = load i64, ptr %18, align 8, !tbaa !5
  %69 = load ptr, ptr %12, align 8, !tbaa !9
  store i64 %68, ptr %69, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  ret void

70:                                               ; preds = %62
  unreachable
}

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

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

!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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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: nofree norecurse nosync nounwind memory(argmem: write) uwtable
define dso_local void @rational_best_approximation(i64 noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr nocapture noundef writeonly %4, ptr nocapture noundef writeonly %5) local_unnamed_addr #0 {
  %7 = icmp eq i64 %2, 0
  br i1 %7, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %6, %9
  %.02955 = phi i64 [ %.03054, %9 ], [ %0, %6 ]
  %.03054 = phi i64 [ %11, %9 ], [ %1, %6 ]
  %.03253 = phi i64 [ %15, %9 ], [ 0, %6 ]
  %.03452 = phi i64 [ %13, %9 ], [ 1, %6 ]
  %.03651 = phi i64 [ %.03253, %9 ], [ 1, %6 ]
  %.03850 = phi i64 [ %.03452, %9 ], [ 0, %6 ]
  %8 = icmp eq i64 %.03054, 0
  br i1 %8, label %._crit_edge, label %9

9:                                                ; preds = %.lr.ph
  %10 = udiv i64 %.02955, %.03054
  %11 = urem i64 %.02955, %.03054
  %12 = mul i64 %10, %.03452
  %13 = add i64 %12, %.03850
  %14 = mul i64 %10, %.03253
  %15 = add i64 %14, %.03651
  %16 = icmp ugt i64 %13, %2
  %17 = icmp ugt i64 %15, %3
  %or.cond = select i1 %16, i1 true, i1 %17
  br i1 %or.cond, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %9, %6
  %.135.ph = phi i64 [ 0, %6 ], [ %.03452, %9 ], [ %.03452, %.lr.ph ]
  %.133.ph = phi i64 [ 1, %6 ], [ %.03253, %9 ], [ %.03253, %.lr.ph ]
  store i64 %.135.ph, ptr %4, align 8, !tbaa !5
  store i64 %.133.ph, ptr %5, align 8, !tbaa !5
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: write) 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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