; LLVM IR from specinfo-ua/UAPKI :: library/uapkic/src (math-int-internal)

; 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.Dword_st = type { i64, i64 }
%struct.WordArray_st = type { ptr, i64 }

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

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

; 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 hidden void @word_mul_64(i64 noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @factorial(i64 noundef %0, ptr noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca %struct.Dword_st, align 8
  %8 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8, !tbaa !9
  call void @wa_one(ptr noundef %9)
  store i64 2, ptr %5, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %43, %2
  %11 = load i64, ptr %5, align 8, !tbaa !5
  %12 = load i64, ptr %3, align 8, !tbaa !5
  %13 = icmp ule i64 %11, %12
  br i1 %13, label %14, label %46

14:                                               ; preds = %10
  store i64 0, ptr %6, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %39, %14
  %16 = load i64, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %4, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.WordArray_st, ptr %17, i32 0, i32 1
  %19 = load i64, ptr %18, align 8, !tbaa !11
  %20 = icmp ult i64 %16, %19
  br i1 %20, label %21, label %42

21:                                               ; preds = %15
  %22 = load ptr, ptr %4, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.WordArray_st, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = load i64, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds i64, ptr %24, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !5
  %28 = load i64, ptr %5, align 8, !tbaa !5
  call void @word_mul_64(i64 noundef %27, i64 noundef %28, ptr noundef %7)
  %29 = load i64, ptr %8, align 8, !tbaa !5
  call void @word_add_word_64(ptr noundef %7, i64 noundef %29, ptr noundef %7)
  %30 = getelementptr inbounds %struct.Dword_st, ptr %7, i32 0, i32 0
  %31 = load i64, ptr %30, align 8, !tbaa !14
  %32 = load ptr, ptr %4, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.WordArray_st, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !13
  %35 = load i64, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds i64, ptr %34, i64 %35
  store i64 %31, ptr %36, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.Dword_st, ptr %7, i32 0, i32 1
  %38 = load i64, ptr %37, align 8, !tbaa !16
  store i64 %38, ptr %8, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %21
  %40 = load i64, ptr %6, align 8, !tbaa !5
  %41 = add i64 %40, 1
  store i64 %41, ptr %6, align 8, !tbaa !5
  br label %15, !llvm.loop !17

42:                                               ; preds = %15
  br label %43

43:                                               ; preds = %42
  %44 = load i64, ptr %5, align 8, !tbaa !5
  %45 = add i64 %44, 1
  store i64 %45, ptr %5, align 8, !tbaa !5
  br label %10, !llvm.loop !19

46:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

declare void @wa_one(ptr noundef) #2

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 = { "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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"WordArray_st", !10, i64 0, !6, i64 8}
!13 = !{!12, !10, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"Dword_st", !6, i64 0, !6, i64 8}
!16 = !{!15, !6, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


; 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.Dword_st = type { i64, i64 }

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

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

; 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 hidden void @word_mul_64(i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @factorial(i64 noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca %struct.Dword_st, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #3
  tail call void @wa_one(ptr noundef %1) #3
  %.not16 = icmp ult i64 %0, 2
  br i1 %.not16, label %._crit_edge19, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %2
  %4 = getelementptr inbounds i8, ptr %1, i64 8
  %5 = getelementptr inbounds i8, ptr %3, i64 8
  %6 = load i64, ptr %4, align 8, !tbaa !5
  %.not20 = icmp eq i64 %6, 0
  br i1 %.not20, label %._crit_edge19, label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %7 = phi i64 [ %18, %._crit_edge ], [ 1, %.preheader.lr.ph ]
  %.018 = phi i64 [ %.1.lcssa, %._crit_edge ], [ 0, %.preheader.lr.ph ]
  %.01317 = phi i64 [ %19, %._crit_edge ], [ 2, %.preheader.lr.ph ]
  %.not21 = icmp eq i64 %7, 0
  br i1 %.not21, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %.pre = load ptr, ptr %1, align 8, !tbaa !11
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %8 = phi ptr [ %12, %.lr.ph ], [ %.pre, %.lr.ph.preheader ]
  %.115 = phi i64 [ %14, %.lr.ph ], [ %.018, %.lr.ph.preheader ]
  %.01214 = phi i64 [ %15, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %9 = getelementptr inbounds i64, ptr %8, i64 %.01214
  %10 = load i64, ptr %9, align 8, !tbaa !12
  call void @word_mul_64(i64 noundef %10, i64 noundef %.01317, ptr noundef nonnull %3)
  call void @word_add_word_64(ptr noundef nonnull %3, i64 noundef %.115, ptr noundef nonnull %3)
  %11 = load i64, ptr %3, align 8, !tbaa !13
  %12 = load ptr, ptr %1, align 8, !tbaa !11
  %13 = getelementptr inbounds i64, ptr %12, i64 %.01214
  store i64 %11, ptr %13, align 8, !tbaa !12
  %14 = load i64, ptr %5, align 8, !tbaa !15
  %15 = add nuw i64 %.01214, 1
  %16 = load i64, ptr %4, align 8, !tbaa !5
  %17 = icmp ult i64 %15, %16
  br i1 %17, label %.lr.ph, label %._crit_edge, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %18 = phi i64 [ 0, %.preheader ], [ %16, %.lr.ph ]
  %.1.lcssa = phi i64 [ %.018, %.preheader ], [ %14, %.lr.ph ]
  %19 = add i64 %.01317, 1
  %.not = icmp ugt i64 %19, %0
  br i1 %.not, label %._crit_edge19, label %.preheader, !llvm.loop !18

._crit_edge19:                                    ; preds = %._crit_edge, %.preheader.lr.ph, %2
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #3
  ret void
}

declare void @wa_one(ptr noundef) local_unnamed_addr #2

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 = { "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, !10, i64 8}
!6 = !{!"WordArray_st", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!10, !10, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"Dword_st", !10, i64 0, !10, i64 8}
!15 = !{!14, !10, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17, !19}
!19 = !{!"llvm.loop.unswitch.partial.disable"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass