; LLVM IR from tangjz/acm-icpc :: buaa/oj3rd (1001)

; 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"

@m = external dso_local global i32, align 4
@n = external dso_local global i64, align 8
@x = external dso_local global i64, align 8
@s = external dso_local global [50 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 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 = %61, %0
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %8 = icmp eq i32 %7, 1
  br i1 %8, label %9, label %67

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

10:                                               ; preds = %58, %9
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = icmp slt i32 %11, 3
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  store i32 4, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %61

14:                                               ; preds = %10
  call void @_Z4scanIiEvRT_(ptr noundef nonnull align 4 dereferenceable(4) @m)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %27, %14
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = load i32, ptr @m, align 4, !tbaa !5
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  store i32 7, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %30

20:                                               ; preds = %15
  %21 = call i32 @getchar()
  %22 = trunc i32 %21 to i8
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [50 x i8], ptr @s, i64 0, i64 %24
  store i8 %22, ptr %25, align 1, !tbaa !9
  %26 = call i32 @getchar()
  br label %27

27:                                               ; preds = %20
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %4, align 4, !tbaa !5
  br label %15, !llvm.loop !10

30:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %54, %30
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = load i32, ptr @m, align 4, !tbaa !5
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  store i32 10, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %57

36:                                               ; preds = %31
  call void @_Z4scanIxEvRT_(ptr noundef nonnull align 8 dereferenceable(8) @x)
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [50 x i8], ptr @s, i64 0, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !9
  %41 = sext i8 %40 to i32
  %42 = icmp eq i32 %41, 49
  br i1 %42, label %43, label %53

43:                                               ; preds = %36
  %44 = load i64, ptr @n, align 8, !tbaa !12
  %45 = load i64, ptr @x, align 8, !tbaa !12
  %46 = icmp sge i64 %44, %45
  br i1 %46, label %47, label %51

47:                                               ; preds = %43
  %48 = load i64, ptr @x, align 8, !tbaa !12
  %49 = load i64, ptr @n, align 8, !tbaa !12
  %50 = sub nsw i64 %49, %48
  store i64 %50, ptr @n, align 8, !tbaa !12
  br label %52

51:                                               ; preds = %43
  store i64 -1, ptr @n, align 8, !tbaa !12
  br label %52

52:                                               ; preds = %51, %47
  br label %53

53:                                               ; preds = %52, %36
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %5, align 4, !tbaa !5
  br label %31, !llvm.loop !14

57:                                               ; preds = %35
  br label %58

58:                                               ; preds = %57
  %59 = load i32, ptr %2, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %2, align 4, !tbaa !5
  br label %10, !llvm.loop !15

61:                                               ; preds = %13
  %62 = load i64, ptr @n, align 8, !tbaa !12
  %63 = icmp eq i64 %62, -1
  %64 = zext i1 %63 to i64
  %65 = select i1 %63, ptr @.str.1, ptr @.str.2
  %66 = call i32 @puts(ptr noundef %65)
  br label %6, !llvm.loop !16

67:                                               ; preds = %6
  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: mustprogress uwtable
declare dso_local void @_Z4scanIiEvRT_(ptr noundef nonnull align 4 dereferenceable(4)) #3

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4scanIxEvRT_(ptr noundef nonnull align 8 dereferenceable(8)) #3

declare i32 @puts(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 = { 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 = { 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 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = distinct !{!14, !11}
!15 = distinct !{!15, !11}
!16 = distinct !{!16, !11}


; 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"

@m = external dso_local global i32, align 4
@n = external dso_local global i64, align 8
@x = external dso_local global i64, align 8
@s = external dso_local local_unnamed_addr global [50 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress norecurse 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)
  %2 = icmp eq i32 %1, 1
  br i1 %2, label %.preheader12, label %._crit_edge17

.preheader12:                                     ; preds = %0, %._crit_edge.2
  tail call void @_Z4scanIiEvRT_(ptr noundef nonnull align 4 dereferenceable(4) @m)
  %3 = load i32, ptr @m, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %._crit_edge

.preheader:                                       ; preds = %.lr.ph
  %5 = icmp sgt i32 %10, 0
  br i1 %5, label %.lr.ph15, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader12, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader12 ]
  %6 = tail call i32 @getchar()
  %7 = trunc i32 %6 to i8
  %8 = getelementptr inbounds [50 x i8], ptr @s, i64 0, i64 %indvars.iv
  store i8 %7, ptr %8, align 1, !tbaa !9
  %9 = tail call i32 @getchar()
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %10 = load i32, ptr @m, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = icmp slt i64 %indvars.iv.next, %11
  br i1 %12, label %.lr.ph, label %.preheader, !llvm.loop !10

._crit_edge:                                      ; preds = %65, %.preheader12, %.preheader
  tail call void @_Z4scanIiEvRT_(ptr noundef nonnull align 4 dereferenceable(4) @m)
  %13 = load i32, ptr @m, align 4, !tbaa !5
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %.lr.ph.1, label %._crit_edge.1

.lr.ph.1:                                         ; preds = %._crit_edge, %.lr.ph.1
  %indvars.iv.1 = phi i64 [ %indvars.iv.next.1, %.lr.ph.1 ], [ 0, %._crit_edge ]
  %15 = tail call i32 @getchar()
  %16 = trunc i32 %15 to i8
  %17 = getelementptr inbounds [50 x i8], ptr @s, i64 0, i64 %indvars.iv.1
  store i8 %16, ptr %17, align 1, !tbaa !9
  %18 = tail call i32 @getchar()
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv.1, 1
  %19 = load i32, ptr @m, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = icmp slt i64 %indvars.iv.next.1, %20
  br i1 %21, label %.lr.ph.1, label %.preheader.1, !llvm.loop !10

.preheader.1:                                     ; preds = %.lr.ph.1
  %22 = icmp sgt i32 %19, 0
  br i1 %22, label %.lr.ph15.1, label %._crit_edge.1

.lr.ph15.1:                                       ; preds = %.preheader.1, %29
  %indvars.iv19.1 = phi i64 [ %indvars.iv.next20.1, %29 ], [ 0, %.preheader.1 ]
  tail call void @_Z4scanIxEvRT_(ptr noundef nonnull align 8 dereferenceable(8) @x)
  %23 = getelementptr inbounds [50 x i8], ptr @s, i64 0, i64 %indvars.iv19.1
  %24 = load i8, ptr %23, align 1, !tbaa !9
  %25 = icmp eq i8 %24, 49
  br i1 %25, label %.sink.split, label %29

.sink.split:                                      ; preds = %.lr.ph15.1
  %26 = load i64, ptr @n, align 8, !tbaa !12
  %27 = load i64, ptr @x, align 8, !tbaa !12
  %.not.1 = icmp slt i64 %26, %27
  %28 = sub nsw i64 %26, %27
  %.sink = select i1 %.not.1, i64 -1, i64 %28
  store i64 %.sink, ptr @n, align 8, !tbaa !12
  br label %29

29:                                               ; preds = %.sink.split, %.lr.ph15.1
  %indvars.iv.next20.1 = add nuw nsw i64 %indvars.iv19.1, 1
  %30 = load i32, ptr @m, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = icmp slt i64 %indvars.iv.next20.1, %31
  br i1 %32, label %.lr.ph15.1, label %._crit_edge.1, !llvm.loop !14

._crit_edge.1:                                    ; preds = %29, %._crit_edge, %.preheader.1
  tail call void @_Z4scanIiEvRT_(ptr noundef nonnull align 4 dereferenceable(4) @m)
  %33 = load i32, ptr @m, align 4, !tbaa !5
  %34 = icmp sgt i32 %33, 0
  br i1 %34, label %.lr.ph.2, label %._crit_edge.2

.lr.ph.2:                                         ; preds = %._crit_edge.1, %.lr.ph.2
  %indvars.iv.2 = phi i64 [ %indvars.iv.next.2, %.lr.ph.2 ], [ 0, %._crit_edge.1 ]
  %35 = tail call i32 @getchar()
  %36 = trunc i32 %35 to i8
  %37 = getelementptr inbounds [50 x i8], ptr @s, i64 0, i64 %indvars.iv.2
  store i8 %36, ptr %37, align 1, !tbaa !9
  %38 = tail call i32 @getchar()
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv.2, 1
  %39 = load i32, ptr @m, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = icmp slt i64 %indvars.iv.next.2, %40
  br i1 %41, label %.lr.ph.2, label %.preheader.2, !llvm.loop !10

.preheader.2:                                     ; preds = %.lr.ph.2
  %42 = icmp sgt i32 %39, 0
  br i1 %42, label %.lr.ph15.2, label %._crit_edge.2

.lr.ph15.2:                                       ; preds = %.preheader.2, %49
  %indvars.iv19.2 = phi i64 [ %indvars.iv.next20.2, %49 ], [ 0, %.preheader.2 ]
  tail call void @_Z4scanIxEvRT_(ptr noundef nonnull align 8 dereferenceable(8) @x)
  %43 = getelementptr inbounds [50 x i8], ptr @s, i64 0, i64 %indvars.iv19.2
  %44 = load i8, ptr %43, align 1, !tbaa !9
  %45 = icmp eq i8 %44, 49
  br i1 %45, label %.sink.split24, label %49

.sink.split24:                                    ; preds = %.lr.ph15.2
  %46 = load i64, ptr @n, align 8, !tbaa !12
  %47 = load i64, ptr @x, align 8, !tbaa !12
  %.not.2 = icmp slt i64 %46, %47
  %48 = sub nsw i64 %46, %47
  %.sink25 = select i1 %.not.2, i64 -1, i64 %48
  store i64 %.sink25, ptr @n, align 8, !tbaa !12
  br label %49

49:                                               ; preds = %.sink.split24, %.lr.ph15.2
  %indvars.iv.next20.2 = add nuw nsw i64 %indvars.iv19.2, 1
  %50 = load i32, ptr @m, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = icmp slt i64 %indvars.iv.next20.2, %51
  br i1 %52, label %.lr.ph15.2, label %._crit_edge.2, !llvm.loop !14

._crit_edge.2:                                    ; preds = %49, %._crit_edge.1, %.preheader.2
  %53 = load i64, ptr @n, align 8, !tbaa !12
  %54 = icmp eq i64 %53, -1
  %55 = select i1 %54, ptr @.str.1, ptr @.str.2
  %56 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %55)
  %57 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %58 = icmp eq i32 %57, 1
  br i1 %58, label %.preheader12, label %._crit_edge17, !llvm.loop !15

.lr.ph15:                                         ; preds = %.preheader, %65
  %indvars.iv19 = phi i64 [ %indvars.iv.next20, %65 ], [ 0, %.preheader ]
  tail call void @_Z4scanIxEvRT_(ptr noundef nonnull align 8 dereferenceable(8) @x)
  %59 = getelementptr inbounds [50 x i8], ptr @s, i64 0, i64 %indvars.iv19
  %60 = load i8, ptr %59, align 1, !tbaa !9
  %61 = icmp eq i8 %60, 49
  br i1 %61, label %.sink.split26, label %65

.sink.split26:                                    ; preds = %.lr.ph15
  %62 = load i64, ptr @n, align 8, !tbaa !12
  %63 = load i64, ptr @x, align 8, !tbaa !12
  %.not = icmp slt i64 %62, %63
  %64 = sub nsw i64 %62, %63
  %.sink27 = select i1 %.not, i64 -1, i64 %64
  store i64 %.sink27, ptr @n, align 8, !tbaa !12
  br label %65

65:                                               ; preds = %.sink.split26, %.lr.ph15
  %indvars.iv.next20 = add nuw nsw i64 %indvars.iv19, 1
  %66 = load i32, ptr @m, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = icmp slt i64 %indvars.iv.next20, %67
  br i1 %68, label %.lr.ph15, label %._crit_edge, !llvm.loop !14

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4scanIiEvRT_(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4scanIxEvRT_(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @puts(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 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 = { 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" }

!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"}
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = distinct !{!14, !11}
!15 = distinct !{!15, !11}


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