; LLVM IR from tangjz/acm-icpc :: 51nod/1040.ll (Z3dfsiii)

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

@n = external dso_local global i32, align 4
@cnt = external dso_local global i32, align 4
@s = external dso_local global [10 x i32], align 16
@c = external dso_local global [10 x i32], align 16
@ans = external dso_local global i64, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = load i32, ptr @cnt, align 4, !tbaa !5
  %11 = icmp eq i32 %9, %10
  br i1 %11, label %12, label %21

12:                                               ; preds = %3
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = sdiv i32 %13, %14
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = mul nsw i32 %15, %16
  %18 = sext i32 %17 to i64
  %19 = load i64, ptr @ans, align 8, !tbaa !9
  %20 = add nsw i64 %19, %18
  store i64 %20, ptr @ans, align 8, !tbaa !9
  br label %55

21:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 1, ptr %8, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %46, %21
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [10 x i32], ptr @c, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = icmp sle i32 %23, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %55

30:                                               ; preds = %22
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = load i32, ptr %8, align 4, !tbaa !5
  %35 = mul nsw i32 %33, %34
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = load i32, ptr %8, align 4, !tbaa !5
  %38 = load i32, ptr %8, align 4, !tbaa !5
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [10 x i32], ptr @s, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = sdiv i32 %38, %42
  %44 = sub nsw i32 %37, %43
  %45 = mul nsw i32 %36, %44
  call void @_Z3dfsiii(i32 noundef %32, i32 noundef %35, i32 noundef %45)
  br label %46

46:                                               ; preds = %30
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %7, align 4, !tbaa !5
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [10 x i32], ptr @s, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = load i32, ptr %8, align 4, !tbaa !5
  %54 = mul nsw i32 %53, %52
  store i32 %54, ptr %8, align 4, !tbaa !5
  br label %22, !llvm.loop !11

55:                                               ; preds = %29, %12
  ret void
}

; 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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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"

@n = external dso_local local_unnamed_addr global i32, align 4
@cnt = external dso_local local_unnamed_addr global i32, align 4
@s = external dso_local local_unnamed_addr global [10 x i32], align 16
@c = external dso_local local_unnamed_addr global [10 x i32], align 16
@ans = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3dfsiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = load i32, ptr @cnt, align 4, !tbaa !5
  %5 = icmp eq i32 %4, %0
  br i1 %5, label %11, label %.preheader

.preheader:                                       ; preds = %3
  %6 = sext i32 %0 to i64
  %7 = getelementptr inbounds [10 x i32], ptr @c, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %.not17 = icmp slt i32 %8, 0
  br i1 %.not17, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %9 = add nsw i32 %0, 1
  %10 = getelementptr inbounds [10 x i32], ptr @s, i64 0, i64 %6
  %.pre = load i32, ptr %10, align 4, !tbaa !5
  br label %18

11:                                               ; preds = %3
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = sdiv i32 %12, %1
  %14 = mul nsw i32 %13, %2
  %15 = sext i32 %14 to i64
  %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 %.loopexit

18:                                               ; preds = %.lr.ph, %18
  %19 = phi i32 [ %.pre, %.lr.ph ], [ %25, %18 ]
  %.019 = phi i32 [ 1, %.lr.ph ], [ %26, %18 ]
  %.01518 = phi i32 [ 0, %.lr.ph ], [ %24, %18 ]
  %20 = mul nsw i32 %.019, %1
  %21 = sdiv i32 %.019, %19
  %22 = sub nsw i32 %.019, %21
  %23 = mul nsw i32 %22, %2
  tail call void @_Z3dfsiii(i32 noundef %9, i32 noundef %20, i32 noundef %23)
  %24 = add nuw nsw i32 %.01518, 1
  %25 = load i32, ptr %10, align 4, !tbaa !5
  %26 = mul nsw i32 %25, %.019
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.01518, %27
  br i1 %.not.not, label %18, label %.loopexit, !llvm.loop !11

.loopexit:                                        ; preds = %18, %.preheader, %11
  ret void
}

attributes #0 = { mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass