; LLVM IR from tangjz/acm-icpc :: codeforces/complete (755D)

; 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
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3addii(i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3sumi(i32 noundef) #0

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %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
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  %8 = load i32, ptr @m, align 4, !tbaa !5
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = load i32, ptr @m, align 4, !tbaa !5
  %11 = sub nsw i32 %9, %10
  %12 = icmp sgt i32 %8, %11
  br i1 %12, label %13, label %17

13:                                               ; preds = %0
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = load i32, ptr @m, align 4, !tbaa !5
  %16 = sub nsw i32 %14, %15
  store i32 %16, ptr @m, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %13, %0
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  store i64 1, ptr %2, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 1, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = load i32, ptr @m, align 4, !tbaa !5
  %20 = add nsw i32 %18, %19
  store i32 %20, ptr %5, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %77, %17
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %24 = icmp sle i32 %22, %23
  br i1 %24, label %26, label %25

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

26:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = load i32, ptr @m, align 4, !tbaa !5
  %29 = add nsw i32 %27, %28
  %30 = sub nsw i32 %29, 1
  store i32 %30, ptr %6, align 4, !tbaa !5
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = load i32, ptr @n, align 4, !tbaa !5
  %33 = icmp sgt i32 %31, %32
  br i1 %33, label %34, label %38

34:                                               ; preds = %26
  %35 = load i32, ptr @n, align 4, !tbaa !5
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = sub nsw i32 %36, %35
  store i32 %37, ptr %6, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %34, %26
  %39 = load i32, ptr %6, align 4, !tbaa !5
  %40 = call noundef i32 @_Z3sumi(i32 noundef %39)
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = call noundef i32 @_Z3sumi(i32 noundef %41)
  %43 = sub nsw i32 %40, %42
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = icmp slt i32 %44, %45
  br i1 %46, label %47, label %48

47:                                               ; preds = %38
  br label %50

48:                                               ; preds = %38
  %49 = load i32, ptr %3, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %48, %47
  %51 = phi i32 [ 1, %47 ], [ %49, %48 ]
  %52 = add nsw i32 %43, %51
  %53 = sext i32 %52 to i64
  %54 = load i64, ptr %2, align 8, !tbaa !9
  %55 = add nsw i64 %54, %53
  store i64 %55, ptr %2, align 8, !tbaa !9
  %56 = load i64, ptr %2, align 8, !tbaa !9
  %57 = load i32, ptr %3, align 4, !tbaa !5
  %58 = load i32, ptr @n, align 4, !tbaa !5
  %59 = icmp eq i32 %57, %58
  %60 = zext i1 %59 to i64
  %61 = getelementptr inbounds [3 x i8], ptr @.str.2, i64 0, i64 %60
  %62 = load i8, ptr %61, align 1, !tbaa !11
  %63 = sext i8 %62 to i32
  %64 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %56, i32 noundef %63)
  %65 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z3addii(i32 noundef %65, i32 noundef 1)
  %66 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %66, ptr %4, align 4, !tbaa !5
  %67 = load i32, ptr @m, align 4, !tbaa !5
  %68 = load i32, ptr %5, align 4, !tbaa !5
  %69 = add nsw i32 %68, %67
  store i32 %69, ptr %5, align 4, !tbaa !5
  %70 = load i32, ptr @n, align 4, !tbaa !5
  %71 = icmp sgt i32 %69, %70
  br i1 %71, label %72, label %76

72:                                               ; preds = %50
  %73 = load i32, ptr @n, align 4, !tbaa !5
  %74 = load i32, ptr %5, align 4, !tbaa !5
  %75 = sub nsw i32 %74, %73
  store i32 %75, ptr %5, align 4, !tbaa !5
  br label %76

76:                                               ; preds = %72, %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %77

77:                                               ; preds = %76
  %78 = load i32, ptr %3, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %3, align 4, !tbaa !5
  br label %21, !llvm.loop !12

80:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  ret i32 0
}

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

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

attributes #0 = { mustprogress 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; 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
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3addii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3sumi(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %2 = load i32, ptr @m, align 4, !tbaa !5
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = sub nsw i32 %3, %2
  %5 = icmp sgt i32 %2, %4
  br i1 %5, label %6, label %7

6:                                                ; preds = %0
  store i32 %4, ptr @m, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %6, %0
  %8 = phi i32 [ %4, %6 ], [ %2, %0 ]
  %.not29 = icmp slt i32 %3, 1
  br i1 %.not29, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %7
  %9 = add nsw i32 %8, 1
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %7
  ret i32 0

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %10 = phi i32 [ %31, %.lr.ph ], [ %8, %.lr.ph.preheader ]
  %11 = phi i32 [ %33, %.lr.ph ], [ %3, %.lr.ph.preheader ]
  %.01833 = phi i32 [ %.1, %.lr.ph ], [ %9, %.lr.ph.preheader ]
  %.01932 = phi i32 [ %.01833, %.lr.ph ], [ 1, %.lr.ph.preheader ]
  %.02031 = phi i32 [ %36, %.lr.ph ], [ 1, %.lr.ph.preheader ]
  %.02130 = phi i64 [ %23, %.lr.ph ], [ 1, %.lr.ph.preheader ]
  %12 = add i32 %.01833, -1
  %13 = add i32 %12, %10
  %14 = icmp sgt i32 %13, %11
  %15 = select i1 %14, i32 %11, i32 0
  %spec.select = sub nsw i32 %13, %15
  %16 = tail call noundef i32 @_Z3sumi(i32 noundef %spec.select)
  %17 = tail call noundef i32 @_Z3sumi(i32 noundef %.01932)
  %18 = sub i32 %16, %17
  %19 = icmp slt i32 %.01932, %spec.select
  %20 = select i1 %19, i32 1, i32 %.02031
  %21 = add nsw i32 %18, %20
  %22 = sext i32 %21 to i64
  %23 = add nsw i64 %.02130, %22
  %24 = load i32, ptr @n, align 4, !tbaa !5
  %25 = icmp eq i32 %.02031, %24
  %26 = zext i1 %25 to i64
  %27 = getelementptr inbounds [3 x i8], ptr @.str.2, i64 0, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !9
  %29 = sext i8 %28 to i32
  %30 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %23, i32 noundef %29)
  tail call void @_Z3addii(i32 noundef %.01833, i32 noundef 1)
  %31 = load i32, ptr @m, align 4, !tbaa !5
  %32 = add nsw i32 %31, %.01833
  %33 = load i32, ptr @n, align 4, !tbaa !5
  %34 = icmp sgt i32 %32, %33
  %35 = select i1 %34, i32 %33, i32 0
  %.1 = sub nsw i32 %32, %35
  %36 = add nuw nsw i32 %.02031, 1
  %.not.not = icmp slt i32 %.02031, %33
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !10
}

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

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

attributes #0 = { mustprogress 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 = { mustprogress 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 #2 = { 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" }

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


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