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

; 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.gf_s = type { [8 x i64] }

@.str = external hidden unnamed_addr constant [19 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1
@__PRETTY_FUNCTION__.gf_serialize = external hidden unnamed_addr constant [55 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @gf_serialize(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i128, align 16
  %10 = alloca i32, align 4
  %11 = alloca [1 x %struct.gf_s], align 16
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #4
  store i128 0, ptr %9, align 16, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 64, ptr %11) #4
  %12 = getelementptr inbounds [1 x %struct.gf_s], ptr %11, i64 0, i64 0
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  call void @gf_copy(ptr noundef %12, ptr noundef %13)
  %14 = getelementptr inbounds [1 x %struct.gf_s], ptr %11, i64 0, i64 0
  call void @gf_strong_reduce(ptr noundef %14)
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %24, label %17

17:                                               ; preds = %3
  %18 = getelementptr inbounds [1 x %struct.gf_s], ptr %11, i64 0, i64 0
  %19 = call i64 @gf_hibit(ptr noundef %18)
  %20 = icmp eq i64 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %17
  br label %23

22:                                               ; preds = %17
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 31, ptr noundef @__PRETTY_FUNCTION__.gf_serialize) #5
  unreachable

23:                                               ; preds = %21
  br label %24

24:                                               ; preds = %23, %3
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %67, %24
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = icmp ne i32 %27, 0
  %29 = zext i1 %28 to i64
  %30 = select i1 %28, i32 56, i32 56
  %31 = icmp slt i32 %26, %30
  br i1 %31, label %32, label %70

32:                                               ; preds = %25
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = icmp ult i32 %33, 8
  br i1 %34, label %35, label %56

35:                                               ; preds = %32
  %36 = load i32, ptr %7, align 4, !tbaa !9
  %37 = zext i32 %36 to i64
  %38 = icmp ult i64 %37, 8
  br i1 %38, label %39, label %56

39:                                               ; preds = %35
  %40 = getelementptr inbounds [1 x %struct.gf_s], ptr %11, i64 0, i64 0
  %41 = getelementptr inbounds %struct.gf_s, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds [8 x i64], ptr %41, i64 0, i64 %43
  %45 = load i64, ptr %44, align 8, !tbaa !13
  %46 = zext i64 %45 to i128
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = zext i32 %47 to i128
  %49 = shl i128 %46, %48
  %50 = load i128, ptr %9, align 16, !tbaa !11
  %51 = or i128 %50, %49
  store i128 %51, ptr %9, align 16, !tbaa !11
  %52 = load i32, ptr %8, align 4, !tbaa !9
  %53 = add i32 %52, 56
  store i32 %53, ptr %8, align 4, !tbaa !9
  %54 = load i32, ptr %7, align 4, !tbaa !9
  %55 = add i32 %54, 1
  store i32 %55, ptr %7, align 4, !tbaa !9
  br label %56

56:                                               ; preds = %39, %35, %32
  %57 = load i128, ptr %9, align 16, !tbaa !11
  %58 = trunc i128 %57 to i8
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = load i32, ptr %10, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds i8, ptr %59, i64 %61
  store i8 %58, ptr %62, align 1, !tbaa !15
  %63 = load i32, ptr %8, align 4, !tbaa !9
  %64 = sub i32 %63, 8
  store i32 %64, ptr %8, align 4, !tbaa !9
  %65 = load i128, ptr %9, align 16, !tbaa !11
  %66 = lshr i128 %65, 8
  store i128 %66, ptr %9, align 16, !tbaa !11
  br label %67

67:                                               ; preds = %56
  %68 = load i32, ptr %10, align 4, !tbaa !9
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %10, align 4, !tbaa !9
  br label %25, !llvm.loop !16

70:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 64, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  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: alwaysinline nounwind uwtable
declare hidden void @gf_copy(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @gf_strong_reduce(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @gf_hibit(ptr noundef) #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

; 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 = { 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 #3 = { noreturn nounwind "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 }
attributes #5 = { noreturn 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}
!11 = !{!12, !12, i64 0}
!12 = !{!"__int128", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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.gf_s = type { [8 x i64] }

@.str = external hidden unnamed_addr constant [19 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1
@__PRETTY_FUNCTION__.gf_serialize = external hidden unnamed_addr constant [55 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @gf_serialize(ptr nocapture noundef writeonly %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca [1 x %struct.gf_s], align 16
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %4) #4
  call void @gf_copy(ptr noundef nonnull %4, ptr noundef %1)
  call void @gf_strong_reduce(ptr noundef nonnull %4)
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %5, label %.preheader

.preheader:                                       ; preds = %5, %3
  br label %9

5:                                                ; preds = %3
  %6 = call i64 @gf_hibit(ptr noundef nonnull %4)
  %7 = icmp eq i64 %6, 0
  br i1 %7, label %.preheader, label %8

8:                                                ; preds = %5
  call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 31, ptr noundef nonnull @__PRETTY_FUNCTION__.gf_serialize) #5
  unreachable

9:                                                ; preds = %.preheader, %22
  %indvars.iv = phi i64 [ %indvars.iv.next, %22 ], [ 0, %.preheader ]
  %.01826 = phi i128 [ %26, %22 ], [ 0, %.preheader ]
  %.01925 = phi i32 [ %25, %22 ], [ 0, %.preheader ]
  %.02124 = phi i32 [ %.122, %22 ], [ 0, %.preheader ]
  %10 = icmp ult i32 %.01925, 8
  %11 = icmp ult i32 %.02124, 8
  %or.cond = select i1 %10, i1 %11, i1 false
  br i1 %or.cond, label %12, label %22

12:                                               ; preds = %9
  %13 = zext nneg i32 %.02124 to i64
  %14 = getelementptr inbounds [8 x i64], ptr %4, i64 0, i64 %13
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = zext i64 %15 to i128
  %17 = zext nneg i32 %.01925 to i128
  %18 = shl nuw nsw i128 %16, %17
  %19 = or i128 %18, %.01826
  %20 = or disjoint i32 %.01925, 56
  %21 = add nuw nsw i32 %.02124, 1
  br label %22

22:                                               ; preds = %12, %9
  %.122 = phi i32 [ %21, %12 ], [ %.02124, %9 ]
  %.120 = phi i32 [ %20, %12 ], [ %.01925, %9 ]
  %.1 = phi i128 [ %19, %12 ], [ %.01826, %9 ]
  %23 = trunc i128 %.1 to i8
  %24 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  store i8 %23, ptr %24, align 1, !tbaa !9
  %25 = add i32 %.120, -8
  %26 = lshr i128 %.1, 8
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 56
  br i1 %exitcond.not, label %27, label %9, !llvm.loop !10

27:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %4) #4
  ret void
}

; 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 void @gf_copy(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @gf_strong_reduce(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @gf_hibit(ptr noundef) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { noreturn nounwind "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 }
attributes #5 = { noreturn 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass