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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3addiii(i32 noundef, i32 noundef, 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 nounwind uwtable
declare dso_local noundef i32 @_Z3sumii(i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i8, align 1
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 1, ptr %2) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  br label %9

9:                                                ; preds = %89, %22, %0
  %10 = call i32 @getchar()
  %11 = trunc i32 %10 to i8
  store i8 %11, ptr %2, align 1, !tbaa !5
  %12 = sext i8 %11 to i32
  %13 = icmp ne i32 %12, -1
  br i1 %13, label %14, label %90

14:                                               ; preds = %9
  %15 = load i8, ptr %2, align 1, !tbaa !5
  %16 = sext i8 %15 to i32
  %17 = icmp eq i32 %16, 13
  br i1 %17, label %22, label %18

18:                                               ; preds = %14
  %19 = load i8, ptr %2, align 1, !tbaa !5
  %20 = sext i8 %19 to i32
  %21 = icmp eq i32 %20, 10
  br i1 %21, label %22, label %23

22:                                               ; preds = %18, %14
  br label %9, !llvm.loop !8

23:                                               ; preds = %18
  %24 = load i8, ptr %2, align 1, !tbaa !5
  %25 = sext i8 %24 to i32
  %26 = icmp eq i32 %25, 76
  br i1 %26, label %27, label %57

27:                                               ; preds = %23
  %28 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %3, ptr noundef %5, ptr noundef %4, ptr noundef %6, ptr noundef %7)
  %29 = load i32, ptr %3, align 4, !tbaa !10
  %30 = load i32, ptr %4, align 4, !tbaa !10
  %31 = icmp sgt i32 %29, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %27
  call void @_Z4swapRiS_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  br label %33

33:                                               ; preds = %32, %27
  %34 = load i32, ptr %5, align 4, !tbaa !10
  %35 = load i32, ptr %6, align 4, !tbaa !10
  %36 = icmp sgt i32 %34, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %33
  call void @_Z4swapRiS_(ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6)
  br label %38

38:                                               ; preds = %37, %33
  %39 = load i32, ptr %3, align 4, !tbaa !10
  %40 = load i32, ptr %5, align 4, !tbaa !10
  %41 = load i32, ptr %7, align 4, !tbaa !10
  call void @_Z3addiii(i32 noundef %39, i32 noundef %40, i32 noundef %41)
  %42 = load i32, ptr %4, align 4, !tbaa !10
  %43 = add nsw i32 %42, 1
  %44 = load i32, ptr %5, align 4, !tbaa !10
  %45 = load i32, ptr %7, align 4, !tbaa !10
  %46 = sub nsw i32 0, %45
  call void @_Z3addiii(i32 noundef %43, i32 noundef %44, i32 noundef %46)
  %47 = load i32, ptr %3, align 4, !tbaa !10
  %48 = load i32, ptr %6, align 4, !tbaa !10
  %49 = add nsw i32 %48, 1
  %50 = load i32, ptr %7, align 4, !tbaa !10
  %51 = sub nsw i32 0, %50
  call void @_Z3addiii(i32 noundef %47, i32 noundef %49, i32 noundef %51)
  %52 = load i32, ptr %4, align 4, !tbaa !10
  %53 = add nsw i32 %52, 1
  %54 = load i32, ptr %6, align 4, !tbaa !10
  %55 = add nsw i32 %54, 1
  %56 = load i32, ptr %7, align 4, !tbaa !10
  call void @_Z3addiii(i32 noundef %53, i32 noundef %55, i32 noundef %56)
  br label %89

57:                                               ; preds = %23
  %58 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %3, ptr noundef %5, ptr noundef %4, ptr noundef %6)
  %59 = load i32, ptr %3, align 4, !tbaa !10
  %60 = load i32, ptr %4, align 4, !tbaa !10
  %61 = icmp sgt i32 %59, %60
  br i1 %61, label %62, label %63

62:                                               ; preds = %57
  call void @_Z4swapRiS_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  br label %63

63:                                               ; preds = %62, %57
  %64 = load i32, ptr %5, align 4, !tbaa !10
  %65 = load i32, ptr %6, align 4, !tbaa !10
  %66 = icmp sgt i32 %64, %65
  br i1 %66, label %67, label %68

67:                                               ; preds = %63
  call void @_Z4swapRiS_(ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6)
  br label %68

68:                                               ; preds = %67, %63
  %69 = load i32, ptr %4, align 4, !tbaa !10
  %70 = load i32, ptr %6, align 4, !tbaa !10
  %71 = call noundef i32 @_Z3sumii(i32 noundef %69, i32 noundef %70)
  %72 = load i32, ptr %3, align 4, !tbaa !10
  %73 = sub nsw i32 %72, 1
  %74 = load i32, ptr %6, align 4, !tbaa !10
  %75 = call noundef i32 @_Z3sumii(i32 noundef %73, i32 noundef %74)
  %76 = sub nsw i32 %71, %75
  %77 = load i32, ptr %4, align 4, !tbaa !10
  %78 = load i32, ptr %5, align 4, !tbaa !10
  %79 = sub nsw i32 %78, 1
  %80 = call noundef i32 @_Z3sumii(i32 noundef %77, i32 noundef %79)
  %81 = sub nsw i32 %76, %80
  %82 = load i32, ptr %3, align 4, !tbaa !10
  %83 = sub nsw i32 %82, 1
  %84 = load i32, ptr %5, align 4, !tbaa !10
  %85 = sub nsw i32 %84, 1
  %86 = call noundef i32 @_Z3sumii(i32 noundef %83, i32 noundef %85)
  %87 = add nsw i32 %81, %86
  %88 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %87)
  br label %89

89:                                               ; preds = %68, %38
  br label %9, !llvm.loop !8

90:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 1, ptr %2) #6
  ret i32 0
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare i32 @getchar() #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z4swapRiS_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #5

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 = { 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 #5 = { inlinehint 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 #6 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, i64 0}


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

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

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

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

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

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %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
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #6
  %6 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  br label %.backedge

.backedge:                                        ; preds = %.backedge.backedge, %0
  %7 = call i32 @getchar()
  %trunc = trunc i32 %7 to i8
  switch i8 %trunc, label %38 [
    i8 -1, label %70
    i8 13, label %.backedge.backedge
    i8 10, label %.backedge.backedge
    i8 76, label %8
  ]

8:                                                ; preds = %.backedge
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1, ptr noundef nonnull %3, ptr noundef nonnull %2, ptr noundef nonnull %4, ptr noundef nonnull %5)
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = icmp sgt i32 %10, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %8
  call void @_Z4swapRiS_(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2)
  br label %14

14:                                               ; preds = %13, %8
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = icmp sgt i32 %15, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %14
  call void @_Z4swapRiS_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %.pre = load i32, ptr %3, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %18, %14
  %20 = phi i32 [ %.pre, %18 ], [ %15, %14 ]
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %22 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z3addiii(i32 noundef %21, i32 noundef %20, i32 noundef %22)
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = sub nsw i32 0, %26
  call void @_Z3addiii(i32 noundef %24, i32 noundef %25, i32 noundef %27)
  %28 = load i32, ptr %1, align 4, !tbaa !5
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = sub nsw i32 0, %31
  call void @_Z3addiii(i32 noundef %28, i32 noundef %30, i32 noundef %32)
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  %37 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z3addiii(i32 noundef %34, i32 noundef %36, i32 noundef %37)
  br label %.backedge.backedge

.backedge.backedge:                               ; preds = %19, %49, %.backedge, %.backedge
  br label %.backedge, !llvm.loop !9

38:                                               ; preds = %.backedge
  %39 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %1, ptr noundef nonnull %3, ptr noundef nonnull %2, ptr noundef nonnull %4)
  %40 = load i32, ptr %1, align 4, !tbaa !5
  %41 = load i32, ptr %2, align 4, !tbaa !5
  %42 = icmp sgt i32 %40, %41
  br i1 %42, label %43, label %44

43:                                               ; preds = %38
  call void @_Z4swapRiS_(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2)
  br label %44

44:                                               ; preds = %43, %38
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = icmp sgt i32 %45, %46
  br i1 %47, label %48, label %49

48:                                               ; preds = %44
  call void @_Z4swapRiS_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %.pre7 = load i32, ptr %4, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %48, %44
  %50 = phi i32 [ %.pre7, %48 ], [ %46, %44 ]
  %51 = load i32, ptr %2, align 4, !tbaa !5
  %52 = call noundef i32 @_Z3sumii(i32 noundef %51, i32 noundef %50)
  %53 = load i32, ptr %1, align 4, !tbaa !5
  %54 = add nsw i32 %53, -1
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = call noundef i32 @_Z3sumii(i32 noundef %54, i32 noundef %55)
  %57 = load i32, ptr %2, align 4, !tbaa !5
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = add nsw i32 %58, -1
  %60 = call noundef i32 @_Z3sumii(i32 noundef %57, i32 noundef %59)
  %61 = load i32, ptr %1, align 4, !tbaa !5
  %62 = add nsw i32 %61, -1
  %63 = load i32, ptr %3, align 4, !tbaa !5
  %64 = add nsw i32 %63, -1
  %65 = call noundef i32 @_Z3sumii(i32 noundef %62, i32 noundef %64)
  %66 = add i32 %56, %60
  %67 = sub i32 %52, %66
  %68 = add nsw i32 %67, %65
  %69 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %68)
  br label %.backedge.backedge

70:                                               ; preds = %.backedge
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #6
  ret i32 0
}

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

; Function Attrs: inlinehint mustprogress nofree nounwind uwtable
declare noundef i32 @getchar() local_unnamed_addr #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z4swapRiS_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #5

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


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