; LLVM IR from tangjz/acm-icpc :: hdu (5190)

; 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
@a = external dso_local global [110 x i32], align 16
@b = external dso_local global [110 x i32], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 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
  br label %5

5:                                                ; preds = %65, %0
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  %7 = icmp eq i32 %6, 2
  br i1 %7, label %8, label %68

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

9:                                                ; preds = %22, %8
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = load i32, ptr @m, align 4, !tbaa !5
  %12 = icmp sle i32 %10, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %25

14:                                               ; preds = %9
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds i32, ptr @a, i64 %16
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i32, ptr @b, i64 %19
  %21 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %17, ptr noundef %20)
  br label %22

22:                                               ; preds = %14
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %2, align 4, !tbaa !5
  br label %9, !llvm.loop !9

25:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 1061109567, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %62, %25
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = load i32, ptr @m, align 4, !tbaa !5
  %29 = icmp sle i32 %27, %28
  br i1 %29, label %31, label %30

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

31:                                               ; preds = %26
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = load i32, ptr @n, align 4, !tbaa !5
  %34 = sub nsw i32 %33, 1
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [110 x i32], ptr @a, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = sdiv i32 %34, %38
  %40 = add nsw i32 %39, 1
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [110 x i32], ptr @b, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = mul nsw i32 %40, %44
  %46 = icmp sgt i32 %32, %45
  br i1 %46, label %47, label %61

47:                                               ; preds = %31
  %48 = load i32, ptr @n, align 4, !tbaa !5
  %49 = sub nsw i32 %48, 1
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [110 x i32], ptr @a, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = sdiv i32 %49, %53
  %55 = add nsw i32 %54, 1
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [110 x i32], ptr @b, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = mul nsw i32 %55, %59
  store i32 %60, ptr %3, align 4, !tbaa !5
  br label %61

61:                                               ; preds = %47, %31
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %4, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %4, align 4, !tbaa !5
  br label %26, !llvm.loop !11

65:                                               ; preds = %30
  %66 = load i32, ptr %3, align 4, !tbaa !5
  %67 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %66)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %5, !llvm.loop !12

68:                                               ; preds = %5
  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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; 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
@a = external dso_local global [110 x i32], align 16
@b = external dso_local global [110 x i32], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 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 = icmp eq i32 %1, 2
  br i1 %2, label %.preheader16, label %._crit_edge24

.preheader16:                                     ; preds = %0, %._crit_edge
  %3 = load i32, ptr @m, align 4, !tbaa !5
  %.not17 = icmp slt i32 %3, 1
  br i1 %.not17, label %._crit_edge, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph
  %.not1519 = icmp slt i32 %11, 1
  br i1 %.not1519, label %._crit_edge, label %.lr.ph22

.lr.ph22:                                         ; preds = %.preheader
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = add nsw i32 %4, -1
  %6 = zext nneg i32 %11 to i64
  %xtraiter = and i64 %6, 1
  %7 = icmp eq i32 %11, 1
  br i1 %7, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph22.new

.lr.ph22.new:                                     ; preds = %.lr.ph22
  %unroll_iter = and i64 %6, 2147483646
  br label %23

.lr.ph:                                           ; preds = %.preheader16, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %.preheader16 ]
  %8 = getelementptr inbounds i32, ptr @a, i64 %indvars.iv
  %9 = getelementptr inbounds i32, ptr @b, i64 %indvars.iv
  %10 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %8, ptr noundef nonnull %9)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %11 = load i32, ptr @m, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %.not.not = icmp slt i64 %indvars.iv, %12
  br i1 %.not.not, label %.lr.ph, label %.preheader, !llvm.loop !9

._crit_edge.loopexit.unr-lcssa:                   ; preds = %23, %.lr.ph22
  %spec.select.lcssa.ph = phi i32 [ poison, %.lr.ph22 ], [ %spec.select.1, %23 ]
  %indvars.iv27.unr = phi i64 [ 1, %.lr.ph22 ], [ %indvars.iv.next28.1, %23 ]
  %.01220.unr = phi i32 [ 1061109567, %.lr.ph22 ], [ %spec.select.1, %23 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %13 = getelementptr inbounds [110 x i32], ptr @a, i64 0, i64 %indvars.iv27.unr
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = sdiv i32 %5, %14
  %16 = add nsw i32 %15, 1
  %17 = getelementptr inbounds [110 x i32], ptr @b, i64 0, i64 %indvars.iv27.unr
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = mul nsw i32 %16, %18
  %spec.select.epil = tail call i32 @llvm.smin.i32(i32 %.01220.unr, i32 %19)
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %.preheader16, %.preheader
  %.012.lcssa = phi i32 [ 1061109567, %.preheader ], [ 1061109567, %.preheader16 ], [ %spec.select.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %spec.select.epil, %._crit_edge.loopexit.epilog-lcssa ]
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.012.lcssa)
  %21 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %22 = icmp eq i32 %21, 2
  br i1 %22, label %.preheader16, label %._crit_edge24, !llvm.loop !11

23:                                               ; preds = %23, %.lr.ph22.new
  %indvars.iv27 = phi i64 [ 1, %.lr.ph22.new ], [ %indvars.iv.next28.1, %23 ]
  %.01220 = phi i32 [ 1061109567, %.lr.ph22.new ], [ %spec.select.1, %23 ]
  %niter = phi i64 [ 0, %.lr.ph22.new ], [ %niter.next.1, %23 ]
  %24 = getelementptr inbounds [110 x i32], ptr @a, i64 0, i64 %indvars.iv27
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = sdiv i32 %5, %25
  %27 = add nsw i32 %26, 1
  %28 = getelementptr inbounds [110 x i32], ptr @b, i64 0, i64 %indvars.iv27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = mul nsw i32 %27, %29
  %spec.select = tail call i32 @llvm.smin.i32(i32 %.01220, i32 %30)
  %indvars.iv.next28 = add nuw nsw i64 %indvars.iv27, 1
  %31 = getelementptr inbounds [110 x i32], ptr @a, i64 0, i64 %indvars.iv.next28
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = sdiv i32 %5, %32
  %34 = add nsw i32 %33, 1
  %35 = getelementptr inbounds [110 x i32], ptr @b, i64 0, i64 %indvars.iv.next28
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = mul nsw i32 %34, %36
  %spec.select.1 = tail call i32 @llvm.smin.i32(i32 %spec.select, i32 %37)
  %indvars.iv.next28.1 = add nuw nsw i64 %indvars.iv27, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %23, !llvm.loop !12

._crit_edge24:                                    ; preds = %._crit_edge, %0
  ret i32 0
}

; 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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