; LLVM IR from Water-Melon/Melon :: src (mln_bignum)

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

%struct.mln_bignum_t = type { i32, i32, [257 x i64] }

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

14:                                               ; preds = %3
  store i32 -1, ptr %4, align 4
  br label %78

15:                                               ; preds = %3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %8, i8 0, i64 2064, i1 false)
  %17 = getelementptr inbounds %struct.mln_bignum_t, ptr %8, i32 0, i32 0
  %18 = getelementptr inbounds %struct.mln_bignum_t, ptr %8, i32 0, i32 1
  %19 = getelementptr inbounds %struct.mln_bignum_t, ptr %8, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %16, ptr align 8 %8, i64 2064, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.mln_bignum_t, ptr %20, i32 0, i32 2
  %22 = getelementptr inbounds [257 x i64], ptr %21, i64 0, i64 0
  store ptr %22, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load i64, ptr %7, align 8, !tbaa !9
  %25 = getelementptr inbounds i8, ptr %23, i64 %24
  %26 = getelementptr inbounds i8, ptr %25, i64 -1
  store ptr %26, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %48, %43, %15
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = icmp uge ptr %28, %29
  br i1 %30, label %31, label %51

31:                                               ; preds = %27
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i32 -1
  store ptr %33, ptr %10, align 8, !tbaa !5
  %34 = load i8, ptr %32, align 1, !tbaa !14
  %35 = zext i8 %34 to i64
  %36 = load i64, ptr %11, align 8, !tbaa !9
  %37 = shl i64 %35, %36
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = load i64, ptr %38, align 8, !tbaa !9
  %40 = or i64 %39, %37
  store i64 %40, ptr %38, align 8, !tbaa !9
  %41 = load i64, ptr %11, align 8, !tbaa !9
  %42 = icmp uge i64 %41, 24
  br i1 %42, label %43, label %48

43:                                               ; preds = %31
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = getelementptr inbounds i64, ptr %44, i32 1
  store ptr %45, ptr %9, align 8, !tbaa !5
  %46 = load i64, ptr %44, align 8, !tbaa !9
  %47 = and i64 %46, 4294967295
  store i64 %47, ptr %44, align 8, !tbaa !9
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %27, !llvm.loop !15

48:                                               ; preds = %31
  %49 = load i64, ptr %11, align 8, !tbaa !9
  %50 = add i64 %49, 8
  store i64 %50, ptr %11, align 8, !tbaa !9
  br label %27, !llvm.loop !15

51:                                               ; preds = %27
  %52 = load i64, ptr %11, align 8, !tbaa !9
  %53 = icmp ne i64 %52, 0
  br i1 %53, label %54, label %64

54:                                               ; preds = %51
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.mln_bignum_t, ptr %56, i32 0, i32 2
  %58 = getelementptr inbounds [257 x i64], ptr %57, i64 0, i64 0
  %59 = ptrtoint ptr %55 to i64
  %60 = ptrtoint ptr %58 to i64
  %61 = sub i64 %59, %60
  %62 = sdiv exact i64 %61, 8
  %63 = add nsw i64 %62, 1
  br label %73

64:                                               ; preds = %51
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.mln_bignum_t, ptr %66, i32 0, i32 2
  %68 = getelementptr inbounds [257 x i64], ptr %67, i64 0, i64 0
  %69 = ptrtoint ptr %65 to i64
  %70 = ptrtoint ptr %68 to i64
  %71 = sub i64 %69, %70
  %72 = sdiv exact i64 %71, 8
  br label %73

73:                                               ; preds = %64, %54
  %74 = phi i64 [ %63, %54 ], [ %72, %64 ]
  %75 = trunc i64 %74 to i32
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.mln_bignum_t, ptr %76, i32 0, i32 1
  store i32 %75, ptr %77, align 4, !tbaa !17
  store i32 0, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %78

