; LLVM IR from sca-secure-library-sca25519/sca25519 :: STM32F407-ephemeral/crypto/numerics (bigint)

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

%union.UN_96bitValue_ = type { [1 x i64], [8 x i8] }
%union.UN_128bitValue_ = type { [2 x i64] }

; Function Attrs: alwaysinline nounwind uwtable
declare dso_local void @multiply32x64(ptr noundef, i32 noundef, ptr noundef) #0

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i64 @multiply32x32(i32 noundef, i32 noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local void @square96_c(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %union.UN_96bitValue_, align 8
  %6 = alloca i8, align 1
  %7 = alloca i64, align 8
  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 16, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds [1 x %union.UN_128bitValue_], ptr %8, i64 0, i64 0
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds [1 x i64], ptr %10, i64 0, i64 0
  call void @square64(ptr noundef %9, ptr noundef %11)
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds [3 x i32], ptr %12, i64 0, i64 2
  %14 = load i32, ptr %13, align 8, !tbaa !11
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds [3 x i32], ptr %15, i64 0, i64 2
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = call i64 @multiply32x32(i32 noundef %14, i32 noundef %17)
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds [3 x i64], ptr %19, i64 0, i64 2
  store i64 %18, ptr %20, align 8, !tbaa !11
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds [3 x i32], ptr %21, i64 0, i64 2
  %23 = load i32, ptr %22, align 8, !tbaa !11
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds [1 x i64], ptr %24, i64 0, i64 0
  call void @multiply32x64(ptr noundef %5, i32 noundef %23, ptr noundef %25)
  store i8 0, ptr %6, align 1, !tbaa !11
  br label %26

26:                                               ; preds = %65, %2
  %27 = load i8, ptr %6, align 1, !tbaa !11
  %28 = zext i8 %27 to i32
  %29 = icmp slt i32 %28, 3
  br i1 %29, label %30, label %68

30:                                               ; preds = %26
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = load i8, ptr %6, align 1, !tbaa !11
  %33 = zext i8 %32 to i32
  %34 = add nsw i32 2, %33
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [6 x i32], ptr %31, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !11
  %38 = zext i32 %37 to i64
  %39 = load i64, ptr %7, align 8, !tbaa !9
  %40 = add i64 %39, %38
  store i64 %40, ptr %7, align 8, !tbaa !9
  %41 = load i8, ptr %6, align 1, !tbaa !11
  %42 = zext i8 %41 to i64
  %43 = getelementptr inbounds [3 x i32], ptr %5, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !11
  %45 = zext i32 %44 to i64
  %46 = load i64, ptr %7, align 8, !tbaa !9
  %47 = add i64 %46, %45
  store i64 %47, ptr %7, align 8, !tbaa !9
  %48 = load i8, ptr %6, align 1, !tbaa !11
  %49 = zext i8 %48 to i64
  %50 = getelementptr inbounds [3 x i32], ptr %5, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !11
  %52 = zext i32 %51 to i64
  %53 = load i64, ptr %7, align 8, !tbaa !9
  %54 = add i64 %53, %52
  store i64 %54, ptr %7, align 8, !tbaa !9
  %55 = load i64, ptr %7, align 8, !tbaa !9
  %56 = trunc i64 %55 to i32
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = load i8, ptr %6, align 1, !tbaa !11
  %59 = zext i8 %58 to i32
  %60 = add nsw i32 2, %59
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [6 x i32], ptr %57, i64 0, i64 %61
  store i32 %56, ptr %62, align 4, !tbaa !11
  %63 = load i64, ptr %7, align 8, !tbaa !9
  %64 = lshr i64 %63, 32
  store i64 %64, ptr %7, align 8, !tbaa !9
  br label %65

65:                                               ; preds = %30
  %66 = load i8, ptr %6, align 1, !tbaa !11
  %67 = add i8 %66, 1
  store i8 %67, ptr %6, align 1, !tbaa !11
  br label %26, !llvm.loop !12

68:                                               ; preds = %26
  %69 = load i64, ptr %7, align 8, !tbaa !9
  %70 = trunc i64 %69 to i32
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds [6 x i32], ptr %71, i64 0, i64 5
  %73 = load i32, ptr %72, align 4, !tbaa !11
  %74 = add i32 %73, %70
  store i32 %74, ptr %72, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #3
  ret void
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @square64(ptr noundef, ptr noundef) #0

attributes #0 = { alwaysinline 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 }

!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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

%union.UN_96bitValue_ = type { [1 x i64], [8 x i8] }

; Function Attrs: alwaysinline nounwind uwtable
declare dso_local void @multiply32x64(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i64 @multiply32x32(i32 noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @square96_c(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca %union.UN_96bitValue_, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #3
  tail call void @square64(ptr noundef %0, ptr noundef %1)
  %4 = getelementptr inbounds i8, ptr %1, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = tail call i64 @multiply32x32(i32 noundef %5, i32 noundef %5)
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %6, ptr %7, align 8, !tbaa !5
  %8 = load i32, ptr %4, align 8, !tbaa !5
  call void @multiply32x64(ptr noundef nonnull %3, i32 noundef %8, ptr noundef %1)
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = zext i32 %10 to i64
  %12 = load i32, ptr %3, align 8, !tbaa !5
  %13 = zext i32 %12 to i64
  %reass.add = shl nuw nsw i64 %13, 1
  %14 = add nuw nsw i64 %reass.add, %11
  %15 = trunc i64 %14 to i32
  store i32 %15, ptr %9, align 4, !tbaa !5
  %16 = lshr i64 %14, 32
  %17 = getelementptr inbounds i8, ptr %0, i64 12
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = zext i32 %18 to i64
  %20 = add nuw nsw i64 %16, %19
  %21 = getelementptr inbounds i8, ptr %3, i64 4
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = zext i32 %22 to i64
  %reass.add.1 = shl nuw nsw i64 %23, 1
  %24 = add nuw nsw i64 %20, %reass.add.1
  %25 = trunc i64 %24 to i32
  store i32 %25, ptr %17, align 4, !tbaa !5
  %26 = lshr i64 %24, 32
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = zext i32 %27 to i64
  %29 = add nuw nsw i64 %26, %28
  %30 = getelementptr inbounds i8, ptr %3, i64 8
  %31 = load i32, ptr %30, align 8, !tbaa !5
  %32 = zext i32 %31 to i64
  %reass.add.2 = shl nuw nsw i64 %32, 1
  %33 = add nuw nsw i64 %29, %reass.add.2
  %34 = trunc i64 %33 to i32
  store i32 %34, ptr %7, align 4, !tbaa !5
  %35 = lshr i64 %33, 32
  %36 = trunc nuw nsw i64 %35 to i32
  %37 = getelementptr inbounds i8, ptr %0, i64 20
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = add i32 %38, %36
  store i32 %39, ptr %37, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #3
  ret void
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @square64(ptr noundef, ptr noundef) local_unnamed_addr #0

attributes #0 = { alwaysinline 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 }

!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,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass