; 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: alwaysinline nounwind uwtable
declare dso_local void @multiply64x64(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @multiply96x96_c(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %union.UN_96bitValue_, align 8
  %8 = alloca %union.UN_96bitValue_, align 8
  %9 = alloca i8, align 1
  %10 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds [1 x %union.UN_128bitValue_], ptr %11, i64 0, i64 0
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds [1 x i64], ptr %13, i64 0, i64 0
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds [1 x i64], ptr %15, i64 0, i64 0
  call void @multiply64x64(ptr noundef %12, ptr noundef %14, ptr noundef %16)
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds [3 x i32], ptr %17, i64 0, i64 2
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds [3 x i32], ptr %20, i64 0, i64 2
  %22 = load i32, ptr %21, align 8, !tbaa !11
  %23 = call i64 @multiply32x32(i32 noundef %19, i32 noundef %22)
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds [3 x i64], ptr %24, i64 0, i64 2
  store i64 %23, ptr %25, align 8, !tbaa !11
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds [3 x i32], ptr %26, i64 0, i64 2
  %28 = load i32, ptr %27, align 8, !tbaa !11
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds [1 x i64], ptr %29, i64 0, i64 0
  call void @multiply32x64(ptr noundef %7, i32 noundef %28, ptr noundef %30)
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds [3 x i32], ptr %31, i64 0, i64 2
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds [1 x i64], ptr %34, i64 0, i64 0
  call void @multiply32x64(ptr noundef %8, i32 noundef %33, ptr noundef %35)
  store i8 0, ptr %9, align 1, !tbaa !11
  br label %36

36:                                               ; preds = %75, %3
  %37 = load i8, ptr %9, align 1, !tbaa !11
  %38 = zext i8 %37 to i32
  %39 = icmp slt i32 %38, 3
  br i1 %39, label %40, label %78

40:                                               ; preds = %36
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load i8, ptr %9, align 1, !tbaa !11
  %43 = zext i8 %42 to i32
  %44 = add nsw i32 2, %43
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [6 x i32], ptr %41, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !11
  %48 = zext i32 %47 to i64
  %49 = load i64, ptr %10, align 8, !tbaa !9
  %50 = add i64 %49, %48
  store i64 %50, ptr %10, align 8, !tbaa !9
  %51 = load i8, ptr %9, align 1, !tbaa !11
  %52 = zext i8 %51 to i64
  %53 = getelementptr inbounds [3 x i32], ptr %7, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !11
  %55 = zext i32 %54 to i64
  %56 = load i64, ptr %10, align 8, !tbaa !9
  %57 = add i64 %56, %55
  store i64 %57, ptr %10, align 8, !tbaa !9
  %58 = load i8, ptr %9, align 1, !tbaa !11
  %59 = zext i8 %58 to i64
  %60 = getelementptr inbounds [3 x i32], ptr %8, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !11
  %62 = zext i32 %61 to i64
  %63 = load i64, ptr %10, align 8, !tbaa !9
  %64 = add i64 %63, %62
  store i64 %64, ptr %10, align 8, !tbaa !9
  %65 = load i64, ptr %10, align 8, !tbaa !9
  %66 = trunc i64 %65 to i32
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = load i8, ptr %9, align 1, !tbaa !11
  %69 = zext i8 %68 to i32
  %70 = add nsw i32 2, %69
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [6 x i32], ptr %67, i64 0, i64 %71
  store i32 %66, ptr %72, align 4, !tbaa !11
  %73 = load i64, ptr %10, align 8, !tbaa !9
  %74 = lshr i64 %73, 32
  store i64 %74, ptr %10, align 8, !tbaa !9
  br label %75

75:                                               ; preds = %40
  %76 = load i8, ptr %9, align 1, !tbaa !11
  %77 = add i8 %76, 1
  store i8 %77, ptr %9, align 1, !tbaa !11
  br label %36, !llvm.loop !12

78:                                               ; preds = %36
  %79 = load i64, ptr %10, align 8, !tbaa !9
  %80 = trunc i64 %79 to i32
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds [6 x i32], ptr %81, i64 0, i64 5
  %83 = load i32, ptr %82, align 4, !tbaa !11
  %84 = add i32 %83, %80
  store i32 %84, ptr %82, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #3
  ret void
}

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: alwaysinline nounwind uwtable
declare dso_local void @multiply64x64(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

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