; LLVM IR from Simple-XX/SimpleKernel :: src/libc/src/math (math)

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local i64 @udivmoddi4(i64 noundef %0, i64 noundef %1, ptr noundef %2) #1 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  store i64 %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store i64 0, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  store i64 1, ptr %9, align 8, !tbaa !5
  %11 = load i64, ptr %6, align 8, !tbaa !5
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %13, label %18

13:                                               ; preds = %3
  %14 = load i64, ptr %6, align 8, !tbaa !5
  %15 = trunc i64 %14 to i32
  %16 = udiv i32 1, %15
  %17 = zext i32 %16 to i64
  store i64 %17, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %55

18:                                               ; preds = %3
  br label %19

19:                                               ; preds = %22, %18
  %20 = load i64, ptr %6, align 8, !tbaa !5
  %21 = icmp sge i64 %20, 0
  br i1 %21, label %22, label %27

22:                                               ; preds = %19
  %23 = load i64, ptr %6, align 8, !tbaa !5
  %24 = shl i64 %23, 1
  store i64 %24, ptr %6, align 8, !tbaa !5
  %25 = load i64, ptr %9, align 8, !tbaa !5
  %26 = shl i64 %25, 1
  store i64 %26, ptr %9, align 8, !tbaa !5
  br label %19, !llvm.loop !11

27:                                               ; preds = %19
  br label %28

28:                                               ; preds = %42, %27
  %29 = load i64, ptr %9, align 8, !tbaa !5
  %30 = icmp ne i64 %29, 0
  br i1 %30, label %31, label %47

31:                                               ; preds = %28
  %32 = load i64, ptr %6, align 8, !tbaa !5
  %33 = load i64, ptr %5, align 8, !tbaa !5
  %34 = icmp ule i64 %32, %33
  br i1 %34, label %35, label %42

35:                                               ; preds = %31
  %36 = load i64, ptr %6, align 8, !tbaa !5
  %37 = load i64, ptr %5, align 8, !tbaa !5
  %38 = sub i64 %37, %36
  store i64 %38, ptr %5, align 8, !tbaa !5
  %39 = load i64, ptr %9, align 8, !tbaa !5
  %40 = load i64, ptr %8, align 8, !tbaa !5
  %41 = add i64 %40, %39
  store i64 %41, ptr %8, align 8, !tbaa !5
  br label %42

42:                                               ; preds = %35, %31
  %43 = load i64, ptr %6, align 8, !tbaa !5
  %44 = lshr i64 %43, 1
  store i64 %44, ptr %6, align 8, !tbaa !5
  %45 = load i64, ptr %9, align 8, !tbaa !5
  %46 = lshr i64 %45, 1
  store i64 %46, ptr %9, align 8, !tbaa !5
  br label %28, !llvm.loop !13

47:                                               ; preds = %28
  %48 = load ptr, ptr %7, align 8, !tbaa !9
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %53

50:                                               ; preds = %47
  %51 = load i64, ptr %5, align 8, !tbaa !5
  %52 = load ptr, ptr %7, align 8, !tbaa !9
  store i64 %51, ptr %52, align 8, !tbaa !5
  br label %53

53:                                               ; preds = %50, %47
  %54 = load i64, ptr %8, align 8, !tbaa !5
  store i64 %54, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %55

55:                                               ; preds = %53, %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %56 = load i64, ptr %4, align 8
  ret i64 %56
}

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

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 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}
!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"

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: write) uwtable
define dso_local i64 @udivmoddi4(i64 noundef %0, i64 noundef %1, ptr noundef writeonly %2) local_unnamed_addr #0 {
  %4 = icmp eq i64 %1, 0
  br i1 %4, label %14, label %.preheader30

.preheader30:                                     ; preds = %3
  %5 = icmp sgt i64 %1, -1
  br i1 %5, label %.lr.ph, label %.lr.ph39.preheader

.preheader:                                       ; preds = %.lr.ph
  %.not34 = icmp eq i64 %7, 0
  br i1 %.not34, label %._crit_edge, label %.lr.ph39.preheader

.lr.ph39.preheader:                               ; preds = %.preheader30, %.preheader
  %.138.ph = phi i64 [ 1, %.preheader30 ], [ %7, %.preheader ]
  %.12236.ph = phi i64 [ %1, %.preheader30 ], [ %6, %.preheader ]
  br label %.lr.ph39

.lr.ph:                                           ; preds = %.preheader30, %.lr.ph
  %.032 = phi i64 [ %7, %.lr.ph ], [ 1, %.preheader30 ]
  %.02131 = phi i64 [ %6, %.lr.ph ], [ %1, %.preheader30 ]
  %6 = shl nuw i64 %.02131, 1
  %7 = shl i64 %.032, 1
  %8 = icmp sgt i64 %6, -1
  br i1 %8, label %.lr.ph, label %.preheader, !llvm.loop !5

.lr.ph39:                                         ; preds = %.lr.ph39.preheader, %.lr.ph39
  %.138 = phi i64 [ %12, %.lr.ph39 ], [ %.138.ph, %.lr.ph39.preheader ]
  %.01837 = phi i64 [ %.119, %.lr.ph39 ], [ 0, %.lr.ph39.preheader ]
  %.12236 = phi i64 [ %11, %.lr.ph39 ], [ %.12236.ph, %.lr.ph39.preheader ]
  %.02335 = phi i64 [ %.124, %.lr.ph39 ], [ %0, %.lr.ph39.preheader ]
  %.not29 = icmp ugt i64 %.12236, %.02335
  %9 = select i1 %.not29, i64 0, i64 %.12236
  %.124 = sub i64 %.02335, %9
  %10 = select i1 %.not29, i64 0, i64 %.138
  %.119 = add i64 %10, %.01837
  %11 = lshr i64 %.12236, 1
  %12 = lshr i64 %.138, 1
  %.not = icmp ult i64 %.138, 2
  br i1 %.not, label %._crit_edge, label %.lr.ph39, !llvm.loop !7

._crit_edge:                                      ; preds = %.lr.ph39, %.preheader
  %.023.lcssa = phi i64 [ %0, %.preheader ], [ %.124, %.lr.ph39 ]
  %.018.lcssa = phi i64 [ 0, %.preheader ], [ %.119, %.lr.ph39 ]
  %.not28 = icmp eq ptr %2, null
  br i1 %.not28, label %14, label %13

13:                                               ; preds = %._crit_edge
  store i64 %.023.lcssa, ptr %2, align 8, !tbaa !8
  br label %14

14:                                               ; preds = %._crit_edge, %13, %3
  %.020 = phi i64 [ poison, %3 ], [ %.018.lcssa, %13 ], [ %.018.lcssa, %._crit_edge ]
  ret i64 %.020
}

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


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