; LLVM IR from tangjz/acm-icpc :: codeforces/complete (936C)

; 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
@out = external dso_local global [6003 x i32], align 16
@s = external dso_local global [2001 x i8], align 16
@t = external dso_local global [2001 x i8], align 16
@.str = external hidden unnamed_addr constant [7 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
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %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
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @s, ptr noundef @t)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = sub nsw i32 %7, 1
  store i32 %8, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  br label %9

9:                                                ; preds = %49, %0
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = icmp sge i32 %10, 0
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  store i32 2, ptr %4, align 4
  br label %52

13:                                               ; preds = %9
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = sub nsw i32 %14, 1
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sub nsw i32 %15, %16
  store i32 %17, ptr %3, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %37, %13
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = load i32, ptr @n, align 4, !tbaa !5
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %22, label %34

22:                                               ; preds = %18
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [2001 x i8], ptr @s, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = sext i8 %26 to i32
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [2001 x i8], ptr @t, i64 0, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !9
  %32 = sext i8 %31 to i32
  %33 = icmp ne i32 %27, %32
  br label %34

34:                                               ; preds = %22, %18
  %35 = phi i1 [ false, %18 ], [ %33, %22 ]
  br i1 %35, label %36, label %40

36:                                               ; preds = %34
  br label %37

37:                                               ; preds = %36
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %3, align 4, !tbaa !5
  br label %18, !llvm.loop !10

40:                                               ; preds = %34
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = load i32, ptr @n, align 4, !tbaa !5
  %43 = icmp eq i32 %41, %42
  br i1 %43, label %44, label %46

44:                                               ; preds = %40
  %45 = call i32 @puts(ptr noundef @.str.1)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %4, align 4
  br label %52

46:                                               ; preds = %40
  %47 = load i32, ptr @n, align 4, !tbaa !5
  call void @_Z5shifti(i32 noundef %47)
  %48 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z5shifti(i32 noundef %48)
  call void @_Z5shifti(i32 noundef 1)
  br label %49

49:                                               ; preds = %46
  %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 %9, !llvm.loop !12

52:                                               ; preds = %44, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  %53 = load i32, ptr %4, align 4
  switch i32 %53, label %82 [
    i32 2, label %54
    i32 1, label %80
  ]

54:                                               ; preds = %52
  %55 = load i32, ptr @m, align 4, !tbaa !5
  %56 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %55)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %57

57:                                               ; preds = %76, %54
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = load i32, ptr @m, align 4, !tbaa !5
  %60 = icmp slt i32 %58, %59
  br i1 %60, label %62, label %61

61:                                               ; preds = %57
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %79

62:                                               ; preds = %57
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [6003 x i32], ptr @out, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = load i32, ptr @m, align 4, !tbaa !5
  %69 = sub nsw i32 %68, 1
  %70 = icmp eq i32 %67, %69
  %71 = zext i1 %70 to i64
  %72 = getelementptr inbounds [3 x i8], ptr @.str.4, i64 0, i64 %71
  %73 = load i8, ptr %72, align 1, !tbaa !9
  %74 = sext i8 %73 to i32
  %75 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %66, i32 noundef %74)
  br label %76

76:                                               ; preds = %62
  %77 = load i32, ptr %5, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %5, align 4, !tbaa !5
  br label %57, !llvm.loop !13

79:                                               ; preds = %61
  store i32 0, ptr %1, align 4
  br label %80

80:                                               ; preds = %79, %52
  %81 = load i32, ptr %1, align 4
  ret i32 %81

82:                                               ; preds = %52
  unreachable
}

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

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

declare i32 @puts(ptr noundef) #2

; 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, ...) #2

attributes #0 = { 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 #1 = { 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 #2 = { "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 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !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"

@n = external dso_local global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4
@out = external dso_local local_unnamed_addr global [6003 x i32], align 16
@s = external dso_local global [2001 x i8], align 16
@t = external dso_local global [2001 x i8], align 16
@.str = external hidden unnamed_addr constant [7 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
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1

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

; Function Attrs: mustprogress norecurse 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 @s, ptr noundef nonnull @t)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph30.preheader, label %._crit_edge

.lr.ph30.preheader:                               ; preds = %0
  %4 = sub nsw i32 0, %2
  %5 = zext nneg i32 %2 to i64
  br label %.lr.ph30

.lr.ph30:                                         ; preds = %.lr.ph30.preheader, %20
  %indvars.iv37 = phi i64 [ %5, %.lr.ph30.preheader ], [ %indvars.iv.next38, %20 ]
  %indvars.iv = phi i32 [ %4, %.lr.ph30.preheader ], [ %indvars.iv.next, %20 ]
  %indvars.iv.next38 = add nsw i64 %indvars.iv37, -1
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = trunc nuw nsw i64 %indvars.iv37 to i32
  %8 = sub i32 %6, %7
  %9 = icmp slt i32 %8, %6
  br i1 %9, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %.lr.ph30
  %10 = getelementptr inbounds [2001 x i8], ptr @t, i64 0, i64 %indvars.iv.next38
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %12 = add i32 %6, %indvars.iv
  %13 = sext i32 %12 to i64
  br label %14

14:                                               ; preds = %.lr.ph, %17
  %indvars.iv34 = phi i64 [ %13, %.lr.ph ], [ %indvars.iv.next35, %17 ]
  %15 = getelementptr inbounds [2001 x i8], ptr @s, i64 0, i64 %indvars.iv34
  %16 = load i8, ptr %15, align 1, !tbaa !9
  %.not = icmp eq i8 %16, %11
  br i1 %.not, label %.critedge.loopexit, label %17

17:                                               ; preds = %14
  %indvars.iv.next35 = add nsw i64 %indvars.iv34, 1
  %lftr.wideiv = trunc i64 %indvars.iv.next35 to i32
  %exitcond.not = icmp eq i32 %6, %lftr.wideiv
  br i1 %exitcond.not, label %.critedge.thread, label %14, !llvm.loop !10

.critedge.loopexit:                               ; preds = %14
  %18 = trunc nsw i64 %indvars.iv34 to i32
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %.lr.ph30
  %.016.lcssa = phi i32 [ %8, %.lr.ph30 ], [ %18, %.critedge.loopexit ]
  %19 = icmp eq i32 %.016.lcssa, %6
  br i1 %19, label %.critedge.thread, label %20

20:                                               ; preds = %.critedge
  tail call void @_Z5shifti(i32 noundef %6)
  tail call void @_Z5shifti(i32 noundef %.016.lcssa)
  tail call void @_Z5shifti(i32 noundef 1)
  %21 = icmp sgt i64 %indvars.iv37, 1
  %indvars.iv.next = add i32 %indvars.iv, 1
  br i1 %21, label %.lr.ph30, label %._crit_edge, !llvm.loop !12

.critedge.thread:                                 ; preds = %.critedge, %17
  %22 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %.loopexit

._crit_edge:                                      ; preds = %20, %0
  %23 = load i32, ptr @m, align 4, !tbaa !5
  %24 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %23)
  %25 = load i32, ptr @m, align 4, !tbaa !5
  %26 = icmp sgt i32 %25, 0
  br i1 %26, label %.lr.ph33, label %.loopexit

.lr.ph33:                                         ; preds = %._crit_edge, %.lr.ph33
  %indvars.iv40 = phi i64 [ %indvars.iv.next41, %.lr.ph33 ], [ 0, %._crit_edge ]
  %27 = phi i32 [ %38, %.lr.ph33 ], [ %25, %._crit_edge ]
  %28 = getelementptr inbounds [6003 x i32], ptr @out, i64 0, i64 %indvars.iv40
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = add nsw i32 %27, -1
  %31 = zext i32 %30 to i64
  %32 = icmp eq i64 %indvars.iv40, %31
  %33 = zext i1 %32 to i64
  %34 = getelementptr inbounds [3 x i8], ptr @.str.4, i64 0, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !9
  %36 = sext i8 %35 to i32
  %37 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %29, i32 noundef %36)
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
  %38 = load i32, ptr @m, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = icmp slt i64 %indvars.iv.next41, %39
  br i1 %40, label %.lr.ph33, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %.lr.ph33, %._crit_edge, %.critedge.thread
  ret i32 0
}

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

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


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