; LLVM IR from tangjz/acm-icpc :: self_training/2015-02-15 (B)

; 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
@x = external dso_local global [500 x i32], align 16
@y = external dso_local global [500 x i32], align 16
@ans = external dso_local global i32, align 4
@xpos = external dso_local global i32, align 4
@ypos = 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 [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

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

7:                                                ; preds = %20, %0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = icmp slt i32 %8, %9
  br i1 %10, label %12, label %11

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

12:                                               ; preds = %7
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i32, ptr @x, i64 %14
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds i32, ptr @y, i64 %17
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %15, ptr noundef %18)
  br label %20

20:                                               ; preds = %12
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !9

23:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %24

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

28:                                               ; preds = %24
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %129

29:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %5, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %122, %29
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = load i32, ptr @n, align 4, !tbaa !5
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %32
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %125

37:                                               ; preds = %32
  %38 = load i32, ptr @ans, align 4, !tbaa !5
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [500 x i32], ptr @x, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [500 x i32], ptr @x, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = sub nsw i32 %42, %46
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [500 x i32], ptr @x, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [500 x i32], ptr @x, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = sub nsw i32 %51, %55
  %57 = mul nsw i32 %47, %56
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [500 x i32], ptr @y, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [500 x i32], ptr @y, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = sub nsw i32 %61, %65
  %67 = load i32, ptr %3, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [500 x i32], ptr @y, i64 0, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !5
  %71 = load i32, ptr %5, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [500 x i32], ptr @y, i64 0, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !5
  %75 = sub nsw i32 %70, %74
  %76 = mul nsw i32 %66, %75
  %77 = add nsw i32 %57, %76
  %78 = icmp slt i32 %38, %77
  br i1 %78, label %79, label %121

79:                                               ; preds = %37
  %80 = load i32, ptr %3, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [500 x i32], ptr @x, i64 0, i64 %81
  %83 = load i32, ptr %82, align 4, !tbaa !5
  %84 = load i32, ptr %5, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [500 x i32], ptr @x, i64 0, i64 %85
  %87 = load i32, ptr %86, align 4, !tbaa !5
  %88 = sub nsw i32 %83, %87
  %89 = load i32, ptr %3, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [500 x i32], ptr @x, i64 0, i64 %90
  %92 = load i32, ptr %91, align 4, !tbaa !5
  %93 = load i32, ptr %5, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [500 x i32], ptr @x, i64 0, i64 %94
  %96 = load i32, ptr %95, align 4, !tbaa !5
  %97 = sub nsw i32 %92, %96
  %98 = mul nsw i32 %88, %97
  %99 = load i32, ptr %3, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [500 x i32], ptr @y, i64 0, i64 %100
  %102 = load i32, ptr %101, align 4, !tbaa !5
  %103 = load i32, ptr %5, align 4, !tbaa !5
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [500 x i32], ptr @y, i64 0, i64 %104
  %106 = load i32, ptr %105, align 4, !tbaa !5
  %107 = sub nsw i32 %102, %106
  %108 = load i32, ptr %3, align 4, !tbaa !5
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds [500 x i32], ptr @y, i64 0, i64 %109
  %111 = load i32, ptr %110, align 4, !tbaa !5
  %112 = load i32, ptr %5, align 4, !tbaa !5
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds [500 x i32], ptr @y, i64 0, i64 %113
  %115 = load i32, ptr %114, align 4, !tbaa !5
  %116 = sub nsw i32 %111, %115
  %117 = mul nsw i32 %107, %116
  %118 = add nsw i32 %98, %117
  store i32 %118, ptr @ans, align 4, !tbaa !5
  %119 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %119, ptr @xpos, align 4, !tbaa !5
  %120 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %120, ptr @ypos, align 4, !tbaa !5
  br label %121

121:                                              ; preds = %79, %37
  br label %122

122:                                              ; preds = %121
  %123 = load i32, ptr %5, align 4, !tbaa !5
  %124 = add nsw i32 %123, 1
  store i32 %124, ptr %5, align 4, !tbaa !5
  br label %32, !llvm.loop !11

125:                                              ; preds = %36
  br label %126

126:                                              ; preds = %125
  %127 = load i32, ptr %3, align 4, !tbaa !5
  %128 = add nsw i32 %127, 1
  store i32 %128, ptr %3, align 4, !tbaa !5
  br label %24, !llvm.loop !12

129:                                              ; preds = %28
  %130 = load i32, ptr @xpos, align 4, !tbaa !5
  %131 = add nsw i32 %130, 1
  %132 = load i32, ptr @ypos, align 4, !tbaa !5
  %133 = add nsw i32 %132, 1
  %134 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %131, i32 noundef %133)
  ret i32 0
}

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

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

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

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

attributes #0 = { 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 #1 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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"

@n = external dso_local global i32, align 4
@x = external dso_local global [500 x i32], align 16
@y = external dso_local global [500 x i32], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4
@xpos = external dso_local local_unnamed_addr global i32, align 4
@ypos = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %._crit_edge

.preheader:                                       ; preds = %.lr.ph
  %4 = icmp sgt i32 %9, 0
  br i1 %4, label %.lr.ph40.preheader, label %._crit_edge

.lr.ph40.preheader:                               ; preds = %.preheader
  %ans.promoted33 = load i32, ptr @ans, align 4, !tbaa !5
  %5 = zext nneg i32 %9 to i64
  %wide.trip.count51 = zext nneg i32 %9 to i64
  br label %.lr.ph40

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %6 = getelementptr inbounds i32, ptr @x, i64 %indvars.iv
  %7 = getelementptr inbounds i32, ptr @y, i64 %indvars.iv
  %8 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %6, ptr noundef nonnull %7)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = icmp slt i64 %indvars.iv.next, %10
  br i1 %11, label %.lr.ph, label %.preheader, !llvm.loop !9

.loopexit:                                        ; preds = %37, %.lr.ph40
  %ans.promoted34 = phi i32 [ %ans.promoted3738, %.lr.ph40 ], [ %ans.promoted35, %37 ]
  %indvars.iv.next44 = add nuw nsw i64 %indvars.iv43, 1
  %exitcond52.not = icmp eq i64 %indvars.iv.next49, %wide.trip.count51
  br i1 %exitcond52.not, label %._crit_edge, label %.lr.ph40, !llvm.loop !11

._crit_edge:                                      ; preds = %.loopexit, %0, %.preheader
  %12 = load i32, ptr @xpos, align 4, !tbaa !5
  %13 = add nsw i32 %12, 1
  %14 = load i32, ptr @ypos, align 4, !tbaa !5
  %15 = add nsw i32 %14, 1
  %16 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %13, i32 noundef %15)
  ret i32 0

.lr.ph40:                                         ; preds = %.lr.ph40.preheader, %.loopexit
  %indvars.iv48 = phi i64 [ 0, %.lr.ph40.preheader ], [ %indvars.iv.next49, %.loopexit ]
  %indvars.iv43 = phi i64 [ 1, %.lr.ph40.preheader ], [ %indvars.iv.next44, %.loopexit ]
  %ans.promoted3738 = phi i32 [ %ans.promoted33, %.lr.ph40.preheader ], [ %ans.promoted34, %.loopexit ]
  %indvars.iv.next49 = add nuw nsw i64 %indvars.iv48, 1
  %17 = icmp ult i64 %indvars.iv.next49, %5
  br i1 %17, label %.lr.ph32, label %.loopexit

.lr.ph32:                                         ; preds = %.lr.ph40
  %18 = getelementptr inbounds [500 x i32], ptr @x, i64 0, i64 %indvars.iv48
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = getelementptr inbounds [500 x i32], ptr @y, i64 0, i64 %indvars.iv48
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = trunc nuw nsw i64 %indvars.iv48 to i32
  br label %23

23:                                               ; preds = %.lr.ph32, %37
  %indvars.iv45 = phi i64 [ %indvars.iv43, %.lr.ph32 ], [ %indvars.iv.next46, %37 ]
  %ans.promoted36 = phi i32 [ %ans.promoted3738, %.lr.ph32 ], [ %ans.promoted35, %37 ]
  %24 = phi i32 [ %ans.promoted3738, %.lr.ph32 ], [ %38, %37 ]
  %25 = getelementptr inbounds [500 x i32], ptr @x, i64 0, i64 %indvars.iv45
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = sub nsw i32 %19, %26
  %28 = mul nsw i32 %27, %27
  %29 = getelementptr inbounds [500 x i32], ptr @y, i64 0, i64 %indvars.iv45
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = sub nsw i32 %21, %30
  %32 = mul nsw i32 %31, %31
  %33 = add nuw nsw i32 %32, %28
  %34 = icmp slt i32 %24, %33
  br i1 %34, label %35, label %37

35:                                               ; preds = %23
  store i32 %33, ptr @ans, align 4, !tbaa !5
  store i32 %22, ptr @xpos, align 4, !tbaa !5
  %36 = trunc nuw nsw i64 %indvars.iv45 to i32
  store i32 %36, ptr @ypos, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %23, %35
  %ans.promoted35 = phi i32 [ %ans.promoted36, %23 ], [ %33, %35 ]
  %38 = phi i32 [ %24, %23 ], [ %33, %35 ]
  %indvars.iv.next46 = add nuw nsw i64 %indvars.iv45, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next46, %wide.trip.count51
  br i1 %exitcond.not, label %.loopexit, label %23, !llvm.loop !12
}

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

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

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


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