; LLVM IR from openssl/openssl :: crypto/ec/curve448 (scalar)

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

%struct.curve448_scalar_s = type { [7 x i64] }

@sc_p = external hidden constant [1 x %struct.curve448_scalar_s], align 16

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

; Function Attrs: nounwind uwtable
define dso_local void @ossl_curve448_scalar_add(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i128, align 16
  %8 = alloca i32, align 4
  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) #2
  store i128 0, ptr %7, align 16, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %9

9:                                                ; preds = %39, %3
  %10 = load i32, ptr %8, align 4, !tbaa !11
  %11 = icmp ult i32 %10, 7
  br i1 %11, label %12, label %42

12:                                               ; preds = %9
  %13 = load i128, ptr %7, align 16, !tbaa !9
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.curve448_scalar_s, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %8, align 4, !tbaa !11
  %17 = zext i32 %16 to i64
  %18 = getelementptr inbounds [7 x i64], ptr %15, i64 0, i64 %17
  %19 = load i64, ptr %18, align 8, !tbaa !13
  %20 = zext i64 %19 to i128
  %21 = add i128 %13, %20
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.curve448_scalar_s, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %8, align 4, !tbaa !11
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds [7 x i64], ptr %23, i64 0, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !13
  %28 = zext i64 %27 to i128
  %29 = add i128 %21, %28
  store i128 %29, ptr %7, align 16, !tbaa !9
  %30 = load i128, ptr %7, align 16, !tbaa !9
  %31 = trunc i128 %30 to i64
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.curve448_scalar_s, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %8, align 4, !tbaa !11
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds [7 x i64], ptr %33, i64 0, i64 %35
  store i64 %31, ptr %36, align 8, !tbaa !13
  %37 = load i128, ptr %7, align 16, !tbaa !9
  %38 = lshr i128 %37, 64
  store i128 %38, ptr %7, align 16, !tbaa !9
  br label %39

39:                                               ; preds = %12
  %40 = load i32, ptr %8, align 4, !tbaa !11
  %41 = add i32 %40, 1
  store i32 %41, ptr %8, align 4, !tbaa !11
  br label %9, !llvm.loop !15

42:                                               ; preds = %9
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.curve448_scalar_s, ptr %44, i32 0, i32 0
  %46 = getelementptr inbounds [7 x i64], ptr %45, i64 0, i64 0
  %47 = load i128, ptr %7, align 16, !tbaa !9
  %48 = trunc i128 %47 to i64
  call void @sc_subx(ptr noundef %43, ptr noundef %46, ptr noundef @sc_p, ptr noundef @sc_p, i64 noundef %48)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #2
  ret void
}

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

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

attributes #0 = { 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 }

!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 = !{!"__int128", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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"

%struct.curve448_scalar_s = type { [7 x i64] }

@sc_p = external hidden constant [1 x %struct.curve448_scalar_s], align 16

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

; Function Attrs: nounwind uwtable
define dso_local void @ossl_curve448_scalar_add(ptr noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %4 = load i64, ptr %1, align 8, !tbaa !5
  %5 = load i64, ptr %2, align 8, !tbaa !5
  %add.narrowed = add i64 %4, %5
  %add.narrowed.overflow = icmp ult i64 %add.narrowed, %4
  store i64 %add.narrowed, ptr %0, align 8, !tbaa !5
  %6 = zext i1 %add.narrowed.overflow to i128
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = zext i64 %8 to i128
  %10 = add nuw nsw i128 %6, %9
  %11 = getelementptr inbounds i8, ptr %2, i64 8
  %12 = load i64, ptr %11, align 8, !tbaa !5
  %13 = zext i64 %12 to i128
  %14 = add nuw nsw i128 %10, %13
  %15 = trunc i128 %14 to i64
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %15, ptr %16, align 8, !tbaa !5
  %17 = lshr i128 %14, 64
  %18 = getelementptr inbounds i8, ptr %1, i64 16
  %19 = load i64, ptr %18, align 8, !tbaa !5
  %20 = zext i64 %19 to i128
  %21 = add nuw nsw i128 %17, %20
  %22 = getelementptr inbounds i8, ptr %2, i64 16
  %23 = load i64, ptr %22, align 8, !tbaa !5
  %24 = zext i64 %23 to i128
  %25 = add nuw nsw i128 %21, %24
  %26 = trunc i128 %25 to i64
  %27 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %26, ptr %27, align 8, !tbaa !5
  %28 = lshr i128 %25, 64
  %29 = getelementptr inbounds i8, ptr %1, i64 24
  %30 = load i64, ptr %29, align 8, !tbaa !5
  %31 = zext i64 %30 to i128
  %32 = add nuw nsw i128 %28, %31
  %33 = getelementptr inbounds i8, ptr %2, i64 24
  %34 = load i64, ptr %33, align 8, !tbaa !5
  %35 = zext i64 %34 to i128
  %36 = add nuw nsw i128 %32, %35
  %37 = trunc i128 %36 to i64
  %38 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 %37, ptr %38, align 8, !tbaa !5
  %39 = lshr i128 %36, 64
  %40 = getelementptr inbounds i8, ptr %1, i64 32
  %41 = load i64, ptr %40, align 8, !tbaa !5
  %42 = zext i64 %41 to i128
  %43 = add nuw nsw i128 %39, %42
  %44 = getelementptr inbounds i8, ptr %2, i64 32
  %45 = load i64, ptr %44, align 8, !tbaa !5
  %46 = zext i64 %45 to i128
  %47 = add nuw nsw i128 %43, %46
  %48 = trunc i128 %47 to i64
  %49 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 %48, ptr %49, align 8, !tbaa !5
  %50 = lshr i128 %47, 64
  %51 = getelementptr inbounds i8, ptr %1, i64 40
  %52 = load i64, ptr %51, align 8, !tbaa !5
  %53 = zext i64 %52 to i128
  %54 = add nuw nsw i128 %50, %53
  %55 = getelementptr inbounds i8, ptr %2, i64 40
  %56 = load i64, ptr %55, align 8, !tbaa !5
  %57 = zext i64 %56 to i128
  %58 = add nuw nsw i128 %54, %57
  %59 = trunc i128 %58 to i64
  %60 = getelementptr inbounds i8, ptr %0, i64 40
  store i64 %59, ptr %60, align 8, !tbaa !5
  %61 = lshr i128 %58, 64
  %62 = getelementptr inbounds i8, ptr %1, i64 48
  %63 = load i64, ptr %62, align 8, !tbaa !5
  %64 = zext i64 %63 to i128
  %65 = add nuw nsw i128 %61, %64
  %66 = getelementptr inbounds i8, ptr %2, i64 48
  %67 = load i64, ptr %66, align 8, !tbaa !5
  %68 = zext i64 %67 to i128
  %69 = add nuw nsw i128 %65, %68
  %70 = trunc i128 %69 to i64
  %71 = getelementptr inbounds i8, ptr %0, i64 48
  store i64 %70, ptr %71, align 8, !tbaa !5
  %72 = lshr i128 %69, 64
  %73 = trunc nuw nsw i128 %72 to i64
  tail call void @sc_subx(ptr noundef nonnull %0, ptr noundef nonnull %0, ptr noundef nonnull @sc_p, ptr noundef nonnull @sc_p, i64 noundef %73)
  ret void
}

attributes #0 = { 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" }

!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/C++ TBAA"}


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