; LLVM IR from tangjz/acm-icpc :: Summer_Training/2016-07-17 (B - Constructing Chimney - liuzy)

; 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
@T = external dso_local global i32, align 4
@status = external dso_local global [4 x [4 x i32]], align 16
@mask = external dso_local global [4 x [4 x i32]], align 16
@B = external dso_local global [300 x [300 x i32]], align 16
@init = external dso_local global [4 x [4 x i32]], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3DFSiii(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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z10quickPoweri(i32 noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z5floydv() #3

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

5:                                                ; preds = %43, %0
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 256
  br i1 %7, label %8, label %46

8:                                                ; preds = %5
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %38, %8
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = icmp sle i32 %10, 3
  br i1 %11, label %12, label %41

12:                                               ; preds = %9
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %34, %12
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = icmp sle i32 %14, 3
  br i1 %15, label %16, label %37

16:                                               ; preds = %13
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [4 x [4 x i32]], ptr @mask, i64 0, i64 %18
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [4 x i32], ptr %19, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = and i32 %23, %24
  %26 = icmp ne i32 %25, 0
  %27 = zext i1 %26 to i32
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [4 x [4 x i32]], ptr @status, i64 0, i64 %29
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [4 x i32], ptr %30, i64 0, i64 %32
  store i32 %27, ptr %33, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %16
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %4, align 4, !tbaa !5
  br label %13, !llvm.loop !9

37:                                               ; preds = %13
  br label %38

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

41:                                               ; preds = %9
  store i32 1, ptr getelementptr inbounds ([4 x i32], ptr getelementptr inbounds ([4 x [4 x i32]], ptr @status, i64 0, i64 2), i64 0, i64 2), align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 @init, ptr align 16 @status, i64 64, i1 false)
  %42 = load i32, ptr %2, align 4, !tbaa !5
  call void @_Z3DFSiii(i32 noundef %42, i32 noundef 1, i32 noundef 1)
  br label %43

43:                                               ; preds = %41
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %2, align 4, !tbaa !5
  br label %5, !llvm.loop !12

46:                                               ; preds = %5
  call void @_Z5floydv()
  %47 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @T)
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %58, %46
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = load i32, ptr @T, align 4, !tbaa !5
  %51 = icmp sle i32 %49, %50
  br i1 %51, label %52, label %61

52:                                               ; preds = %48
  %53 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @N)
  %54 = load i32, ptr @N, align 4, !tbaa !5
  call void @_Z10quickPoweri(i32 noundef %54)
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = load i32, ptr @B, align 16, !tbaa !5
  %57 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %55, i32 noundef %56)
  br label %58

58:                                               ; preds = %52
  %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 %48, !llvm.loop !13

61:                                               ; preds = %48
  call void @exit(i32 noundef 0) #8
  unreachable
}

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

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #6

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 #5 = { "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 = { noreturn 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 #7 = { nounwind }
attributes #8 = { noreturn 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 = distinct !{!12, !10}
!13 = distinct !{!13, !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"

@N = external dso_local global i32, align 4
@T = external dso_local global i32, align 4
@status = external dso_local local_unnamed_addr global [4 x [4 x i32]], align 16
@mask = external dso_local local_unnamed_addr global [4 x [4 x i32]], align 16
@B = external dso_local local_unnamed_addr global [300 x [300 x i32]], align 16
@init = external dso_local local_unnamed_addr global [4 x [4 x i32]], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z10quickPoweri(i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z5floydv() local_unnamed_addr #2

; Function Attrs: mustprogress norecurse noreturn uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 {
  br label %.preheader17

.preheader17:                                     ; preds = %0, %.preheader17
  %.01620 = phi i32 [ 0, %0 ], [ %27, %.preheader17 ]
  %1 = load <2 x i32>, ptr getelementptr inbounds (i8, ptr @mask, i64 20), align 4, !tbaa !5
  %2 = insertelement <2 x i32> poison, i32 %.01620, i64 0
  %3 = shufflevector <2 x i32> %2, <2 x i32> poison, <2 x i32> zeroinitializer
  %4 = and <2 x i32> %1, %3
  %5 = icmp ne <2 x i32> %4, zeroinitializer
  %6 = zext <2 x i1> %5 to <2 x i32>
  store <2 x i32> %6, ptr getelementptr inbounds (i8, ptr @status, i64 20), align 4, !tbaa !5
  %7 = load i32, ptr getelementptr inbounds (i8, ptr @mask, i64 28), align 4, !tbaa !5
  %8 = and i32 %7, %.01620
  %9 = icmp ne i32 %8, 0
  %10 = zext i1 %9 to i32
  store i32 %10, ptr getelementptr inbounds (i8, ptr @status, i64 28), align 4, !tbaa !5
  %11 = load i32, ptr getelementptr inbounds (i8, ptr @mask, i64 36), align 4, !tbaa !5
  %12 = and i32 %11, %.01620
  %13 = icmp ne i32 %12, 0
  %14 = zext i1 %13 to i32
  store i32 %14, ptr getelementptr inbounds (i8, ptr @status, i64 36), align 4, !tbaa !5
  %15 = load i32, ptr getelementptr inbounds (i8, ptr @mask, i64 44), align 4, !tbaa !5
  %16 = and i32 %15, %.01620
  %17 = icmp ne i32 %16, 0
  %18 = zext i1 %17 to i32
  store i32 %18, ptr getelementptr inbounds (i8, ptr @status, i64 44), align 4, !tbaa !5
  %19 = load <2 x i32>, ptr getelementptr inbounds (i8, ptr @mask, i64 52), align 4, !tbaa !5
  %20 = and <2 x i32> %19, %3
  %21 = icmp ne <2 x i32> %20, zeroinitializer
  %22 = zext <2 x i1> %21 to <2 x i32>
  store <2 x i32> %22, ptr getelementptr inbounds (i8, ptr @status, i64 52), align 4, !tbaa !5
  %23 = load i32, ptr getelementptr inbounds (i8, ptr @mask, i64 60), align 4, !tbaa !5
  %24 = and i32 %23, %.01620
  %25 = icmp ne i32 %24, 0
  %26 = zext i1 %25 to i32
  store i32 %26, ptr getelementptr inbounds (i8, ptr @status, i64 60), align 4, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @status, i64 40), align 8, !tbaa !5
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(64) @init, ptr noundef nonnull align 16 dereferenceable(64) @status, i64 64, i1 false)
  tail call void @_Z3DFSiii(i32 noundef %.01620, i32 noundef 1, i32 noundef 1)
  %27 = add nuw nsw i32 %.01620, 1
  %exitcond.not = icmp eq i32 %27, 256
  br i1 %exitcond.not, label %28, label %.preheader17, !llvm.loop !9

28:                                               ; preds = %.preheader17
  tail call void @_Z5floydv()
  %29 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @T)
  %30 = load i32, ptr @T, align 4, !tbaa !5
  %.not21 = icmp slt i32 %30, 1
  br i1 %.not21, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %28, %.lr.ph
  %.122 = phi i32 [ %35, %.lr.ph ], [ 1, %28 ]
  %31 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @N)
  %32 = load i32, ptr @N, align 4, !tbaa !5
  tail call void @_Z10quickPoweri(i32 noundef %32)
  %33 = load i32, ptr @B, align 16, !tbaa !5
  %34 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.122, i32 noundef %33)
  %35 = add nuw nsw i32 %.122, 1
  %36 = load i32, ptr @T, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.122, %36
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %28
  tail call void @exit(i32 noundef 0) #6
  unreachable
}

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

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #5

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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { mustprogress norecurse noreturn 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 = { 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 #5 = { noreturn 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 #6 = { noreturn 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}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass