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

; 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
@lim = external dso_local global i32, align 4
@f = external dso_local global [100001 x i64], align 16
@ans = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [5 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)
  %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 = %70, %13
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %20, label %19

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

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

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

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

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

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

54:                                               ; preds = %39
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %56
  %58 = load i64, ptr %57, align 8, !tbaa !9
  %59 = load i32, ptr %2, align 4, !tbaa !5
  %60 = shl i32 %59, 1
  %61 = sext i32 %60 to i64
  %62 = mul nsw i64 %58, %61
  %63 = load i32, ptr %2, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %64
  %66 = load i64, ptr %65, align 8, !tbaa !9
  %67 = sub nsw i64 %62, %66
  %68 = load i64, ptr @ans, align 8, !tbaa !9
  %69 = add nsw i64 %68, %67
  store i64 %69, ptr @ans, align 8, !tbaa !9
  br label %70

70:                                               ; preds = %54
  %71 = load i32, ptr %2, align 4, !tbaa !5
  %72 = add nsw i32 %71, -1
  store i32 %72, ptr %2, align 4, !tbaa !5
  br label %16, !llvm.loop !13

73:                                               ; preds = %19
  %74 = load i64, ptr @ans, align 8, !tbaa !9
  %75 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %74)
  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
@lim = external dso_local local_unnamed_addr global i32, align 4
@f = external dso_local local_unnamed_addr global [100001 x i64], align 16
@ans = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [5 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)
  %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
  %ans.promoted = load i64, ptr @ans, align 8, !tbaa !9
  %.not18 = icmp eq i32 %4, 0
  br i1 %.not18, label %8, label %.lr.ph21.preheader

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

._crit_edge22:                                    ; preds = %._crit_edge
  store i64 %25, ptr @ans, align 8, !tbaa !9
  br label %8

8:                                                ; preds = %._crit_edge22, %0
  %9 = phi i64 [ %25, %._crit_edge22 ], [ %ans.promoted, %0 ]
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %9)
  ret i32 0

.lr.ph21:                                         ; preds = %.lr.ph21.preheader, %._crit_edge
  %indvars.iv27 = phi i64 [ %7, %.lr.ph21.preheader ], [ %indvars.iv.next28, %._crit_edge ]
  %indvars.iv23 = phi i64 [ %smin, %.lr.ph21.preheader ], [ %indvars.iv.next24, %._crit_edge ]
  %indvars.iv = phi i32 [ %5, %.lr.ph21.preheader ], [ %indvars.iv.next, %._crit_edge ]
  %11 = phi i64 [ %ans.promoted, %.lr.ph21.preheader ], [ %25, %._crit_edge ]
  %12 = trunc nsw i64 %indvars.iv27 to i32
  %13 = sdiv i32 %2, %12
  %14 = sext i32 %13 to i64
  %15 = sdiv i32 %3, %12
  %16 = sext i32 %15 to i64
  %17 = mul nsw i64 %16, %14
  %18 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %indvars.iv27
  store i64 %17, ptr %18, align 8, !tbaa !9
  %19 = shl i32 %12, 1
  %.not1516 = icmp sgt i32 %19, %4
  br i1 %.not1516, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph21
  %20 = sext i32 %indvars.iv to i64
  br label %26

._crit_edge:                                      ; preds = %26, %.lr.ph21
  %21 = phi i64 [ %17, %.lr.ph21 ], [ %30, %26 ]
  %22 = sext i32 %19 to i64
  %23 = add nsw i64 %22, -1
  %24 = mul i64 %21, %23
  %25 = add nsw i64 %11, %24
  %indvars.iv.next28 = add nsw i64 %indvars.iv27, -1
  %.not = icmp eq i64 %indvars.iv.next28, 0
  %indvars.iv.next = add i32 %indvars.iv, -2
  %indvars.iv.next24 = add nsw i64 %indvars.iv23, -1
  br i1 %.not, label %._crit_edge22, label %.lr.ph21, !llvm.loop !11

26:                                               ; preds = %.lr.ph, %26
  %indvars.iv25 = phi i64 [ %20, %.lr.ph ], [ %indvars.iv.next26, %26 ]
  %27 = phi i64 [ %17, %.lr.ph ], [ %30, %26 ]
  %28 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %indvars.iv25
  %29 = load i64, ptr %28, align 8, !tbaa !9
  %30 = sub nsw i64 %27, %29
  store i64 %30, ptr %18, align 8, !tbaa !9
  %31 = add nsw i64 %indvars.iv25, %indvars.iv27
  %.not15 = icmp sgt i64 %31, %7
  %indvars.iv.next26 = add nsw i64 %indvars.iv25, %indvars.iv23
  br i1 %.not15, label %._crit_edge, label %26, !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,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass