; LLVM IR from trustwallet/wallet-core :: trezor-crypto/crypto/ed25519-donna (curve25519-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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local void @curve25519_contract(ptr noundef, ptr noundef) #1

; 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 @curve25519_isnonzero(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca [32 x i8], align 16
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %3) #3
  call void @llvm.memset.p0.i64(ptr align 16 %3, i8 0, i64 32, i1 false)
  %4 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 0
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  call void @curve25519_contract(ptr noundef %4, ptr noundef %5)
  %6 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 0
  %7 = load i8, ptr %6, align 16, !tbaa !9
  %8 = zext i8 %7 to i32
  %9 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 1
  %10 = load i8, ptr %9, align 1, !tbaa !9
  %11 = zext i8 %10 to i32
  %12 = or i32 %8, %11
  %13 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 2
  %14 = load i8, ptr %13, align 2, !tbaa !9
  %15 = zext i8 %14 to i32
  %16 = or i32 %12, %15
  %17 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 3
  %18 = load i8, ptr %17, align 1, !tbaa !9
  %19 = zext i8 %18 to i32
  %20 = or i32 %16, %19
  %21 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 4
  %22 = load i8, ptr %21, align 4, !tbaa !9
  %23 = zext i8 %22 to i32
  %24 = or i32 %20, %23
  %25 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 5
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = zext i8 %26 to i32
  %28 = or i32 %24, %27
  %29 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 6
  %30 = load i8, ptr %29, align 2, !tbaa !9
  %31 = zext i8 %30 to i32
  %32 = or i32 %28, %31
  %33 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 7
  %34 = load i8, ptr %33, align 1, !tbaa !9
  %35 = zext i8 %34 to i32
  %36 = or i32 %32, %35
  %37 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 8
  %38 = load i8, ptr %37, align 8, !tbaa !9
  %39 = zext i8 %38 to i32
  %40 = or i32 %36, %39
  %41 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 9
  %42 = load i8, ptr %41, align 1, !tbaa !9
  %43 = zext i8 %42 to i32
  %44 = or i32 %40, %43
  %45 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 10
  %46 = load i8, ptr %45, align 2, !tbaa !9
  %47 = zext i8 %46 to i32
  %48 = or i32 %44, %47
  %49 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 11
  %50 = load i8, ptr %49, align 1, !tbaa !9
  %51 = zext i8 %50 to i32
  %52 = or i32 %48, %51
  %53 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 12
  %54 = load i8, ptr %53, align 4, !tbaa !9
  %55 = zext i8 %54 to i32
  %56 = or i32 %52, %55
  %57 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 13
  %58 = load i8, ptr %57, align 1, !tbaa !9
  %59 = zext i8 %58 to i32
  %60 = or i32 %56, %59
  %61 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 14
  %62 = load i8, ptr %61, align 2, !tbaa !9
  %63 = zext i8 %62 to i32
  %64 = or i32 %60, %63
  %65 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 15
  %66 = load i8, ptr %65, align 1, !tbaa !9
  %67 = zext i8 %66 to i32
  %68 = or i32 %64, %67
  %69 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 16
  %70 = load i8, ptr %69, align 16, !tbaa !9
  %71 = zext i8 %70 to i32
  %72 = or i32 %68, %71
  %73 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 17
  %74 = load i8, ptr %73, align 1, !tbaa !9
  %75 = zext i8 %74 to i32
  %76 = or i32 %72, %75
  %77 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 18
  %78 = load i8, ptr %77, align 2, !tbaa !9
  %79 = zext i8 %78 to i32
  %80 = or i32 %76, %79
  %81 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 19
  %82 = load i8, ptr %81, align 1, !tbaa !9
  %83 = zext i8 %82 to i32
  %84 = or i32 %80, %83
  %85 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 20
  %86 = load i8, ptr %85, align 4, !tbaa !9
  %87 = zext i8 %86 to i32
  %88 = or i32 %84, %87
  %89 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 21
  %90 = load i8, ptr %89, align 1, !tbaa !9
  %91 = zext i8 %90 to i32
  %92 = or i32 %88, %91
  %93 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 22
  %94 = load i8, ptr %93, align 2, !tbaa !9
  %95 = zext i8 %94 to i32
  %96 = or i32 %92, %95
  %97 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 23
  %98 = load i8, ptr %97, align 1, !tbaa !9
  %99 = zext i8 %98 to i32
  %100 = or i32 %96, %99
  %101 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 24
  %102 = load i8, ptr %101, align 8, !tbaa !9
  %103 = zext i8 %102 to i32
  %104 = or i32 %100, %103
  %105 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 25
  %106 = load i8, ptr %105, align 1, !tbaa !9
  %107 = zext i8 %106 to i32
  %108 = or i32 %104, %107
  %109 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 26
  %110 = load i8, ptr %109, align 2, !tbaa !9
  %111 = zext i8 %110 to i32
  %112 = or i32 %108, %111
  %113 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 27
  %114 = load i8, ptr %113, align 1, !tbaa !9
  %115 = zext i8 %114 to i32
  %116 = or i32 %112, %115
  %117 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 28
  %118 = load i8, ptr %117, align 4, !tbaa !9
  %119 = zext i8 %118 to i32
  %120 = or i32 %116, %119
  %121 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 29
  %122 = load i8, ptr %121, align 1, !tbaa !9
  %123 = zext i8 %122 to i32
  %124 = or i32 %120, %123
  %125 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 30
  %126 = load i8, ptr %125, align 2, !tbaa !9
  %127 = zext i8 %126 to i32
  %128 = or i32 %124, %127
  %129 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 31
  %130 = load i8, ptr %129, align 1, !tbaa !9
  %131 = zext i8 %130 to i32
  %132 = or i32 %128, %131
  %133 = sub nsw i32 %132, 1
  %134 = ashr i32 %133, 8
  %135 = add nsw i32 %134, 1
  %136 = and i32 %135, 1
  call void @llvm.lifetime.end.p0(i64 32, ptr %3) #3
  ret i32 %136
}

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @curve25519_contract(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress 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 range(i32 0, 2) i32 @curve25519_isnonzero(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca [32 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %2, i8 0, i64 32, i1 false)
  call void @curve25519_contract(ptr noundef nonnull %2, ptr noundef %0)
  %3 = load <32 x i8>, ptr %2, align 16, !tbaa !5
  %4 = call i8 @llvm.vector.reduce.or.v32i8(<32 x i8> %3)
  %5 = zext i8 %4 to i32
  %6 = add nuw nsw i32 %5, 511
  %7 = lshr i32 %6, 8
  %8 = and i32 %7, 1
  %9 = xor i32 %8, 1
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #4
  ret i32 %9
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i8 @llvm.vector.reduce.or.v32i8(<32 x i8>) #3

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SLPVectorizerPass,SROAPass