; LLVM IR from tangjz/acm-icpc :: codeforces/gym (100624C)

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

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@str = external dso_local global [50010 x i8], align 16
@f = external dso_local global [50010 x i8], align 16
@a = external dso_local global [256 x [256 x i8]], align 16
@.str = external hidden unnamed_addr constant [3 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 [3 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z4initv() #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 i32, align 4
  store i32 0, ptr %1, align 4
  call void @_Z4initv()
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %4

4:                                                ; preds = %88, %0
  %5 = load i32, ptr @t, align 4, !tbaa !5
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr @t, align 4, !tbaa !5
  %7 = icmp ne i32 %5, 0
  br i1 %7, label %8, label %97

8:                                                ; preds = %4
  call void @llvm.memset.p0.i64(ptr align 16 @f, i8 0, i64 50010, i1 false)
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef getelementptr inbounds (i8, ptr @str, i64 1))
  %10 = call i64 @strlen(ptr noundef getelementptr inbounds (i8, ptr @str, i64 1)) #6
  %11 = trunc i64 %10 to i32
  store i32 %11, ptr @n, align 4, !tbaa !5
  store i8 1, ptr @f, align 16, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #7
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %85, %8
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = icmp sle i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #7
  br label %88

17:                                               ; preds = %12
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = icmp sgt i32 %18, 1
  br i1 %19, label %20, label %56

20:                                               ; preds = %17
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sub nsw i32 %21, 1
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [50010 x i8], ptr @str, i64 0, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !11
  %26 = sext i8 %25 to i32
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [256 x [256 x i8]], ptr @a, i64 0, i64 %27
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [50010 x i8], ptr @str, i64 0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !11
  %33 = sext i8 %32 to i32
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [256 x i8], ptr %28, i64 0, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !9, !range !12, !noundef !13
  %37 = trunc i8 %36 to i1
  %38 = zext i1 %37 to i32
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = sub nsw i32 %39, 2
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [50010 x i8], ptr @f, i64 0, i64 %41
  %43 = load i8, ptr %42, align 1, !tbaa !9, !range !12, !noundef !13
  %44 = trunc i8 %43 to i1
  %45 = zext i1 %44 to i32
  %46 = and i32 %38, %45
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [50010 x i8], ptr @f, i64 0, i64 %48
  %50 = load i8, ptr %49, align 1, !tbaa !9, !range !12, !noundef !13
  %51 = trunc i8 %50 to i1
  %52 = zext i1 %51 to i32
  %53 = or i32 %52, %46
  %54 = icmp ne i32 %53, 0
  %55 = zext i1 %54 to i8
  store i8 %55, ptr %49, align 1, !tbaa !9
  br label %56

56:                                               ; preds = %20, %17
  %57 = load i32, ptr %2, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [50010 x i8], ptr @str, i64 0, i64 %58
  %60 = load i8, ptr %59, align 1, !tbaa !11
  %61 = sext i8 %60 to i32
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [256 x [256 x i8]], ptr @a, i64 0, i64 %62
  %64 = getelementptr inbounds [256 x i8], ptr %63, i64 0, i64 0
  %65 = load i8, ptr %64, align 16, !tbaa !9, !range !12, !noundef !13
  %66 = trunc i8 %65 to i1
  %67 = zext i1 %66 to i32
  %68 = load i32, ptr %2, align 4, !tbaa !5
  %69 = sub nsw i32 %68, 1
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [50010 x i8], ptr @f, i64 0, i64 %70
  %72 = load i8, ptr %71, align 1, !tbaa !9, !range !12, !noundef !13
  %73 = trunc i8 %72 to i1
  %74 = zext i1 %73 to i32
  %75 = and i32 %67, %74
  %76 = load i32, ptr %2, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [50010 x i8], ptr @f, i64 0, i64 %77
  %79 = load i8, ptr %78, align 1, !tbaa !9, !range !12, !noundef !13
  %80 = trunc i8 %79 to i1
  %81 = zext i1 %80 to i32
  %82 = or i32 %81, %75
  %83 = icmp ne i32 %82, 0
  %84 = zext i1 %83 to i8
  store i8 %84, ptr %78, align 1, !tbaa !9
  br label %85

85:                                               ; preds = %56
  %86 = load i32, ptr %2, align 4, !tbaa !5
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %2, align 4, !tbaa !5
  br label %12, !llvm.loop !14

88:                                               ; preds = %16
  %89 = load i32, ptr @n, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [50010 x i8], ptr @f, i64 0, i64 %90
  %92 = load i8, ptr %91, align 1, !tbaa !9, !range !12, !noundef !13
  %93 = trunc i8 %92 to i1
  %94 = zext i1 %93 to i64
  %95 = select i1 %93, ptr @.str.2, ptr @.str.3
  %96 = call i32 @puts(ptr noundef %95)
  br label %4, !llvm.loop !16

97:                                               ; preds = %4
  ret i32 0
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #5

declare i32 @puts(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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind willreturn memory(read) "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 willreturn memory(read) }
attributes #7 = { 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 = !{!"bool", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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

@t = external dso_local global i32, align 4
@n = external dso_local local_unnamed_addr global i32, align 4
@str = external dso_local global [50010 x i8], align 16
@f = external dso_local local_unnamed_addr global [50010 x i8], align 16
@a = external dso_local local_unnamed_addr global [256 x [256 x i8]], align 16
@.str = external hidden unnamed_addr constant [3 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 [3 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z4initv() local_unnamed_addr #0

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  tail call void @_Z4initv()
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @t, align 4, !tbaa !5
  %.not14 = icmp eq i32 %2, 0
  br i1 %.not14, label %._crit_edge17, label %.lr.ph16

.lr.ph16:                                         ; preds = %0, %._crit_edge
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(50010) @f, i8 0, i64 50010, i1 false)
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull getelementptr inbounds (i8, ptr @str, i64 1))
  %5 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) getelementptr inbounds (i8, ptr @str, i64 1)) #5
  %6 = trunc i64 %5 to i32
  store i32 %6, ptr @n, align 4, !tbaa !5
  store i8 1, ptr @f, align 16, !tbaa !9
  %.not1112 = icmp slt i32 %6, 1
  br i1 %.not1112, label %._crit_edge, label %7

7:                                                ; preds = %.lr.ph16
  %8 = add nuw nsw i64 %5, 1
  %wide.trip.count = and i64 %8, 4294967295
  %.pre = load i8, ptr getelementptr inbounds (i8, ptr @str, i64 1), align 1, !tbaa !11
  %.pre22 = load i8, ptr getelementptr inbounds (i8, ptr @f, i64 1), align 1, !tbaa !9, !range !12
  %.phi.trans.insert = sext i8 %.pre to i64
  %.phi.trans.insert20 = getelementptr inbounds [256 x [256 x i8]], ptr @a, i64 0, i64 %.phi.trans.insert
  %.pre21 = load i8, ptr %.phi.trans.insert20, align 16, !tbaa !9, !range !12
  %9 = or i8 %.pre22, %.pre21
  store i8 %9, ptr getelementptr inbounds (i8, ptr @f, i64 1), align 1, !tbaa !9
  %exitcond.peel.not = icmp eq i64 %wide.trip.count, 2
  br i1 %exitcond.peel.not, label %._crit_edge, label %.lr.ph.peel.next

._crit_edge:                                      ; preds = %.lr.ph.peel.next, %7, %.lr.ph16
  %sext = shl i64 %5, 32
  %10 = ashr exact i64 %sext, 32
  %11 = getelementptr inbounds [50010 x i8], ptr @f, i64 0, i64 %10
  %12 = load i8, ptr %11, align 1, !tbaa !9, !range !12, !noundef !13
  %13 = trunc nuw i8 %12 to i1
  %14 = select i1 %13, ptr @.str.2, ptr @.str.3
  %15 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %14)
  %16 = load i32, ptr @t, align 4, !tbaa !5
  %17 = add nsw i32 %16, -1
  store i32 %17, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %._crit_edge17, label %.lr.ph16, !llvm.loop !14

.lr.ph.peel.next:                                 ; preds = %7, %.lr.ph.peel.next
  %18 = phi i8 [ %33, %.lr.ph.peel.next ], [ %9, %7 ]
  %19 = phi i8 [ %18, %.lr.ph.peel.next ], [ 1, %7 ]
  %20 = phi i8 [ %23, %.lr.ph.peel.next ], [ %.pre, %7 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph.peel.next ], [ 2, %7 ]
  %21 = sext i8 %20 to i64
  %22 = getelementptr inbounds [50010 x i8], ptr @str, i64 0, i64 %indvars.iv
  %23 = load i8, ptr %22, align 1, !tbaa !11
  %24 = sext i8 %23 to i64
  %25 = getelementptr inbounds [256 x [256 x i8]], ptr @a, i64 0, i64 %21, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !9, !range !12, !noundef !13
  %27 = and i8 %19, %26
  %28 = getelementptr inbounds [50010 x i8], ptr @f, i64 0, i64 %indvars.iv
  %29 = load i8, ptr %28, align 1, !tbaa !9, !range !12, !noundef !13
  %30 = or i8 %29, %27
  %.phi.trans.insert25 = getelementptr inbounds [256 x [256 x i8]], ptr @a, i64 0, i64 %24
  %.pre26 = load i8, ptr %.phi.trans.insert25, align 16, !tbaa !9, !range !12
  %31 = and i8 %18, %.pre26
  %32 = getelementptr inbounds [50010 x i8], ptr @f, i64 0, i64 %indvars.iv
  %33 = or i8 %30, %31
  store i8 %33, ptr %32, align 1, !tbaa !9
  %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_edge, label %.lr.ph.peel.next, !llvm.loop !16

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @puts(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" }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 willreturn memory(read) }

!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 = !{!"bool", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15, !17}
!17 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: BDCEPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass