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

@.str = external hidden unnamed_addr constant [27 x i8], align 1

; 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
declare dso_local void @int_div(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

declare ptr @wa_alloc_with_zero(i64 noundef) #2

declare void @stacktrace_add(ptr noundef, i64 noundef, i32 noundef) #2

declare i32 @wa_copy_part(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #2

declare void @wa_free(ptr noundef) #2

declare void @stacktrace_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) #2

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

16:                                               ; preds = %5
  %17 = load i64, ptr %7, align 8, !tbaa !9
  %18 = load i64, ptr %8, align 8, !tbaa !9
  %19 = icmp ule i64 %17, %18
  br i1 %19, label %22, label %20

20:                                               ; preds = %16
  store i32 2, ptr %15, align 4, !tbaa !11
  %21 = load i32, ptr %15, align 4, !tbaa !11
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 1068, i32 noundef %21, ptr noundef null)
  br label %85

22:                                               ; preds = %16
  br label %23

23:                                               ; preds = %22
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  %26 = load i32, ptr %9, align 4, !tbaa !11
  %27 = mul nsw i32 2, %26
  %28 = sext i32 %27 to i64
  %29 = call ptr @wa_alloc_with_zero(i64 noundef %28)
  store ptr %29, ptr %14, align 8, !tbaa !5
  %30 = icmp eq ptr null, %29
  br i1 %30, label %31, label %33

31:                                               ; preds = %25
  store i32 2, ptr %15, align 4, !tbaa !11
  %32 = load i32, ptr %15, align 4, !tbaa !11
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 1070, i32 noundef %32)
  br label %85

33:                                               ; preds = %25
  br label %34

34:                                               ; preds = %33
  br label %35

35:                                               ; preds = %34
  store i64 0, ptr %13, align 8, !tbaa !9
  store i32 0, ptr %11, align 4, !tbaa !11
  br label %36

36:                                               ; preds = %60, %35
  %37 = load i32, ptr %11, align 4, !tbaa !11
  %38 = load i32, ptr %9, align 4, !tbaa !11
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %40, label %63

40:                                               ; preds = %36
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.WordArray_st, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !13
  %44 = load i32, ptr %11, align 4, !tbaa !11
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i64, ptr %43, i64 %45
  %47 = load i64, ptr %46, align 8, !tbaa !9
  %48 = load i64, ptr %7, align 8, !tbaa !9
  call void @word_mul_64(i64 noundef %47, i64 noundef %48, ptr noundef %12)
  %49 = load i64, ptr %13, align 8, !tbaa !9
  call void @word_add_word_64(ptr noundef %12, i64 noundef %49, ptr noundef %12)
  %50 = getelementptr inbounds %struct.Dword_st, ptr %12, i32 0, i32 0
  %51 = load i64, ptr %50, align 8, !tbaa !15
  %52 = load ptr, ptr %14, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.WordArray_st, ptr %52, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !13
  %55 = load i32, ptr %11, align 4, !tbaa !11
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i64, ptr %54, i64 %56
  store i64 %51, ptr %57, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.Dword_st, ptr %12, i32 0, i32 1
  %59 = load i64, ptr %58, align 8, !tbaa !17
  store i64 %59, ptr %13, align 8, !tbaa !9
  br label %60

60:                                               ; preds = %40
  %61 = load i32, ptr %11, align 4, !tbaa !11
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %11, align 4, !tbaa !11
  br label %36, !llvm.loop !18

63:                                               ; preds = %36
  %64 = load i64, ptr %13, align 8, !tbaa !9
  %65 = load ptr, ptr %14, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.WordArray_st, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !13
  %68 = load i32, ptr %9, align 4, !tbaa !11
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds i64, ptr %67, i64 %69
  store i64 %64, ptr %70, align 8, !tbaa !9
  %71 = load ptr, ptr %10, align 8, !tbaa !5
  call void @wa_zero(ptr noundef %71)
  %72 = load i64, ptr %8, align 8, !tbaa !9
  %73 = load ptr, ptr %10, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.WordArray_st, ptr %73, i32 0, i32 0
  %75 = load ptr, ptr %74, align 8, !tbaa !13
  %76 = getelementptr inbounds i64, ptr %75, i64 0
  store i64 %72, ptr %76, align 8, !tbaa !9
  %77 = load ptr, ptr %14, align 8, !tbaa !5
  %78 = load ptr, ptr %10, align 8, !tbaa !5
  %79 = load ptr, ptr %14, align 8, !tbaa !5
  call void @int_div(ptr noundef %77, ptr noundef %78, ptr noundef %79, ptr noundef null)
  %80 = load ptr, ptr %14, align 8, !tbaa !5
  %81 = load i32, ptr %9, align 4, !tbaa !11
  %82 = sext i32 %81 to i64
  %83 = load ptr, ptr %10, align 8, !tbaa !5
  %84 = call i32 @wa_copy_part(ptr noundef %80, i64 noundef 0, i64 noundef %82, ptr noundef %83)
  br label %85

85:                                               ; preds = %63, %31, %20
  %86 = load ptr, ptr %14, align 8, !tbaa !5
  call void @wa_free(ptr noundef %86)
  %87 = load i32, ptr %15, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  ret i32 %87
}

declare void @wa_zero(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 = !{!"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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"WordArray_st", !6, i64 0, !10, i64 8}
!15 = !{!16, !10, i64 0}
!16 = !{!"Dword_st", !10, i64 0, !10, i64 8}
!17 = !{!16, !10, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"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.Dword_st = type { i64, i64 }

@.str = external hidden unnamed_addr constant [27 x i8], align 1

; 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
declare dso_local void @int_div(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @wa_alloc_with_zero(i64 noundef) local_unnamed_addr #2

declare void @stacktrace_add(ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #2

declare i32 @wa_copy_part(ptr noundef, i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

declare void @wa_free(ptr noundef) local_unnamed_addr #2

declare void @stacktrace_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 3) i32 @int_mult_and_div(ptr nocapture noundef readonly %0, i64 noundef %1, i64 noundef %2, i32 noundef %3, ptr noundef %4) local_unnamed_addr #1 {
  %6 = alloca %struct.Dword_st, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #3
  %.not = icmp ugt i64 %1, %2
  br i1 %.not, label %7, label %8

7:                                                ; preds = %5
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 1068, i32 noundef 2, ptr noundef null) #3
  br label %29

8:                                                ; preds = %5
  %9 = shl nsw i32 %3, 1
  %10 = sext i32 %9 to i64
  %11 = tail call ptr @wa_alloc_with_zero(i64 noundef %10) #3
  %12 = icmp eq ptr %11, null
  br i1 %12, label %15, label %.preheader

.preheader:                                       ; preds = %8
  %13 = icmp sgt i32 %3, 0
  br i1 %13, label %.lr.ph, label %.preheader.._crit_edge_crit_edge

.preheader.._crit_edge_crit_edge:                 ; preds = %.preheader
  %.pre = load ptr, ptr %11, align 8, !tbaa !5
  br label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %14 = getelementptr inbounds i8, ptr %6, i64 8
  %wide.trip.count = zext nneg i32 %3 to i64
  br label %16

15:                                               ; preds = %8
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 1070, i32 noundef 2) #3
  br label %29

16:                                               ; preds = %.lr.ph, %16
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %16 ]
  %.02835 = phi i64 [ 0, %.lr.ph ], [ %23, %16 ]
  %17 = load ptr, ptr %0, align 8, !tbaa !5
  %18 = getelementptr inbounds i64, ptr %17, i64 %indvars.iv
  %19 = load i64, ptr %18, align 8, !tbaa !11
  call void @word_mul_64(i64 noundef %19, i64 noundef %1, ptr noundef nonnull %6)
  call void @word_add_word_64(ptr noundef nonnull %6, i64 noundef %.02835, ptr noundef nonnull %6)
  %20 = load i64, ptr %6, align 8, !tbaa !12
  %21 = load ptr, ptr %11, align 8, !tbaa !5
  %22 = getelementptr inbounds i64, ptr %21, i64 %indvars.iv
  store i64 %20, ptr %22, align 8, !tbaa !11
  %23 = load i64, ptr %14, align 8, !tbaa !14
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %16, !llvm.loop !15

._crit_edge:                                      ; preds = %16, %.preheader.._crit_edge_crit_edge
  %24 = phi ptr [ %.pre, %.preheader.._crit_edge_crit_edge ], [ %21, %16 ]
  %.028.lcssa = phi i64 [ 0, %.preheader.._crit_edge_crit_edge ], [ %23, %16 ]
  %25 = sext i32 %3 to i64
  %26 = getelementptr inbounds i64, ptr %24, i64 %25
  store i64 %.028.lcssa, ptr %26, align 8, !tbaa !11
  call void @wa_zero(ptr noundef %4) #3
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  store i64 %2, ptr %27, align 8, !tbaa !11
  call void @int_div(ptr noundef nonnull %11, ptr noundef nonnull %4, ptr noundef nonnull %11, ptr noundef null)
  %28 = call i32 @wa_copy_part(ptr noundef nonnull %11, i64 noundef 0, i64 noundef %25, ptr noundef nonnull %4) #3
  br label %29

29:                                               ; preds = %._crit_edge, %15, %7
  %.027 = phi ptr [ null, %15 ], [ %11, %._crit_edge ], [ null, %7 ]
  %.0 = phi i32 [ 2, %15 ], [ 0, %._crit_edge ], [ 2, %7 ]
  call void @wa_free(ptr noundef %.027) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #3
  ret i32 %.0
}

declare void @wa_zero(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, !7, i64 0}
!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 = !{!10, !10, i64 0}
!12 = !{!13, !10, i64 0}
!13 = !{!"Dword_st", !10, i64 0, !10, i64 8}
!14 = !{!13, !10, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass