; LLVM IR from tfhe/spqlios-arithmetic :: test/testlib/mod_q120.ll (ZNK8mod_q12013save_as_q120cEPv)

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

%class.mod_q120 = type { [4 x i64] }

@_ZN8mod_q1202QiE = external dso_local constant [4 x i64], 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: mustprogress nounwind uwtable
define dso_local void @_ZNK8mod_q12013save_as_q120cEPv(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %8, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %9

9:                                                ; preds = %45, %2
  %10 = load i64, ptr %6, align 8, !tbaa !9
  %11 = icmp ult i64 %10, 4
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %48

13:                                               ; preds = %9
  %14 = getelementptr inbounds %class.mod_q120, ptr %7, i32 0, i32 0
  %15 = load i64, ptr %6, align 8, !tbaa !9
  %16 = getelementptr inbounds [4 x i64], ptr %14, i64 0, i64 %15
  %17 = load i64, ptr %16, align 8, !tbaa !9
  %18 = load i64, ptr %6, align 8, !tbaa !9
  %19 = getelementptr inbounds [4 x i64], ptr @_ZN8mod_q1202QiE, i64 0, i64 %18
  %20 = load i64, ptr %19, align 8, !tbaa !9
  %21 = mul nsw i64 3, %20
  %22 = add nsw i64 %17, %21
  %23 = trunc i64 %22 to i32
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load i64, ptr %6, align 8, !tbaa !9
  %26 = mul i64 2, %25
  %27 = getelementptr inbounds i32, ptr %24, i64 %26
  store i32 %23, ptr %27, align 4, !tbaa !11
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load i64, ptr %6, align 8, !tbaa !9
  %30 = mul i64 2, %29
  %31 = getelementptr inbounds i32, ptr %28, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !11
  %33 = sext i32 %32 to i64
  %34 = shl i64 %33, 32
  %35 = load i64, ptr %6, align 8, !tbaa !9
  %36 = getelementptr inbounds [4 x i64], ptr @_ZN8mod_q1202QiE, i64 0, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !9
  %38 = urem i64 %34, %37
  %39 = trunc i64 %38 to i32
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load i64, ptr %6, align 8, !tbaa !9
  %42 = mul i64 2, %41
  %43 = add i64 %42, 1
  %44 = getelementptr inbounds i32, ptr %40, i64 %43
  store i32 %39, ptr %44, align 4, !tbaa !11
  br label %45

45:                                               ; preds = %13
  %46 = load i64, ptr %6, align 8, !tbaa !9
  %47 = add i64 %46, 1
  store i64 %47, ptr %6, align 8, !tbaa !9
  br label %9, !llvm.loop !13

48:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@_ZN8mod_q1202QiE = external dso_local local_unnamed_addr constant [4 x i64], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @_ZNK8mod_q12013save_as_q120cEPv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(32) %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 align 2 {
  %3 = load i64, ptr %0, align 8, !tbaa !5
  %4 = load i64, ptr @_ZN8mod_q1202QiE, align 16, !tbaa !5
  %5 = mul nsw i64 %4, 3
  %6 = add nsw i64 %5, %3
  %7 = trunc i64 %6 to i32
  store i32 %7, ptr %1, align 4, !tbaa !9
  %sext = shl i64 %6, 32
  %8 = urem i64 %sext, %4
  %9 = trunc i64 %8 to i32
  %10 = getelementptr inbounds i8, ptr %1, i64 4
  store i32 %9, ptr %10, align 4, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load i64, ptr %11, align 8, !tbaa !5
  %13 = load i64, ptr getelementptr inbounds (i8, ptr @_ZN8mod_q1202QiE, i64 8), align 8, !tbaa !5
  %14 = mul nsw i64 %13, 3
  %15 = add nsw i64 %14, %12
  %16 = trunc i64 %15 to i32
  %17 = getelementptr inbounds i8, ptr %1, i64 8
  store i32 %16, ptr %17, align 4, !tbaa !9
  %sext.1 = shl i64 %15, 32
  %18 = urem i64 %sext.1, %13
  %19 = trunc i64 %18 to i32
  %20 = getelementptr inbounds i8, ptr %1, i64 12
  store i32 %19, ptr %20, align 4, !tbaa !9
  %21 = getelementptr inbounds i8, ptr %0, i64 16
  %22 = load i64, ptr %21, align 8, !tbaa !5
  %23 = load i64, ptr getelementptr inbounds (i8, ptr @_ZN8mod_q1202QiE, i64 16), align 16, !tbaa !5
  %24 = mul nsw i64 %23, 3
  %25 = add nsw i64 %24, %22
  %26 = trunc i64 %25 to i32
  %27 = getelementptr inbounds i8, ptr %1, i64 16
  store i32 %26, ptr %27, align 4, !tbaa !9
  %sext.2 = shl i64 %25, 32
  %28 = urem i64 %sext.2, %23
  %29 = trunc i64 %28 to i32
  %30 = getelementptr inbounds i8, ptr %1, i64 20
  store i32 %29, ptr %30, align 4, !tbaa !9
  %31 = getelementptr inbounds i8, ptr %0, i64 24
  %32 = load i64, ptr %31, align 8, !tbaa !5
  %33 = load i64, ptr getelementptr inbounds (i8, ptr @_ZN8mod_q1202QiE, i64 24), align 8, !tbaa !5
  %34 = mul nsw i64 %33, 3
  %35 = add nsw i64 %34, %32
  %36 = trunc i64 %35 to i32
  %37 = getelementptr inbounds i8, ptr %1, i64 24
  store i32 %36, ptr %37, align 4, !tbaa !9
  %sext.3 = shl i64 %35, 32
  %38 = urem i64 %sext.3, %33
  %39 = trunc i64 %38 to i32
  %40 = getelementptr inbounds i8, ptr %1, i64 28
  store i32 %39, ptr %40, align 4, !tbaa !9
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass