; LLVM IR from tangjz/acm-icpc :: lydsy (2045)

; 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
@m = external dso_local global i32, align 4
@d = external dso_local global i32, align 4
@lim = external dso_local global i32, align 4
@f = external dso_local global [1000001 x i64], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m, ptr noundef @d)
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = load i32, ptr @m, align 4, !tbaa !5
  %8 = icmp slt i32 %6, %7
  br i1 %8, label %9, label %11

9:                                                ; preds = %0
  %10 = load i32, ptr @n, align 4, !tbaa !5
  br label %13

11:                                               ; preds = %0
  %12 = load i32, ptr @m, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %11, %9
  %14 = phi i32 [ %10, %9 ], [ %12, %11 ]
  store i32 %14, ptr @lim, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  %15 = load i32, ptr @lim, align 4, !tbaa !5
  store i32 %15, ptr %2, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %56, %13
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = load i32, ptr @d, align 4, !tbaa !5
  %19 = icmp sge i32 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %59

21:                                               ; preds = %16
  %22 = load i32, ptr @n, align 4, !tbaa !5
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = sdiv i32 %22, %23
  %25 = sext i32 %24 to i64
  %26 = load i32, ptr @m, align 4, !tbaa !5
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = sdiv i32 %26, %27
  %29 = sext i32 %28 to i64
  %30 = mul nsw i64 %25, %29
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [1000001 x i64], ptr @f, i64 0, i64 %32
  store i64 %30, ptr %33, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = shl i32 %34, 1
  store i32 %35, ptr %4, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %51, %21
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = load i32, ptr @lim, align 4, !tbaa !5
  %39 = icmp sle i32 %37, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %36
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %55

41:                                               ; preds = %36
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [1000001 x i64], ptr @f, i64 0, i64 %43
  %45 = load i64, ptr %44, align 8, !tbaa !9
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [1000001 x i64], ptr @f, i64 0, i64 %47
  %49 = load i64, ptr %48, align 8, !tbaa !9
  %50 = sub nsw i64 %49, %45
  store i64 %50, ptr %48, align 8, !tbaa !9
  br label %51

51:                                               ; preds = %41
  %52 = load i32, ptr %2, align 4, !tbaa !5
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = add nsw i32 %53, %52
  store i32 %54, ptr %4, align 4, !tbaa !5
  br label %36, !llvm.loop !11

55:                                               ; preds = %40
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %2, align 4, !tbaa !5
  %58 = add nsw i32 %57, -1
  store i32 %58, ptr %2, align 4, !tbaa !5
  br label %16, !llvm.loop !13

59:                                               ; preds = %20
  %60 = load i32, ptr @d, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [1000001 x i64], ptr @f, i64 0, i64 %61
  %63 = load i64, ptr %62, align 8, !tbaa !9
  %64 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %63)
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #1

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

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

declare i32 @printf(ptr noundef, ...) #1

attributes #0 = { mustprogress norecurse 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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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"}
!13 = distinct !{!13, !12}


; 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 global i32, align 4
@m = external dso_local global i32, align 4
@d = external dso_local global i32, align 4
@lim = external dso_local local_unnamed_addr global i32, align 4
@f = external dso_local local_unnamed_addr global [1000001 x i64], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m, ptr noundef nonnull @d)
  %2 = load i32, ptr @n, align 4
  %3 = load i32, ptr @m, align 4
  %4 = tail call i32 @llvm.smin.i32(i32 %2, i32 %3)
  store i32 %4, ptr @lim, align 4, !tbaa !5
  %5 = load i32, ptr @d, align 4, !tbaa !5
  %.not16 = icmp slt i32 %4, %5
  br i1 %.not16, label %.._crit_edge20_crit_edge, label %.lr.ph19.preheader

.._crit_edge20_crit_edge:                         ; preds = %0
  %.pre = sext i32 %5 to i64
  br label %._crit_edge20

.lr.ph19.preheader:                               ; preds = %0
  %6 = shl i32 %4, 1
  %7 = tail call i32 @llvm.smin.i32(i32 %2, i32 %3)
  %smin = sext i32 %7 to i64
  %8 = sext i32 %4 to i64
  %9 = sext i32 %5 to i64
  br label %.lr.ph19

._crit_edge20:                                    ; preds = %._crit_edge, %.._crit_edge20_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.._crit_edge20_crit_edge ], [ %9, %._crit_edge ]
  %10 = getelementptr inbounds [1000001 x i64], ptr @f, i64 0, i64 %.pre-phi
  %11 = load i64, ptr %10, align 8, !tbaa !9
  %12 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %11)
  ret i32 0

.lr.ph19:                                         ; preds = %.lr.ph19.preheader, %._crit_edge
  %indvars.iv25 = phi i64 [ %8, %.lr.ph19.preheader ], [ %indvars.iv.next26, %._crit_edge ]
  %indvars.iv21 = phi i64 [ %smin, %.lr.ph19.preheader ], [ %indvars.iv.next22, %._crit_edge ]
  %indvars.iv = phi i32 [ %6, %.lr.ph19.preheader ], [ %indvars.iv.next, %._crit_edge ]
  %13 = trunc nsw i64 %indvars.iv25 to i32
  %14 = sdiv i32 %2, %13
  %15 = sext i32 %14 to i64
  %16 = sdiv i32 %3, %13
  %17 = sext i32 %16 to i64
  %18 = mul nsw i64 %17, %15
  %19 = getelementptr inbounds [1000001 x i64], ptr @f, i64 0, i64 %indvars.iv25
  store i64 %18, ptr %19, align 8, !tbaa !9
  %20 = shl i32 %13, 1
  %.not1314 = icmp sgt i32 %20, %4
  br i1 %.not1314, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph19
  %21 = sext i32 %indvars.iv to i64
  br label %22

._crit_edge:                                      ; preds = %22, %.lr.ph19
  %indvars.iv.next26 = add nsw i64 %indvars.iv25, -1
  %.not.not = icmp sgt i64 %indvars.iv25, %9
  %indvars.iv.next = add i32 %indvars.iv, -2
  %indvars.iv.next22 = add nsw i64 %indvars.iv21, -1
  br i1 %.not.not, label %.lr.ph19, label %._crit_edge20, !llvm.loop !11

22:                                               ; preds = %.lr.ph, %22
  %indvars.iv23 = phi i64 [ %21, %.lr.ph ], [ %indvars.iv.next24, %22 ]
  %23 = phi i64 [ %18, %.lr.ph ], [ %26, %22 ]
  %24 = getelementptr inbounds [1000001 x i64], ptr @f, i64 0, i64 %indvars.iv23
  %25 = load i64, ptr %24, align 8, !tbaa !9
  %26 = sub nsw i64 %23, %25
  store i64 %26, ptr %19, align 8, !tbaa !9
  %27 = add nsw i64 %indvars.iv23, %indvars.iv25
  %.not13 = icmp sgt i64 %27, %8
  %indvars.iv.next24 = add nsw i64 %indvars.iv23, %indvars.iv21
  br i1 %.not13, label %._crit_edge, label %22, !llvm.loop !13
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #2

attributes #0 = { mustprogress nofree norecurse 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 = { nofree nounwind "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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"}
!13 = distinct !{!13, !12}


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