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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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
define dso_local i32 @words_sub_64(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca %struct.Dword_st, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #3
  call void @llvm.memset.p0.i64(ptr align 8 %9, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 -9223372036854775808, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %50, %4
  %13 = load i64, ptr %11, align 8, !tbaa !9
  %14 = load i64, ptr %7, align 8, !tbaa !9
  %15 = icmp ult i64 %13, %14
  br i1 %15, label %16, label %53

16:                                               ; preds = %12
  %17 = getelementptr inbounds %struct.Dword_st, ptr %9, i32 0, i32 1
  %18 = load i64, ptr %17, align 8, !tbaa !11
  %19 = load i64, ptr %10, align 8, !tbaa !9
  %20 = and i64 %18, %19
  %21 = icmp ne i64 %20, 0
  br i1 %21, label %22, label %33

22:                                               ; preds = %16
  %23 = getelementptr inbounds %struct.Dword_st, ptr %9, i32 0, i32 1
  store i64 0, ptr %23, align 8, !tbaa !11
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load i64, ptr %11, align 8, !tbaa !9
  %26 = getelementptr inbounds i64, ptr %24, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.Dword_st, ptr %9, i32 0, i32 0
  store i64 %27, ptr %28, align 8, !tbaa !13
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load i64, ptr %11, align 8, !tbaa !9
  %31 = getelementptr inbounds i64, ptr %29, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !9
  call void @word_sub_word_64(ptr noundef %9, i64 noundef %32, ptr noundef %9)
  call void @word_sub_word_64(ptr noundef %9, i64 noundef 1, ptr noundef %9)
  br label %44

33:                                               ; preds = %16
  %34 = getelementptr inbounds %struct.Dword_st, ptr %9, i32 0, i32 1
  store i64 0, ptr %34, align 8, !tbaa !11
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load i64, ptr %11, align 8, !tbaa !9
  %37 = getelementptr inbounds i64, ptr %35, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.Dword_st, ptr %9, i32 0, i32 0
  store i64 %38, ptr %39, align 8, !tbaa !13
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load i64, ptr %11, align 8, !tbaa !9
  %42 = getelementptr inbounds i64, ptr %40, i64 %41
  %43 = load i64, ptr %42, align 8, !tbaa !9
  call void @word_sub_word_64(ptr noundef %9, i64 noundef %43, ptr noundef %9)
  br label %44

44:                                               ; preds = %33, %22
  %45 = getelementptr inbounds %struct.Dword_st, ptr %9, i32 0, i32 0
  %46 = load i64, ptr %45, align 8, !tbaa !13
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = load i64, ptr %11, align 8, !tbaa !9
  %49 = getelementptr inbounds i64, ptr %47, i64 %48
  store i64 %46, ptr %49, align 8, !tbaa !9
  br label %50

50:                                               ; preds = %44
  %51 = load i64, ptr %11, align 8, !tbaa !9
  %52 = add i64 %51, 1
  store i64 %52, ptr %11, align 8, !tbaa !9
  br label %12, !llvm.loop !14

53:                                               ; preds = %12
  %54 = getelementptr inbounds %struct.Dword_st, ptr %9, i32 0, i32 1
  %55 = load i64, ptr %54, align 8, !tbaa !11
  %56 = trunc i64 %55 to i32
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #3
  ret i32 %56
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!12, !10, i64 8}
!12 = !{!"Dword_st", !10, i64 0, !10, i64 8}
!13 = !{!12, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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 }

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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
define dso_local i32 @words_sub_64(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i64 noundef %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #2 {
  %5 = alloca %struct.Dword_st, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #3
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %5, i8 0, i64 16, i1 false)
  %.not14 = icmp eq i64 %2, 0
  br i1 %.not14, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %6 = getelementptr inbounds i8, ptr %5, i64 8
  br label %7

7:                                                ; preds = %.lr.ph, %14
  %.013 = phi i64 [ 0, %.lr.ph ], [ %17, %14 ]
  %8 = load i64, ptr %6, align 8, !tbaa !5
  %.not = icmp sgt i64 %8, -1
  store i64 0, ptr %6, align 8, !tbaa !5
  %9 = getelementptr inbounds i64, ptr %0, i64 %.013
  %10 = load i64, ptr %9, align 8, !tbaa !10
  store i64 %10, ptr %5, align 8, !tbaa !11
  %11 = getelementptr inbounds i64, ptr %1, i64 %.013
  %12 = load i64, ptr %11, align 8, !tbaa !10
  call void @word_sub_word_64(ptr noundef nonnull %5, i64 noundef %12, ptr noundef nonnull %5)
  br i1 %.not, label %14, label %13

13:                                               ; preds = %7
  call void @word_sub_word_64(ptr noundef nonnull %5, i64 noundef 1, ptr noundef nonnull %5)
  br label %14

14:                                               ; preds = %7, %13
  %15 = load i64, ptr %5, align 8, !tbaa !11
  %16 = getelementptr inbounds i64, ptr %3, i64 %.013
  store i64 %15, ptr %16, align 8, !tbaa !10
  %17 = add nuw i64 %.013, 1
  %exitcond.not = icmp eq i64 %17, %2
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %7, !llvm.loop !12

._crit_edge.loopexit:                             ; preds = %14
  %.pre = load i64, ptr %6, align 8, !tbaa !5
  %18 = trunc i64 %.pre to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %4
  %19 = phi i32 [ %18, %._crit_edge.loopexit ], [ 0, %4 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #3
  ret i32 %19
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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, !7, i64 8}
!6 = !{!"Dword_st", !7, i64 0, !7, i64 8}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = !{!6, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass