; LLVM IR from tangjz/acm-icpc :: self_training/2015-09-22 (F)

; 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
@tot = external dso_local global i32, align 4
@seq = external dso_local global [100010 x i32], align 16
@ans = external dso_local global i32, align 4
@.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
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  br label %7

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

10:                                               ; preds = %7
  store i32 0, ptr @ans, align 4, !tbaa !5
  store i32 0, ptr @tot, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %49, %10
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %52

16:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3, ptr noundef %4)
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %21, label %29

21:                                               ; preds = %16
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = sub nsw i32 %22, %23
  %25 = load i32, ptr @tot, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr @tot, align 4, !tbaa !5
  %27 = sext i32 %25 to i64
  %28 = getelementptr inbounds [100010 x i32], ptr @seq, i64 0, i64 %27
  store i32 %24, ptr %28, align 4, !tbaa !5
  br label %48

29:                                               ; preds = %16
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = icmp eq i32 %30, %31
  br i1 %32, label %33, label %44

33:                                               ; preds = %29
  %34 = load i32, ptr @ans, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr @ans, align 4, !tbaa !5
  %36 = load i32, ptr @m, align 4, !tbaa !5
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %43

38:                                               ; preds = %33
  %39 = load i32, ptr @m, align 4, !tbaa !5
  %40 = add nsw i32 %39, -1
  store i32 %40, ptr @m, align 4, !tbaa !5
  %41 = load i32, ptr @ans, align 4, !tbaa !5
  %42 = add nsw i32 %41, 2
  store i32 %42, ptr @ans, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %38, %33
  br label %47

44:                                               ; preds = %29
  %45 = load i32, ptr @ans, align 4, !tbaa !5
  %46 = add nsw i32 %45, 3
  store i32 %46, ptr @ans, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %44, %43
  br label %48

48:                                               ; preds = %47, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %2, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %2, align 4, !tbaa !5
  br label %11, !llvm.loop !9

52:                                               ; preds = %15
  %53 = load i32, ptr @tot, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i32, ptr @seq, i64 %54
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef @seq, ptr noundef %55)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %87, %52
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = load i32, ptr @tot, align 4, !tbaa !5
  %59 = icmp slt i32 %57, %58
  br i1 %59, label %61, label %60

60:                                               ; preds = %56
  store i32 7, ptr %6, align 4
  br label %90

61:                                               ; preds = %56
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [100010 x i32], ptr @seq, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = load i32, ptr @m, align 4, !tbaa !5
  %67 = icmp sle i32 %65, %66
  br i1 %67, label %68, label %85

68:                                               ; preds = %61
  %69 = load i32, ptr %5, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [100010 x i32], ptr @seq, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = load i32, ptr @m, align 4, !tbaa !5
  %74 = sub nsw i32 %73, %72
  store i32 %74, ptr @m, align 4, !tbaa !5
  %75 = load i32, ptr @ans, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr @ans, align 4, !tbaa !5
  %77 = load i32, ptr @m, align 4, !tbaa !5
  %78 = icmp ne i32 %77, 0
  br i1 %78, label %79, label %84

79:                                               ; preds = %68
  %80 = load i32, ptr @m, align 4, !tbaa !5
  %81 = add nsw i32 %80, -1
  store i32 %81, ptr @m, align 4, !tbaa !5
  %82 = load i32, ptr @ans, align 4, !tbaa !5
  %83 = add nsw i32 %82, 2
  store i32 %83, ptr @ans, align 4, !tbaa !5
  br label %84

84:                                               ; preds = %79, %68
  br label %86

85:                                               ; preds = %61
  store i32 7, ptr %6, align 4
  br label %90

86:                                               ; preds = %84
  br label %87

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

90:                                               ; preds = %85, %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %91

91:                                               ; preds = %90
  %92 = load i32, ptr @ans, align 4, !tbaa !5
  %93 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %92)
  br label %7, !llvm.loop !12

94:                                               ; preds = %7
  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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr noundef) #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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #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}


; 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
@tot = external dso_local local_unnamed_addr global i32, align 4
@seq = external dso_local global [100010 x i32], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4
@.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() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %4 = icmp eq i32 %3, 2
  br i1 %4, label %.lr.ph23, label %._crit_edge24

.lr.ph23:                                         ; preds = %0, %._crit_edge20
  store i32 0, ptr @ans, align 4, !tbaa !5
  store i32 0, ptr @tot, align 4, !tbaa !5
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

._crit_edge.loopexit:                             ; preds = %33
  %.pre = load i32, ptr @tot, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph23
  %7 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ 0, %.lr.ph23 ]
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds i32, ptr @seq, i64 %8
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @seq, ptr noundef nonnull %9)
  %10 = load i32, ptr @tot, align 4, !tbaa !5
  %ans.promoted = load i32, ptr @ans, align 4, !tbaa !5
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.lr.ph19.preheader, label %._crit_edge20

.lr.ph19.preheader:                               ; preds = %._crit_edge
  %m.promoted = load i32, ptr @m, align 4, !tbaa !5
  %wide.trip.count = zext nneg i32 %10 to i64
  br label %.lr.ph19

.lr.ph:                                           ; preds = %.lr.ph23, %33
  %.0616 = phi i32 [ %34, %33 ], [ 0, %.lr.ph23 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %16, label %22

16:                                               ; preds = %.lr.ph
  %17 = sub nsw i32 %14, %13
  %18 = load i32, ptr @tot, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr @tot, align 4, !tbaa !5
  %20 = sext i32 %18 to i64
  %21 = getelementptr inbounds [100010 x i32], ptr @seq, i64 0, i64 %20
  store i32 %17, ptr %21, align 4, !tbaa !5
  br label %33

22:                                               ; preds = %.lr.ph
  %23 = icmp eq i32 %13, %14
  %24 = load i32, ptr @ans, align 4, !tbaa !5
  br i1 %23, label %25, label %31

25:                                               ; preds = %22
  %26 = add nsw i32 %24, 1
  store i32 %26, ptr @ans, align 4, !tbaa !5
  %27 = load i32, ptr @m, align 4, !tbaa !5
  %.not15 = icmp eq i32 %27, 0
  br i1 %.not15, label %33, label %28

28:                                               ; preds = %25
  %29 = add nsw i32 %27, -1
  store i32 %29, ptr @m, align 4, !tbaa !5
  %30 = add nsw i32 %24, 3
  store i32 %30, ptr @ans, align 4, !tbaa !5
  br label %33

31:                                               ; preds = %22
  %32 = add nsw i32 %24, 3
  store i32 %32, ptr @ans, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %31, %28, %25, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  %34 = add nuw nsw i32 %.0616, 1
  %35 = load i32, ptr @n, align 4, !tbaa !5
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !9

.lr.ph19:                                         ; preds = %.lr.ph19.preheader, %47
  %indvars.iv = phi i64 [ 0, %.lr.ph19.preheader ], [ %indvars.iv.next, %47 ]
  %37 = phi i32 [ %m.promoted, %.lr.ph19.preheader ], [ %49, %47 ]
  %38 = phi i32 [ %ans.promoted, %.lr.ph19.preheader ], [ %48, %47 ]
  %39 = getelementptr inbounds [100010 x i32], ptr @seq, i64 0, i64 %indvars.iv
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %.not = icmp sgt i32 %40, %37
  br i1 %.not, label %._crit_edge20, label %41

41:                                               ; preds = %.lr.ph19
  %42 = sub nsw i32 %37, %40
  store i32 %42, ptr @m, align 4, !tbaa !5
  %43 = add nsw i32 %38, 1
  store i32 %43, ptr @ans, align 4, !tbaa !5
  %.not14 = icmp eq i32 %37, %40
  br i1 %.not14, label %47, label %44

44:                                               ; preds = %41
  %45 = add nsw i32 %42, -1
  store i32 %45, ptr @m, align 4, !tbaa !5
  %46 = add nsw i32 %38, 3
  store i32 %46, ptr @ans, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %44, %41
  %48 = phi i32 [ %46, %44 ], [ %43, %41 ]
  %49 = phi i32 [ %45, %44 ], [ %42, %41 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge20, label %.lr.ph19, !llvm.loop !11

._crit_edge20:                                    ; preds = %47, %.lr.ph19, %._crit_edge
  %50 = phi i32 [ %ans.promoted, %._crit_edge ], [ %48, %47 ], [ %38, %.lr.ph19 ]
  %51 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %50)
  %52 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %53 = icmp eq i32 %52, 2
  br i1 %53, label %.lr.ph23, label %._crit_edge24, !llvm.loop !12

._crit_edge24:                                    ; preds = %._crit_edge20, %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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { 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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #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}


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