; LLVM IR from trustwallet/wallet-core :: trezor-crypto/crypto/ed25519-donna (modm-donna-32bit)

; 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, 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: inlinehint nounwind uwtable
declare hidden i32 @U8TO32_LE(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @expand_raw256_modm(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [8 x i32], align 16
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %5) #4
  call void @llvm.memset.p0.i64(ptr align 16 %5, i8 0, i64 32, i1 false)
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 0
  %8 = call i32 @U8TO32_LE(ptr noundef %7)
  %9 = getelementptr inbounds [8 x i32], ptr %5, i64 0, i64 0
  store i32 %8, ptr %9, align 16, !tbaa !9
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i64 4
  %12 = call i32 @U8TO32_LE(ptr noundef %11)
  %13 = getelementptr inbounds [8 x i32], ptr %5, i64 0, i64 1
  store i32 %12, ptr %13, align 4, !tbaa !9
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 8
  %16 = call i32 @U8TO32_LE(ptr noundef %15)
  %17 = getelementptr inbounds [8 x i32], ptr %5, i64 0, i64 2
  store i32 %16, ptr %17, align 8, !tbaa !9
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 12
  %20 = call i32 @U8TO32_LE(ptr noundef %19)
  %21 = getelementptr inbounds [8 x i32], ptr %5, i64 0, i64 3
  store i32 %20, ptr %21, align 4, !tbaa !9
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 16
  %24 = call i32 @U8TO32_LE(ptr noundef %23)
  %25 = getelementptr inbounds [8 x i32], ptr %5, i64 0, i64 4
  store i32 %24, ptr %25, align 16, !tbaa !9
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i64 20
  %28 = call i32 @U8TO32_LE(ptr noundef %27)
  %29 = getelementptr inbounds [8 x i32], ptr %5, i64 0, i64 5
  store i32 %28, ptr %29, align 4, !tbaa !9
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i64 24
  %32 = call i32 @U8TO32_LE(ptr noundef %31)
  %33 = getelementptr inbounds [8 x i32], ptr %5, i64 0, i64 6
  store i32 %32, ptr %33, align 8, !tbaa !9
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i64 28
  %36 = call i32 @U8TO32_LE(ptr noundef %35)
  %37 = getelementptr inbounds [8 x i32], ptr %5, i64 0, i64 7
  store i32 %36, ptr %37, align 4, !tbaa !9
  %38 = getelementptr inbounds [8 x i32], ptr %5, i64 0, i64 0
  %39 = load i32, ptr %38, align 16, !tbaa !9
  %40 = and i32 %39, 1073741823
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds i32, ptr %41, i64 0
  store i32 %40, ptr %42, align 4, !tbaa !9
  %43 = getelementptr inbounds [8 x i32], ptr %5, i64 0, i64 0
  %44 = load i32, ptr %43, align 16, !tbaa !9
  %45 = lshr i32 %44, 30
  %46 = getelementptr inbounds [8 x i32], ptr %5, i64 0, i64 1
  %47 = load i32, ptr %46, align 4, !tbaa !9
  %48 = shl i32 %47, 2
  %49 = or i32 %45, %48
  %50 = and i32 %49, 1073741823
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds i32, ptr %51, i64 1
  store i32 %50, ptr %52, align 4, !tbaa !9
  %53 = getelementptr inbounds [8 x i32], ptr %5, i64 0, i64 1
  %54 = load i32, ptr %53, align 4, !tbaa !9
  %55 = lshr i32 %54, 28
  %56 = getelementptr inbounds [8 x i32], ptr %5, i64 0, i64 2
  %57 = load i32, ptr %56, align 8, !tbaa !9
  %58 = shl i32 %57, 4
  %59 = or i32 %55, %58
  %60 = and i32 %59, 1073741823
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds i32, ptr %61, i64 2
  store i32 %60, ptr %62, align 4, !tbaa !9
  %63 = getelementptr inbounds [8 x i32], ptr %5, i64 0, i64 2
  %64 = load i32, ptr %63, align 8, !tbaa !9
  %65 = lshr i32 %64, 26
  %66 = getelementptr inbounds [8 x i32], ptr %5, i64 0, i64 3
  %67 = load i32, ptr %66, align 4, !tbaa !9
  %68 = shl i32 %67, 6
  %69 = or i32 %65, %68
  %70 = and i32 %69, 1073741823
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds i32, ptr %71, i64 3
  store i32 %70, ptr %72, align 4, !tbaa !9
  %73 = getelementptr inbounds [8 x i32], ptr %5, i64 0, i64 3
  %74 = load i32, ptr %73, align 4, !tbaa !9
  %75 = lshr i32 %74, 24
  %76 = getelementptr inbounds [8 x i32], ptr %5, i64 0, i64 4
  %77 = load i32, ptr %76, align 16, !tbaa !9
  %78 = shl i32 %77, 8
  %79 = or i32 %75, %78
  %80 = and i32 %79, 1073741823
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = getelementptr inbounds i32, ptr %81, i64 4
  store i32 %80, ptr %82, align 4, !tbaa !9
  %83 = getelementptr inbounds [8 x i32], ptr %5, i64 0, i64 4
  %84 = load i32, ptr %83, align 16, !tbaa !9
  %85 = lshr i32 %84, 22
  %86 = getelementptr inbounds [8 x i32], ptr %5, i64 0, i64 5
  %87 = load i32, ptr %86, align 4, !tbaa !9
  %88 = shl i32 %87, 10
  %89 = or i32 %85, %88
  %90 = and i32 %89, 1073741823
  %91 = load ptr, ptr %3, align 8, !tbaa !5
  %92 = getelementptr inbounds i32, ptr %91, i64 5
  store i32 %90, ptr %92, align 4, !tbaa !9
  %93 = getelementptr inbounds [8 x i32], ptr %5, i64 0, i64 5
  %94 = load i32, ptr %93, align 4, !tbaa !9
  %95 = lshr i32 %94, 20
  %96 = getelementptr inbounds [8 x i32], ptr %5, i64 0, i64 6
  %97 = load i32, ptr %96, align 8, !tbaa !9
  %98 = shl i32 %97, 12
  %99 = or i32 %95, %98
  %100 = and i32 %99, 1073741823
  %101 = load ptr, ptr %3, align 8, !tbaa !5
  %102 = getelementptr inbounds i32, ptr %101, i64 6
  store i32 %100, ptr %102, align 4, !tbaa !9
  %103 = getelementptr inbounds [8 x i32], ptr %5, i64 0, i64 6
  %104 = load i32, ptr %103, align 8, !tbaa !9
  %105 = lshr i32 %104, 18
  %106 = getelementptr inbounds [8 x i32], ptr %5, i64 0, i64 7
  %107 = load i32, ptr %106, align 4, !tbaa !9
  %108 = shl i32 %107, 14
  %109 = or i32 %105, %108
  %110 = and i32 %109, 1073741823
  %111 = load ptr, ptr %3, align 8, !tbaa !5
  %112 = getelementptr inbounds i32, ptr %111, i64 7
  store i32 %110, ptr %112, align 4, !tbaa !9
  %113 = getelementptr inbounds [8 x i32], ptr %5, i64 0, i64 7
  %114 = load i32, ptr %113, align 4, !tbaa !9
  %115 = lshr i32 %114, 16
  %116 = and i32 %115, 65535
  %117 = load ptr, ptr %3, align 8, !tbaa !5
  %118 = getelementptr inbounds i32, ptr %117, i64 8
  store i32 %116, ptr %118, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 32, ptr %5) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { inlinehint 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 #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 = !{!"int", !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: inlinehint nounwind uwtable
declare hidden i32 @U8TO32_LE(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @expand_raw256_modm(ptr nocapture noundef writeonly %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = tail call i32 @U8TO32_LE(ptr noundef %1)
  %4 = getelementptr inbounds i8, ptr %1, i64 4
  %5 = tail call i32 @U8TO32_LE(ptr noundef nonnull %4)
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = tail call i32 @U8TO32_LE(ptr noundef nonnull %6)
  %8 = getelementptr inbounds i8, ptr %1, i64 12
  %9 = tail call i32 @U8TO32_LE(ptr noundef nonnull %8)
  %10 = getelementptr inbounds i8, ptr %1, i64 16
  %11 = tail call i32 @U8TO32_LE(ptr noundef nonnull %10)
  %12 = getelementptr inbounds i8, ptr %1, i64 20
  %13 = tail call i32 @U8TO32_LE(ptr noundef nonnull %12)
  %14 = getelementptr inbounds i8, ptr %1, i64 24
  %15 = tail call i32 @U8TO32_LE(ptr noundef nonnull %14)
  %16 = getelementptr inbounds i8, ptr %1, i64 28
  %17 = tail call i32 @U8TO32_LE(ptr noundef nonnull %16)
  %18 = and i32 %3, 1073741823
  store i32 %18, ptr %0, align 4, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %0, i64 4
  %20 = insertelement <4 x i32> poison, i32 %7, i64 0
  %21 = insertelement <4 x i32> %20, i32 %9, i64 1
  %22 = insertelement <4 x i32> %21, i32 %11, i64 2
  %23 = insertelement <4 x i32> %22, i32 %5, i64 3
  %24 = shufflevector <4 x i32> %23, <4 x i32> poison, <4 x i32> <i32 3, i32 0, i32 1, i32 poison>
  %25 = insertelement <4 x i32> %24, i32 %3, i64 3
  %26 = tail call <4 x i32> @llvm.fshl.v4i32(<4 x i32> %23, <4 x i32> %25, <4 x i32> <i32 4, i32 6, i32 8, i32 2>)
  %27 = and <4 x i32> %26, <i32 1073741823, i32 1073741823, i32 1073741823, i32 1073741823>
  %28 = shufflevector <4 x i32> %27, <4 x i32> poison, <4 x i32> <i32 3, i32 0, i32 1, i32 2>
  store <4 x i32> %28, ptr %19, align 4, !tbaa !5
  %29 = tail call i32 @llvm.fshl.i32(i32 %13, i32 %11, i32 10)
  %30 = and i32 %29, 1073741823
  %31 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 %30, ptr %31, align 4, !tbaa !5
  %32 = tail call i32 @llvm.fshl.i32(i32 %15, i32 %13, i32 12)
  %33 = and i32 %32, 1073741823
  %34 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %33, ptr %34, align 4, !tbaa !5
  %35 = tail call i32 @llvm.fshl.i32(i32 %17, i32 %15, i32 14)
  %36 = and i32 %35, 1073741823
  %37 = getelementptr inbounds i8, ptr %0, i64 28
  store i32 %36, ptr %37, align 4, !tbaa !5
  %38 = lshr i32 %17, 16
  %39 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 %38, ptr %39, align 4, !tbaa !5
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.fshl.i32(i32, i32, i32) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x i32> @llvm.fshl.v4i32(<4 x i32>, <4 x i32>, <4 x i32>) #2

attributes #0 = { inlinehint 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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,TailCallElimPass