78:                                               ; preds = %73, %14
  %79 = load i32, ptr %4, align 4
  ret i32 %79
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { 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 = !{!"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 = !{i64 0, i64 4, !12, i64 4, i64 4, !12, i64 8, i64 2056, !14}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !13, i64 4}
!18 = !{!"", !13, i64 0, !13, i64 4, !7, i64 8}


; 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: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local range(i32 -1, 1) i32 @mln_bignum_os2ip(ptr noundef nonnull %0, ptr noundef nonnull readonly %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = icmp ugt i64 %2, 1028
  br i1 %4, label %45, label %5

5:                                                ; preds = %3
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(2064) %0, i8 0, i64 2064, i1 false)
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = getelementptr inbounds i8, ptr %1, i64 %2
  %8 = getelementptr inbounds i8, ptr %7, i64 -1
  %.not2632 = icmp ult ptr %8, %1
  br i1 %.not2632, label %.outer._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5, %.outer
  %.019.ph34 = phi ptr [ %16, %.outer ], [ %8, %5 ]
  %.020.ph33 = phi ptr [ %17, %.outer ], [ %6, %5 ]
  %.020.ph.promoted = load i64, ptr %.020.ph33, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %.019.ph34, i64 -1
  %10 = load i8, ptr %.019.ph34, align 1, !tbaa !9
  %11 = zext i8 %10 to i64
  %12 = or i64 %.020.ph.promoted, %11
  store i64 %12, ptr %.020.ph33, align 8, !tbaa !5
  %.not = icmp ult ptr %9, %1
  br i1 %.not, label %31, label %19, !llvm.loop !10

.outer:                                           ; preds = %25
  %13 = load i8, ptr %26, align 1, !tbaa !9
  %14 = zext i8 %13 to i64
  %15 = shl nuw nsw i64 %14, 24
  %16 = getelementptr i8, ptr %.019.ph34, i64 -4
  %17 = getelementptr inbounds i8, ptr %.020.ph33, i64 8
  %.masked = and i64 %30, 4294967295
  %18 = or i64 %15, %.masked
  store i64 %18, ptr %.020.ph33, align 8, !tbaa !5
  %.not26 = icmp ult ptr %16, %1
  br i1 %.not26, label %.outer._crit_edge, label %.lr.ph, !llvm.loop !10

19:                                               ; preds = %.lr.ph
  %20 = getelementptr inbounds i8, ptr %.019.ph34, i64 -2
  %21 = load i8, ptr %9, align 1, !tbaa !9
  %22 = zext i8 %21 to i64
  %23 = shl nuw nsw i64 %22, 8
  %24 = or i64 %23, %12
  store i64 %24, ptr %.020.ph33, align 8, !tbaa !5
  %.not.1 = icmp ult ptr %20, %1
  br i1 %.not.1, label %31, label %25, !llvm.loop !10

25:                                               ; preds = %19
  %26 = getelementptr inbounds i8, ptr %.019.ph34, i64 -3
  %27 = load i8, ptr %20, align 1, !tbaa !9
  %28 = zext i8 %27 to i64
  %29 = shl nuw nsw i64 %28, 16
  %30 = or i64 %29, %24
  store i64 %30, ptr %.020.ph33, align 8, !tbaa !5
  %.not.2 = icmp ult ptr %26, %1
  br i1 %.not.2, label %31, label %.outer, !llvm.loop !10

31:                                               ; preds = %25, %19, %.lr.ph
  %32 = ptrtoint ptr %.020.ph33 to i64
  %33 = ptrtoint ptr %6 to i64
  %34 = sub i64 %32, %33
  %35 = ashr exact i64 %34, 3
  %36 = add nsw i64 %35, 1
  br label %41

.outer._crit_edge:                                ; preds = %.outer, %5
  %.020.ph.lcssa = phi ptr [ %6, %5 ], [ %17, %.outer ]
  %37 = ptrtoint ptr %.020.ph.lcssa to i64
  %38 = ptrtoint ptr %6 to i64
  %39 = sub i64 %37, %38
  %40 = ashr exact i64 %39, 3
  br label %41

41:                                               ; preds = %.outer._crit_edge, %31
  %42 = phi i64 [ %36, %31 ], [ %40, %.outer._crit_edge ]
  %43 = trunc i64 %42 to i32
  %44 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %43, ptr %44, align 4, !tbaa !12
  br label %45

45:                                               ; preds = %3, %41
  %.021 = phi i32 [ 0, %41 ], [ -1, %3 ]
  ret i32 %.021
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !14, i64 4}
!13 = !{!"", !14, i64 0, !14, i64 4, !7, i64 8}
!14 = !{!"int", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass