; LLVM IR from jgaeddert/liquid-dsp :: src/math/src (modular_arithmetic)

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

@.str = external hidden unnamed_addr constant [88 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [51 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: nounwind uwtable
define dso_local i32 @liquid_factor(i32 noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %12 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %12, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %44, %3
  store i32 2, ptr %8, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %34, %13
  %15 = load i32, ptr %8, align 4, !tbaa !5
  %16 = load i32, ptr %9, align 4, !tbaa !5
  %17 = icmp ule i32 %15, %16
  br i1 %17, label %18, label %37

18:                                               ; preds = %14
  %19 = load i32, ptr %9, align 4, !tbaa !5
  %20 = load i32, ptr %8, align 4, !tbaa !5
  %21 = urem i32 %19, %20
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %33

23:                                               ; preds = %18
  %24 = load i32, ptr %8, align 4, !tbaa !5
  %25 = load ptr, ptr %6, align 8, !tbaa !9
  %26 = load i32, ptr %10, align 4, !tbaa !5
  %27 = add i32 %26, 1
  store i32 %27, ptr %10, align 4, !tbaa !5
  %28 = zext i32 %26 to i64
  %29 = getelementptr inbounds i32, ptr %25, i64 %28
  store i32 %24, ptr %29, align 4, !tbaa !5
  %30 = load i32, ptr %8, align 4, !tbaa !5
  %31 = load i32, ptr %9, align 4, !tbaa !5
  %32 = udiv i32 %31, %30
  store i32 %32, ptr %9, align 4, !tbaa !5
  br label %37

33:                                               ; preds = %18
  br label %34

34:                                               ; preds = %33
  %35 = load i32, ptr %8, align 4, !tbaa !5
  %36 = add i32 %35, 1
  store i32 %36, ptr %8, align 4, !tbaa !5
  br label %14, !llvm.loop !11

37:                                               ; preds = %23, %14
  br label %38

38:                                               ; preds = %37
  %39 = load i32, ptr %9, align 4, !tbaa !5
  %40 = icmp ugt i32 %39, 1
  br i1 %40, label %41, label %44

41:                                               ; preds = %38
  %42 = load i32, ptr %10, align 4, !tbaa !5
  %43 = icmp ult i32 %42, 40
  br label %44

44:                                               ; preds = %41, %38
  %45 = phi i1 [ false, %38 ], [ %43, %41 ]
  br i1 %45, label %13, label %46, !llvm.loop !13

46:                                               ; preds = %44
  %47 = load i32, ptr %9, align 4, !tbaa !5
  %48 = icmp ugt i32 %47, 1
  br i1 %48, label %49, label %55

49:                                               ; preds = %46
  %50 = load i32, ptr %10, align 4, !tbaa !5
  %51 = icmp eq i32 %50, 40
  br i1 %51, label %52, label %55

52:                                               ; preds = %49
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 3, ptr noundef @.str, i32 noundef 74, ptr noundef @.str.1, i32 noundef %53, i32 noundef 40)
  store i32 %54, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %58

55:                                               ; preds = %49, %46
  %56 = load i32, ptr %10, align 4, !tbaa !5
  %57 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 %56, ptr %57, align 4, !tbaa !5
  store i32 0, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %58

58:                                               ; preds = %55, %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %59 = load i32, ptr %4, align 4
  ret i32 %59
}

declare i32 @liquid_error_fl(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) #2

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 = { "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 = { 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 = !{!"int", !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}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@.str = external hidden unnamed_addr constant [88 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [51 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @liquid_factor(i32 noundef %0, ptr nocapture noundef writeonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  br label %4

4:                                                ; preds = %.loopexit, %3
  %.019 = phi i32 [ %0, %3 ], [ %.120, %.loopexit ]
  %.0 = phi i32 [ 0, %3 ], [ %.1, %.loopexit ]
  %.not24 = icmp ult i32 %.019, 2
  br i1 %.not24, label %.thread, label %.lr.ph

.lr.ph:                                           ; preds = %4, %12
  %.02125 = phi i32 [ %13, %12 ], [ 2, %4 ]
  %5 = urem i32 %.019, %.02125
  %6 = udiv i32 %.019, %.02125
  %7 = icmp eq i32 %5, 0
  br i1 %7, label %8, label %12

8:                                                ; preds = %.lr.ph
  %9 = add i32 %.0, 1
  %10 = zext i32 %.0 to i64
  %11 = getelementptr inbounds i32, ptr %1, i64 %10
  store i32 %.02125, ptr %11, align 4, !tbaa !5
  br label %.loopexit

12:                                               ; preds = %.lr.ph
  %13 = add i32 %.02125, 1
  %.not = icmp ugt i32 %13, %.019
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !9

.loopexit:                                        ; preds = %12, %8
  %.120 = phi i32 [ %6, %8 ], [ %.019, %12 ]
  %.1 = phi i32 [ %9, %8 ], [ %.0, %12 ]
  %14 = icmp ugt i32 %.120, 1
  %15 = icmp ult i32 %.1, 40
  %16 = select i1 %14, i1 %15, i1 false
  br i1 %16, label %4, label %17, !llvm.loop !11

17:                                               ; preds = %.loopexit
  %18 = icmp eq i32 %.1, 40
  %or.cond = select i1 %14, i1 %18, i1 false
  br i1 %or.cond, label %19, label %.thread

19:                                               ; preds = %17
  %20 = tail call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 3, ptr noundef nonnull @.str, i32 noundef 74, ptr noundef nonnull @.str.1, i32 noundef %0, i32 noundef 40) #2
  br label %21

.thread:                                          ; preds = %4, %17
  %.12932 = phi i32 [ %.1, %17 ], [ %.0, %4 ]
  store i32 %.12932, ptr %2, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %.thread, %19
  %.022 = phi i32 [ %20, %19 ], [ 0, %.thread ]
  ret i32 %.022
}

declare i32 @liquid_error_fl(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #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 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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