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

; 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
@e = external dso_local global [20 x [20 x i32]], align 16
@c = external dso_local global [20 x i32], align 16
@ans = external dso_local global i32, align 4
@vis = external dso_local global [1048576 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsii(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 norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %8

8:                                                ; preds = %92, %0
  %9 = load i32, ptr @t, align 4, !tbaa !5
  %10 = add nsw i32 %9, -1
  store i32 %10, ptr @t, align 4, !tbaa !5
  %11 = icmp ne i32 %9, 0
  br i1 %11, label %12, label %93

12:                                               ; preds = %8
  store i32 0, ptr @ans, align 4, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 16 @vis, i8 0, i64 1048576, i1 false)
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %52, %12
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  store i32 4, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  br label %55

19:                                               ; preds = %14
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [20 x i32], ptr @c, i64 0, i64 %21
  store i32 0, ptr %22, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %48, %19
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = load i32, ptr @n, align 4, !tbaa !5
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  store i32 7, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  br label %51

28:                                               ; preds = %23
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [20 x [20 x i32]], ptr @e, i64 0, i64 %30
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [20 x i32], ptr %31, i64 0, i64 %33
  %35 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %34)
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [20 x [20 x i32]], ptr @e, i64 0, i64 %37
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [20 x i32], ptr %38, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = load i32, ptr %2, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [20 x i32], ptr @c, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = add nsw i32 %46, %42
  store i32 %47, ptr %45, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %28
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %4, align 4, !tbaa !5
  br label %23, !llvm.loop !9

51:                                               ; preds = %27
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %2, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %2, align 4, !tbaa !5
  br label %14, !llvm.loop !11

55:                                               ; preds = %18
  %56 = load i32, ptr @n, align 4, !tbaa !5
  %57 = shl i32 1, %56
  %58 = sub nsw i32 %57, 1
  %59 = load i32, ptr @n, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %58, i32 noundef %59)
  %60 = load i32, ptr @ans, align 4, !tbaa !5
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %64, label %62

62:                                               ; preds = %55
  %63 = call i32 @puts(ptr noundef @.str.1)
  br label %92

64:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #6
  store i8 0, ptr %5, align 1, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %65

65:                                               ; preds = %87, %64
  %66 = load i32, ptr %6, align 4, !tbaa !5
  %67 = load i32, ptr @n, align 4, !tbaa !5
  %68 = icmp slt i32 %66, %67
  br i1 %68, label %70, label %69

69:                                               ; preds = %65
  store i32 10, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  br label %90

70:                                               ; preds = %65
  %71 = load i32, ptr @ans, align 4, !tbaa !5
  %72 = load i32, ptr %6, align 4, !tbaa !5
  %73 = shl i32 1, %72
  %74 = and i32 %71, %73
  %75 = icmp ne i32 %74, 0
  br i1 %75, label %76, label %86

76:                                               ; preds = %70
  %77 = load i8, ptr %5, align 1, !tbaa !12, !range !14, !noundef !15
  %78 = trunc i8 %77 to i1
  br i1 %78, label %79, label %81

79:                                               ; preds = %76
  %80 = call i32 @putchar(i32 noundef 32)
  br label %82

81:                                               ; preds = %76
  store i8 1, ptr %5, align 1, !tbaa !12
  br label %82

82:                                               ; preds = %81, %79
  %83 = load i32, ptr %6, align 4, !tbaa !5
  %84 = add nsw i32 %83, 1
  %85 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %84)
  br label %86

86:                                               ; preds = %82, %70
  br label %87

87:                                               ; preds = %86
  %88 = load i32, ptr %6, align 4, !tbaa !5
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %6, align 4, !tbaa !5
  br label %65, !llvm.loop !16

90:                                               ; preds = %69
  %91 = call i32 @putchar(i32 noundef 10)
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #6
  br label %92

92:                                               ; preds = %90, %62
  br label %8, !llvm.loop !17

93:                                               ; preds = %8
  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

declare i32 @puts(ptr noundef) #3

; Function Attrs: inlinehint mustprogress uwtable
declare i32 @putchar(i32 noundef) #5

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

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 = { 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 = { 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 #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"}
!11 = distinct !{!11, !10}
!12 = !{!13, !13, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = distinct !{!16, !10}
!17 = distinct !{!17, !10}


; 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 global i32, align 4
@e = external dso_local global [20 x [20 x i32]], align 16
@c = external dso_local local_unnamed_addr global [20 x i32], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4
@vis = external dso_local local_unnamed_addr global [1048576 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsii(i32 noundef, 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 @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
  %.not30 = icmp eq i32 %2, 0
  br i1 %.not30, label %._crit_edge33, label %.lr.ph32

.lr.ph32:                                         ; preds = %0, %41
  store i32 0, ptr @ans, align 4, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1048576) @vis, i8 0, i64 1048576, i1 false)
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph24.split, label %._crit_edge25

._crit_edge25:                                    ; preds = %._crit_edge, %.lr.ph32
  %.lcssa = phi i32 [ %5, %.lr.ph32 ], [ %14, %._crit_edge ]
  %notmask = shl nsw i32 -1, %.lcssa
  %7 = xor i32 %notmask, -1
  tail call void @_Z3dfsii(i32 noundef %7, i32 noundef %.lcssa)
  %8 = load i32, ptr @ans, align 4, !tbaa !5
  %.not19 = icmp eq i32 %8, 0
  br i1 %.not19, label %24, label %.preheader

.preheader:                                       ; preds = %._crit_edge25
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.lr.ph28, label %._crit_edge29

.lr.ph24.split:                                   ; preds = %.lr.ph32, %._crit_edge
  %11 = phi i32 [ %14, %._crit_edge ], [ %5, %.lr.ph32 ]
  %indvars.iv38 = phi i64 [ %indvars.iv.next39, %._crit_edge ], [ 0, %.lr.ph32 ]
  %12 = getelementptr inbounds [20 x i32], ptr @c, i64 0, i64 %indvars.iv38
  store i32 0, ptr %12, align 4, !tbaa !5
  %13 = icmp sgt i32 %11, 0
  br i1 %13, label %.lr.ph, label %.lr.ph24.split.._crit_edge_crit_edge

.lr.ph24.split.._crit_edge_crit_edge:             ; preds = %.lr.ph24.split
  %.pre43 = sext i32 %11 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph24.split.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre43, %.lr.ph24.split.._crit_edge_crit_edge ], [ %22, %.lr.ph ]
  %14 = phi i32 [ %11, %.lr.ph24.split.._crit_edge_crit_edge ], [ %21, %.lr.ph ]
  %indvars.iv.next39 = add nuw nsw i64 %indvars.iv38, 1
  %15 = icmp slt i64 %indvars.iv.next39, %.pre-phi
  br i1 %15, label %.lr.ph24.split, label %._crit_edge25, !llvm.loop !9

.lr.ph:                                           ; preds = %.lr.ph24.split, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.lr.ph24.split ]
  %16 = getelementptr inbounds [20 x [20 x i32]], ptr @e, i64 0, i64 %indvars.iv38, i64 %indvars.iv
  %17 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %16)
  %18 = load i32, ptr %16, align 4, !tbaa !5
  %19 = load i32, ptr %12, align 4, !tbaa !5
  %20 = add nsw i32 %19, %18
  store i32 %20, ptr %12, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %21 = load i32, ptr @n, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = icmp slt i64 %indvars.iv.next, %22
  br i1 %23, label %.lr.ph, label %._crit_edge, !llvm.loop !12

24:                                               ; preds = %._crit_edge25
  %25 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %41

._crit_edge29:                                    ; preds = %37, %.preheader
  %26 = tail call i32 @putchar(i32 noundef 10)
  br label %41

.lr.ph28:                                         ; preds = %.preheader, %37
  %27 = phi i32 [ %38, %37 ], [ %9, %.preheader ]
  %28 = phi i32 [ %39, %37 ], [ %8, %.preheader ]
  %.027 = phi i32 [ %.pre-phi45, %37 ], [ 0, %.preheader ]
  %.01526 = phi i1 [ %.2, %37 ], [ false, %.preheader ]
  %29 = shl nuw i32 1, %.027
  %30 = and i32 %28, %29
  %.not20 = icmp eq i32 %30, 0
  br i1 %.not20, label %.lr.ph28._crit_edge, label %31

.lr.ph28._crit_edge:                              ; preds = %.lr.ph28
  %.pre44 = add nuw nsw i32 %.027, 1
  br label %37

31:                                               ; preds = %.lr.ph28
  br i1 %.01526, label %32, label %34

32:                                               ; preds = %31
  %33 = tail call i32 @putchar(i32 noundef 32)
  br label %34

34:                                               ; preds = %31, %32
  %35 = add nuw nsw i32 %.027, 1
  %36 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %35)
  %.pre = load i32, ptr @ans, align 4, !tbaa !5
  %.pre42 = load i32, ptr @n, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %.lr.ph28._crit_edge, %34
  %.pre-phi45 = phi i32 [ %.pre44, %.lr.ph28._crit_edge ], [ %35, %34 ]
  %38 = phi i32 [ %27, %.lr.ph28._crit_edge ], [ %.pre42, %34 ]
  %39 = phi i32 [ %28, %.lr.ph28._crit_edge ], [ %.pre, %34 ]
  %.2 = phi i1 [ %.01526, %.lr.ph28._crit_edge ], [ true, %34 ]
  %40 = icmp slt i32 %.pre-phi45, %38
  br i1 %40, label %.lr.ph28, label %._crit_edge29, !llvm.loop !13

41:                                               ; preds = %._crit_edge29, %24
  %42 = load i32, ptr @t, align 4, !tbaa !5
  %43 = add nsw i32 %42, -1
  store i32 %43, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %42, 0
  br i1 %.not, label %._crit_edge33, label %.lr.ph32, !llvm.loop !14

._crit_edge33:                                    ; preds = %41, %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: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #2

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

; 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" }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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" }

!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, !11}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.unswitch.partial.disable"}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass