; LLVM IR from tangjz/acm-icpc :: lydsy/2705.ll (Z3dfsix)

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

@sum = external dso_local global i32, align 4
@n = external dso_local global i64, align 8
@f = external dso_local global [40 x i64], align 16
@s = external dso_local global [40 x i64], align 16
@ans = external dso_local global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z3phix(i64 noundef) #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsix(i32 noundef %0, i64 noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = load i32, ptr @sum, align 4, !tbaa !5
  %8 = icmp sgt i32 %6, %7
  br i1 %8, label %9, label %18

9:                                                ; preds = %2
  %10 = load i64, ptr %4, align 8, !tbaa !9
  %11 = load i64, ptr @n, align 8, !tbaa !9
  %12 = load i64, ptr %4, align 8, !tbaa !9
  %13 = sdiv i64 %11, %12
  %14 = call noundef i64 @_Z3phix(i64 noundef %13)
  %15 = mul nsw i64 %10, %14
  %16 = load i64, ptr @ans, align 8, !tbaa !9
  %17 = add nsw i64 %16, %15
  store i64 %17, ptr @ans, align 8, !tbaa !9
  br label %43

18:                                               ; preds = %2
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  %21 = load i64, ptr %4, align 8, !tbaa !9
  call void @_Z3dfsix(i32 noundef %20, i64 noundef %21)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %40, %18
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [40 x i64], ptr @s, i64 0, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !9
  %29 = icmp sle i64 %24, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %43

31:                                               ; preds = %22
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [40 x i64], ptr @f, i64 0, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !9
  %38 = load i64, ptr %4, align 8, !tbaa !9
  %39 = mul nsw i64 %38, %37
  store i64 %39, ptr %4, align 8, !tbaa !9
  call void @_Z3dfsix(i32 noundef %33, i64 noundef %39)
  br label %40

40:                                               ; preds = %31
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %5, align 4, !tbaa !5
  br label %22, !llvm.loop !11

43:                                               ; preds = %30, %9
  ret void
}

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

@sum = external dso_local local_unnamed_addr global i32, align 4
@n = external dso_local local_unnamed_addr global i64, align 8
@f = external dso_local local_unnamed_addr global [40 x i64], align 16
@s = external dso_local local_unnamed_addr global [40 x i64], align 16
@ans = external dso_local local_unnamed_addr global i64, align 8

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3dfsix(i32 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @sum, align 4, !tbaa !5
  %4 = icmp slt i32 %3, %0
  br i1 %4, label %5, label %12

5:                                                ; preds = %2
  %6 = load i64, ptr @n, align 8, !tbaa !9
  %7 = sdiv i64 %6, %1
  %8 = tail call noundef i64 @_Z3phix(i64 noundef %7)
  %9 = mul nsw i64 %8, %1
  %10 = load i64, ptr @ans, align 8, !tbaa !9
  %11 = add nsw i64 %10, %9
  store i64 %11, ptr @ans, align 8, !tbaa !9
  br label %.loopexit

12:                                               ; preds = %2
  %13 = add nsw i32 %0, 1
  tail call void @_Z3dfsix(i32 noundef %13, i64 noundef %1)
  %14 = sext i32 %0 to i64
  %15 = getelementptr inbounds [40 x i64], ptr @s, i64 0, i64 %14
  %16 = load i64, ptr %15, align 8, !tbaa !9
  %.not13 = icmp slt i64 %16, 1
  br i1 %.not13, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %12
  %17 = getelementptr inbounds [40 x i64], ptr @f, i64 0, i64 %14
  br label %18

18:                                               ; preds = %.lr.ph, %18
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %18 ]
  %.01114 = phi i64 [ %1, %.lr.ph ], [ %20, %18 ]
  %19 = load i64, ptr %17, align 8, !tbaa !9
  %20 = mul nsw i64 %19, %.01114
  tail call void @_Z3dfsix(i32 noundef %13, i64 noundef %20)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %21 = load i64, ptr %15, align 8, !tbaa !9
  %.not.not = icmp sgt i64 %21, %indvars.iv
  br i1 %.not.not, label %18, label %.loopexit, !llvm.loop !11

.loopexit:                                        ; preds = %18, %12, %5
  ret void
}

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

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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