; LLVM IR from atcoder/ac-library :: test/example/convolution_int_practice.ll (ZN7atcoder8internal18floor_sum_unsignedEyyyy)

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

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

12:                                               ; preds = %66, %4
  br label %13

13:                                               ; preds = %12
  %14 = load i64, ptr %7, align 8, !tbaa !5
  %15 = load i64, ptr %6, align 8, !tbaa !5
  %16 = icmp uge i64 %14, %15
  br i1 %16, label %17, label %32

17:                                               ; preds = %13
  %18 = load i64, ptr %5, align 8, !tbaa !5
  %19 = load i64, ptr %5, align 8, !tbaa !5
  %20 = sub i64 %19, 1
  %21 = mul i64 %18, %20
  %22 = udiv i64 %21, 2
  %23 = load i64, ptr %7, align 8, !tbaa !5
  %24 = load i64, ptr %6, align 8, !tbaa !5
  %25 = udiv i64 %23, %24
  %26 = mul i64 %22, %25
  %27 = load i64, ptr %9, align 8, !tbaa !5
  %28 = add i64 %27, %26
  store i64 %28, ptr %9, align 8, !tbaa !5
  %29 = load i64, ptr %6, align 8, !tbaa !5
  %30 = load i64, ptr %7, align 8, !tbaa !5
  %31 = urem i64 %30, %29
  store i64 %31, ptr %7, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %17, %13
  %33 = load i64, ptr %8, align 8, !tbaa !5
  %34 = load i64, ptr %6, align 8, !tbaa !5
  %35 = icmp uge i64 %33, %34
  br i1 %35, label %36, label %47

36:                                               ; preds = %32
  %37 = load i64, ptr %5, align 8, !tbaa !5
  %38 = load i64, ptr %8, align 8, !tbaa !5
  %39 = load i64, ptr %6, align 8, !tbaa !5
  %40 = udiv i64 %38, %39
  %41 = mul i64 %37, %40
  %42 = load i64, ptr %9, align 8, !tbaa !5
  %43 = add i64 %42, %41
  store i64 %43, ptr %9, align 8, !tbaa !5
  %44 = load i64, ptr %6, align 8, !tbaa !5
  %45 = load i64, ptr %8, align 8, !tbaa !5
  %46 = urem i64 %45, %44
  store i64 %46, ptr %8, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %36, %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %48 = load i64, ptr %7, align 8, !tbaa !5
  %49 = load i64, ptr %5, align 8, !tbaa !5
  %50 = mul i64 %48, %49
  %51 = load i64, ptr %8, align 8, !tbaa !5
  %52 = add i64 %50, %51
  store i64 %52, ptr %10, align 8, !tbaa !5
  %53 = load i64, ptr %10, align 8, !tbaa !5
  %54 = load i64, ptr %6, align 8, !tbaa !5
  %55 = icmp ult i64 %53, %54
  br i1 %55, label %56, label %57

56:                                               ; preds = %47
  store i32 3, ptr %11, align 4
  br label %64

57:                                               ; preds = %47
  %58 = load i64, ptr %10, align 8, !tbaa !5
  %59 = load i64, ptr %6, align 8, !tbaa !5
  %60 = udiv i64 %58, %59
  store i64 %60, ptr %5, align 8, !tbaa !5
  %61 = load i64, ptr %10, align 8, !tbaa !5
  %62 = load i64, ptr %6, align 8, !tbaa !5
  %63 = urem i64 %61, %62
  store i64 %63, ptr %8, align 8, !tbaa !5
  call void @_ZSt4swapIyENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 8 dereferenceable(8) %6, ptr noundef nonnull align 8 dereferenceable(8) %7) #3
  store i32 0, ptr %11, align 4
  br label %64

64:                                               ; preds = %57, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %65 = load i32, ptr %11, align 4
  switch i32 %65, label %69 [
    i32 0, label %66
    i32 3, label %67
  ]

66:                                               ; preds = %64
  br label %12, !llvm.loop !9

67:                                               ; preds = %64
  %68 = load i64, ptr %9, align 8, !tbaa !5
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret i64 %68

69:                                               ; preds = %64
  unreachable
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIyENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { inlinehint mustprogress 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"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"

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_ZN7atcoder8internal18floor_sum_unsignedEyyyy(i64 noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store i64 %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %29, %4
  %8 = phi i64 [ %1, %4 ], [ %.pre31, %29 ]
  %9 = phi i64 [ %2, %4 ], [ %.pre, %29 ]
  %.018 = phi i64 [ %3, %4 ], [ %31, %29 ]
  %.016 = phi i64 [ 0, %4 ], [ %.2, %29 ]
  %.015 = phi i64 [ %0, %4 ], [ %30, %29 ]
  %.not = icmp ult i64 %9, %8
  br i1 %.not, label %18, label %10

10:                                               ; preds = %7
  %11 = add i64 %.015, -1
  %12 = mul i64 %11, %.015
  %13 = lshr i64 %12, 1
  %14 = udiv i64 %9, %8
  %15 = mul i64 %14, %13
  %16 = add i64 %15, %.016
  %17 = urem i64 %9, %8
  store i64 %17, ptr %6, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %10, %7
  %19 = phi i64 [ %17, %10 ], [ %9, %7 ]
  %.117 = phi i64 [ %16, %10 ], [ %.016, %7 ]
  %.not26 = icmp ult i64 %.018, %8
  br i1 %.not26, label %25, label %20

20:                                               ; preds = %18
  %21 = udiv i64 %.018, %8
  %22 = mul i64 %21, %.015
  %23 = add i64 %22, %.117
  %24 = urem i64 %.018, %8
  br label %25

25:                                               ; preds = %20, %18
  %.119 = phi i64 [ %24, %20 ], [ %.018, %18 ]
  %.2 = phi i64 [ %23, %20 ], [ %.117, %18 ]
  %26 = mul i64 %19, %.015
  %27 = add i64 %26, %.119
  %28 = icmp ult i64 %27, %8
  br i1 %28, label %32, label %29

29:                                               ; preds = %25
  %30 = udiv i64 %27, %8
  %31 = urem i64 %27, %8
  call void @_ZSt4swapIyENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 8 dereferenceable(8) %6) #2
  %.pre = load i64, ptr %6, align 8, !tbaa !5
  %.pre31 = load i64, ptr %5, align 8, !tbaa !5
  br label %7

32:                                               ; preds = %25
  ret i64 %.2
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIyENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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 = { 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 long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass