; LLVM IR from tangjz/acm-icpc :: self_training/2015-02-16 (K)

; 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
@w = external dso_local global [101 x i32], align 16
@f = external dso_local global [101 x i32], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = 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
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  br label %6

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

9:                                                ; preds = %6
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = load i32, ptr @m, align 4, !tbaa !5
  %12 = add nsw i32 %10, %11
  %13 = icmp ne i32 %12, 0
  br label %14

14:                                               ; preds = %9, %6
  %15 = phi i1 [ false, %6 ], [ %13, %9 ]
  br i1 %15, label %16, label %100

16:                                               ; preds = %14
  call void @llvm.memset.p0.i64(ptr align 16 @f, i8 0, i64 404, i1 false)
  br label %17

17:                                               ; preds = %93, %16
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = add nsw i32 %18, -1
  store i32 %19, ptr @n, align 4, !tbaa !5
  %20 = icmp ne i32 %18, 0
  br i1 %20, label %21, label %94

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

22:                                               ; preds = %32, %21
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = load i32, ptr @m, align 4, !tbaa !5
  %25 = icmp sle i32 %23, %24
  br i1 %25, label %27, label %26

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

27:                                               ; preds = %22
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i32, ptr @w, i64 %29
  %31 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %30)
  br label %32

32:                                               ; preds = %27
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %2, align 4, !tbaa !5
  br label %22, !llvm.loop !9

35:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %36 = load i32, ptr @m, align 4, !tbaa !5
  store i32 %36, ptr %3, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %90, %35
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = icmp sgt i32 %38, 0
  br i1 %39, label %41, label %40

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

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

42:                                               ; preds = %86, %41
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = load i32, ptr @m, align 4, !tbaa !5
  %45 = icmp sle i32 %43, %44
  br i1 %45, label %46, label %50

46:                                               ; preds = %42
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = icmp sle i32 %47, %48
  br label %50

50:                                               ; preds = %46, %42
  %51 = phi i1 [ false, %42 ], [ %49, %46 ]
  br i1 %51, label %53, label %52

52:                                               ; preds = %50
  store i32 12, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %89

53:                                               ; preds = %50
  %54 = load i32, ptr %3, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [101 x i32], ptr @f, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = load i32, ptr %5, align 4, !tbaa !5
  %60 = sub nsw i32 %58, %59
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [101 x i32], ptr @f, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = load i32, ptr %5, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [101 x i32], ptr @w, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !5
  %68 = add nsw i32 %63, %67
  %69 = icmp slt i32 %57, %68
  br i1 %69, label %70, label %85

70:                                               ; preds = %53
  %71 = load i32, ptr %3, align 4, !tbaa !5
  %72 = load i32, ptr %5, align 4, !tbaa !5
  %73 = sub nsw i32 %71, %72
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [101 x i32], ptr @f, i64 0, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = load i32, ptr %5, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [101 x i32], ptr @w, i64 0, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !5
  %81 = add nsw i32 %76, %80
  %82 = load i32, ptr %3, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [101 x i32], ptr @f, i64 0, i64 %83
  store i32 %81, ptr %84, align 4, !tbaa !5
  br label %85

85:                                               ; preds = %70, %53
  br label %86

86:                                               ; preds = %85
  %87 = load i32, ptr %5, align 4, !tbaa !5
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %5, align 4, !tbaa !5
  br label %42, !llvm.loop !11

89:                                               ; preds = %52
  br label %90

90:                                               ; preds = %89
  %91 = load i32, ptr %3, align 4, !tbaa !5
  %92 = add nsw i32 %91, -1
  store i32 %92, ptr %3, align 4, !tbaa !5
  br label %37, !llvm.loop !12

93:                                               ; preds = %40
  br label %17, !llvm.loop !13

94:                                               ; preds = %17
  %95 = load i32, ptr @m, align 4, !tbaa !5
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [101 x i32], ptr @f, i64 0, i64 %96
  %98 = load i32, ptr %97, align 4, !tbaa !5
  %99 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %98)
  br label %6, !llvm.loop !14

100:                                              ; preds = %14
  ret i32 0
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

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

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 nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !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
@w = external dso_local global [101 x i32], align 16
@f = external dso_local local_unnamed_addr global [101 x i32], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = 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
  %3 = load i32, ptr @n, align 4
  %4 = load i32, ptr @m, align 4
  %5 = sub i32 0, %4
  %6 = icmp ne i32 %3, %5
  %7 = select i1 %2, i1 %6, i1 false
  br i1 %7, label %.lr.ph33, label %._crit_edge34

.lr.ph33:                                         ; preds = %0, %._crit_edge30
  %8 = phi i32 [ %66, %._crit_edge30 ], [ %4, %0 ]
  %9 = phi i32 [ %65, %._crit_edge30 ], [ %3, %0 ]
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(404) @f, i8 0, i64 404, i1 false)
  %10 = add nsw i32 %9, -1
  store i32 %10, ptr @n, align 4, !tbaa !5
  %.not29 = icmp eq i32 %9, 0
  br i1 %.not29, label %._crit_edge30, label %.preheader23.lr.ph

.preheader23.lr.ph:                               ; preds = %.lr.ph33
  %11 = icmp slt i32 %8, 1
  br i1 %11, label %._crit_edge30.split.us, label %.preheader23

._crit_edge30.split.us:                           ; preds = %.preheader23.lr.ph
  store i32 -1, ptr @n, align 4, !tbaa !5
  br label %._crit_edge30

.loopexit:                                        ; preds = %._crit_edge, %.preheader23, %.preheader22
  %12 = phi i32 [ %21, %.preheader22 ], [ %15, %.preheader23 ], [ %21, %._crit_edge ]
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = add nsw i32 %13, -1
  store i32 %14, ptr @n, align 4, !tbaa !5
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %._crit_edge30, label %.preheader23, !llvm.loop !9

.preheader23:                                     ; preds = %.preheader23.lr.ph, %.loopexit
  %15 = phi i32 [ %12, %.loopexit ], [ %8, %.preheader23.lr.ph ]
  %.not2124 = icmp slt i32 %15, 1
  br i1 %.not2124, label %.loopexit, label %.lr.ph

.preheader22:                                     ; preds = %.lr.ph
  %16 = icmp sgt i32 %21, 0
  br i1 %16, label %.preheader.preheader, label %.loopexit

.preheader.preheader:                             ; preds = %.preheader22
  %17 = zext nneg i32 %21 to i64
  %18 = zext nneg i32 %21 to i64
  br label %.lr.ph27

.lr.ph:                                           ; preds = %.preheader23, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %.preheader23 ]
  %19 = getelementptr inbounds i32, ptr @w, i64 %indvars.iv
  %20 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %19)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %21 = load i32, ptr @m, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %.not21.not = icmp slt i64 %indvars.iv, %22
  br i1 %.not21.not, label %.lr.ph, label %.preheader22, !llvm.loop !12

.lr.ph27:                                         ; preds = %._crit_edge, %.preheader.preheader
  %indvar = phi i32 [ %indvar.next, %._crit_edge ], [ 0, %.preheader.preheader ]
  %indvars.iv45 = phi i64 [ %indvars.iv.next46, %._crit_edge ], [ %17, %.preheader.preheader ]
  %23 = sub i32 %21, %indvar
  %24 = sext i32 %23 to i64
  %smin = tail call i64 @llvm.smin.i64(i64 %18, i64 %24)
  %smax = tail call i64 @llvm.smax.i64(i64 %smin, i64 1)
  %25 = getelementptr inbounds [101 x i32], ptr @f, i64 0, i64 %indvars.iv45
  %.promoted = load i32, ptr %25, align 4, !tbaa !5
  %xtraiter = and i64 %smax, 1
  %26 = icmp slt i64 %smin, 2
  br i1 %26, label %._crit_edge.unr-lcssa, label %.lr.ph27.new

.lr.ph27.new:                                     ; preds = %.lr.ph27
  %unroll_iter = and i64 %smax, 9223372036854775806
  br label %36

._crit_edge.unr-lcssa:                            ; preds = %56, %.lr.ph27
  %indvars.iv42.unr = phi i64 [ 1, %.lr.ph27 ], [ %indvars.iv.next43.1, %56 ]
  %.unr = phi i32 [ %.promoted, %.lr.ph27 ], [ %57, %56 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.unr-lcssa
  %27 = sub nsw i64 %indvars.iv45, %indvars.iv42.unr
  %28 = getelementptr inbounds [101 x i32], ptr @f, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = getelementptr inbounds [101 x i32], ptr @w, i64 0, i64 %indvars.iv42.unr
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = add nsw i32 %31, %29
  %33 = icmp slt i32 %.unr, %32
  br i1 %33, label %34, label %._crit_edge

34:                                               ; preds = %.epil.preheader
  store i32 %32, ptr %25, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %.epil.preheader, %34, %._crit_edge.unr-lcssa
  %indvars.iv.next46 = add nsw i64 %indvars.iv45, -1
  %35 = icmp sgt i64 %indvars.iv45, 1
  %indvar.next = add i32 %indvar, 1
  br i1 %35, label %.lr.ph27, label %.loopexit, !llvm.loop !13

36:                                               ; preds = %56, %.lr.ph27.new
  %indvars.iv42 = phi i64 [ 1, %.lr.ph27.new ], [ %indvars.iv.next43.1, %56 ]
  %37 = phi i32 [ %.promoted, %.lr.ph27.new ], [ %57, %56 ]
  %niter = phi i64 [ 0, %.lr.ph27.new ], [ %niter.next.1, %56 ]
  %38 = sub nsw i64 %indvars.iv45, %indvars.iv42
  %39 = getelementptr inbounds [101 x i32], ptr @f, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = getelementptr inbounds [101 x i32], ptr @w, i64 0, i64 %indvars.iv42
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = add nsw i32 %42, %40
  %44 = icmp slt i32 %37, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %36
  store i32 %43, ptr %25, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %36, %45
  %47 = phi i32 [ %37, %36 ], [ %43, %45 ]
  %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1
  %48 = sub nsw i64 %indvars.iv45, %indvars.iv.next43
  %49 = getelementptr inbounds [101 x i32], ptr @f, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = getelementptr inbounds [101 x i32], ptr @w, i64 0, i64 %indvars.iv.next43
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = add nsw i32 %52, %50
  %54 = icmp slt i32 %47, %53
  br i1 %54, label %55, label %56

55:                                               ; preds = %46
  store i32 %53, ptr %25, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %55, %46
  %57 = phi i32 [ %47, %46 ], [ %53, %55 ]
  %indvars.iv.next43.1 = add nuw nsw i64 %indvars.iv42, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1.not = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1.not, label %._crit_edge.unr-lcssa, label %36, !llvm.loop !14

._crit_edge30:                                    ; preds = %.loopexit, %._crit_edge30.split.us, %.lr.ph33
  %58 = phi i32 [ %8, %._crit_edge30.split.us ], [ %8, %.lr.ph33 ], [ %12, %.loopexit ]
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [101 x i32], ptr @f, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %61)
  %63 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %64 = icmp eq i32 %63, 2
  %65 = load i32, ptr @n, align 4
  %66 = load i32, ptr @m, align 4
  %67 = sub i32 0, %66
  %68 = icmp ne i32 %65, %67
  %69 = select i1 %64, i1 %68, i1 false
  br i1 %69, label %.lr.ph33, label %._crit_edge34, !llvm.loop !15

._crit_edge34:                                    ; preds = %._crit_edge30, %0
  ret i32 0
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; 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 i64 @llvm.smin.i64(i64, i64) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #3

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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, !11}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.unswitch.partial.disable"}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass