; LLVM IR from tangjz/acm-icpc :: TDL_training/2015-11-27 (H - Machine - dby)

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

@w = external dso_local global [10030 x i32], align 16
@f = external dso_local global [10030 x i32], align 16
@tot = external dso_local global [10030 x i32], align 16
@son = external dso_local global [10030 x [2 x i32]], align 16
@n = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4readRi(ptr noundef nonnull align 4 dereferenceable(4)) #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 i32, align 4
  store i32 0, ptr %1, align 4
  br label %6

6:                                                ; preds = %112, %0
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %8 = icmp ne i32 %7, -1
  br i1 %8, label %9, label %115

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

10:                                               ; preds = %22, %9
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = icmp sle i32 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %25

15:                                               ; preds = %10
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [10030 x i32], ptr @f, i64 0, i64 %17
  call void @_Z4readRi(ptr noundef nonnull align 4 dereferenceable(4) %18)
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [10030 x i32], ptr @tot, i64 0, i64 %20
  store i32 0, ptr %21, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %15
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %2, align 4, !tbaa !5
  br label %10, !llvm.loop !9

25:                                               ; preds = %14
  store i32 0, ptr getelementptr inbounds ([10030 x i32], ptr @tot, i64 0, i64 1), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  %26 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %26, ptr %3, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %109, %25
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = icmp sge i32 %28, 1
  br i1 %29, label %31, label %30

30:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %112

31:                                               ; preds = %27
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [10030 x i32], ptr @tot, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %41

37:                                               ; preds = %31
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [10030 x i32], ptr @w, i64 0, i64 %39
  store i32 1, ptr %40, align 4, !tbaa !5
  br label %88

41:                                               ; preds = %31
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [10030 x i32], ptr @tot, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = icmp eq i32 %45, 1
  br i1 %46, label %47, label %56

47:                                               ; preds = %41
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [10030 x [2 x i32]], ptr @son, i64 0, i64 %49
  %51 = getelementptr inbounds [2 x i32], ptr %50, i64 0, i64 0
  %52 = load i32, ptr %51, align 8, !tbaa !5
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [10030 x i32], ptr @w, i64 0, i64 %54
  store i32 %52, ptr %55, align 4, !tbaa !5
  br label %87

56:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %57 = load i32, ptr %3, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [10030 x [2 x i32]], ptr @son, i64 0, i64 %58
  %60 = getelementptr inbounds [2 x i32], ptr %59, i64 0, i64 0
  %61 = load i32, ptr %60, align 8, !tbaa !5
  store i32 %61, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %62 = load i32, ptr %3, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [10030 x [2 x i32]], ptr @son, i64 0, i64 %63
  %65 = getelementptr inbounds [2 x i32], ptr %64, i64 0, i64 1
  %66 = load i32, ptr %65, align 4, !tbaa !5
  store i32 %66, ptr %5, align 4, !tbaa !5
  %67 = load i32, ptr %4, align 4, !tbaa !5
  %68 = load i32, ptr %5, align 4, !tbaa !5
  %69 = icmp sgt i32 %67, %68
  br i1 %69, label %70, label %78

70:                                               ; preds = %56
  %71 = load i32, ptr %5, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = call noundef i32 @_Z3maxii(i32 noundef %72, i32 noundef %73)
  %75 = load i32, ptr %3, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [10030 x i32], ptr @w, i64 0, i64 %76
  store i32 %74, ptr %77, align 4, !tbaa !5
  br label %86

78:                                               ; preds = %56
  %79 = load i32, ptr %4, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  %81 = load i32, ptr %5, align 4, !tbaa !5
  %82 = call noundef i32 @_Z3maxii(i32 noundef %80, i32 noundef %81)
  %83 = load i32, ptr %3, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [10030 x i32], ptr @w, i64 0, i64 %84
  store i32 %82, ptr %85, align 4, !tbaa !5
  br label %86

86:                                               ; preds = %78, %70
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %87

87:                                               ; preds = %86, %47
  br label %88

88:                                               ; preds = %87, %37
  %89 = load i32, ptr %3, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [10030 x i32], ptr @w, i64 0, i64 %90
  %92 = load i32, ptr %91, align 4, !tbaa !5
  %93 = load i32, ptr %3, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [10030 x i32], ptr @f, i64 0, i64 %94
  %96 = load i32, ptr %95, align 4, !tbaa !5
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [10030 x [2 x i32]], ptr @son, i64 0, i64 %97
  %99 = load i32, ptr %3, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [10030 x i32], ptr @f, i64 0, i64 %100
  %102 = load i32, ptr %101, align 4, !tbaa !5
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds [10030 x i32], ptr @tot, i64 0, i64 %103
  %105 = load i32, ptr %104, align 4, !tbaa !5
  %106 = add nsw i32 %105, 1
  store i32 %106, ptr %104, align 4, !tbaa !5
  %107 = sext i32 %105 to i64
  %108 = getelementptr inbounds [2 x i32], ptr %98, i64 0, i64 %107
  store i32 %92, ptr %108, align 4, !tbaa !5
  br label %109

109:                                              ; preds = %88
  %110 = load i32, ptr %3, align 4, !tbaa !5
  %111 = add nsw i32 %110, -1
  store i32 %111, ptr %3, align 4, !tbaa !5
  br label %27, !llvm.loop !11

112:                                              ; preds = %30
  %113 = load i32, ptr getelementptr inbounds ([10030 x i32], ptr @w, i64 0, i64 1), align 4, !tbaa !5
  %114 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %113)
  br label %6, !llvm.loop !12

115:                                              ; preds = %6
  ret i32 0
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3maxii(i32 noundef, i32 noundef) #4

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 = { inlinehint 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 #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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !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"

@w = external dso_local local_unnamed_addr global [10030 x i32], align 16
@f = external dso_local global [10030 x i32], align 16
@tot = external dso_local local_unnamed_addr global [10030 x i32], align 16
@son = external dso_local local_unnamed_addr global [10030 x [2 x i32]], align 16
@n = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4readRi(ptr noundef nonnull align 4 dereferenceable(4)) 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)
  %.not36 = icmp eq i32 %1, -1
  br i1 %.not36, label %._crit_edge37, label %.preheader

.preheader:                                       ; preds = %0, %._crit_edge35
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not2930 = icmp slt i32 %2, 2
  br i1 %.not2930, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.lcssa = phi i32 [ %2, %.preheader ], [ %7, %.lr.ph ]
  store i32 0, ptr getelementptr inbounds (i8, ptr @tot, i64 4), align 4, !tbaa !5
  %3 = icmp sgt i32 %.lcssa, 0
  br i1 %3, label %.lr.ph34.preheader, label %._crit_edge35

.lr.ph34.preheader:                               ; preds = %._crit_edge
  %4 = zext nneg i32 %.lcssa to i64
  br label %.lr.ph34

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 2, %.preheader ]
  %5 = getelementptr inbounds [10030 x i32], ptr @f, i64 0, i64 %indvars.iv
  tail call void @_Z4readRi(ptr noundef nonnull align 4 dereferenceable(4) %5)
  %6 = getelementptr inbounds [10030 x i32], ptr @tot, i64 0, i64 %indvars.iv
  store i32 0, ptr %6, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %.not29.not = icmp slt i64 %indvars.iv, %8
  br i1 %.not29.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge35:                                    ; preds = %33, %._crit_edge
  %9 = load i32, ptr getelementptr inbounds (i8, ptr @w, i64 4), align 4, !tbaa !5
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %9)
  %11 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %.not = icmp eq i32 %11, -1
  br i1 %.not, label %._crit_edge37, label %.preheader, !llvm.loop !11

.lr.ph34:                                         ; preds = %.lr.ph34.preheader, %33
  %indvars.iv40 = phi i64 [ %4, %.lr.ph34.preheader ], [ %indvars.iv.next41, %33 ]
  %12 = getelementptr inbounds [10030 x i32], ptr @tot, i64 0, i64 %indvars.iv40
  %13 = load i32, ptr %12, align 4, !tbaa !5
  switch i32 %13, label %20 [
    i32 0, label %14
    i32 1, label %16
  ]

14:                                               ; preds = %.lr.ph34
  %15 = getelementptr inbounds [10030 x i32], ptr @w, i64 0, i64 %indvars.iv40
  store i32 1, ptr %15, align 4, !tbaa !5
  br label %33

16:                                               ; preds = %.lr.ph34
  %17 = getelementptr inbounds [10030 x [2 x i32]], ptr @son, i64 0, i64 %indvars.iv40
  %18 = load i32, ptr %17, align 8, !tbaa !5
  %19 = getelementptr inbounds [10030 x i32], ptr @w, i64 0, i64 %indvars.iv40
  store i32 %18, ptr %19, align 4, !tbaa !5
  br label %33

20:                                               ; preds = %.lr.ph34
  %21 = getelementptr inbounds [10030 x [2 x i32]], ptr @son, i64 0, i64 %indvars.iv40
  %22 = load i32, ptr %21, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %21, i64 4
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = icmp sgt i32 %22, %24
  %26 = getelementptr inbounds [10030 x i32], ptr @w, i64 0, i64 %indvars.iv40
  br i1 %25, label %27, label %30

27:                                               ; preds = %20
  %28 = add nsw i32 %24, 1
  %29 = tail call noundef i32 @_Z3maxii(i32 noundef %28, i32 noundef %22)
  store i32 %29, ptr %26, align 4, !tbaa !5
  br label %33

30:                                               ; preds = %20
  %31 = add nsw i32 %22, 1
  %32 = tail call noundef i32 @_Z3maxii(i32 noundef %31, i32 noundef %24)
  store i32 %32, ptr %26, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %27, %30, %16, %14
  %34 = phi i32 [ %29, %27 ], [ %32, %30 ], [ %18, %16 ], [ 1, %14 ]
  %35 = getelementptr inbounds [10030 x i32], ptr @f, i64 0, i64 %indvars.iv40
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [10030 x i32], ptr @tot, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %38, align 4, !tbaa !5
  %41 = sext i32 %39 to i64
  %42 = getelementptr inbounds [10030 x [2 x i32]], ptr @son, i64 0, i64 %37, i64 %41
  store i32 %34, ptr %42, align 4, !tbaa !5
  %indvars.iv.next41 = add nsw i64 %indvars.iv40, -1
  %43 = icmp sgt i64 %indvars.iv40, 1
  br i1 %43, label %.lr.ph34, label %._crit_edge35, !llvm.loop !12

._crit_edge37:                                    ; preds = %._crit_edge35, %0
  ret i32 0
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3maxii(i32 noundef, i32 noundef) local_unnamed_addr #3

; 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 = { inlinehint 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" }

!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}


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