; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2015-16/Jan 2016/Silver/16 Jan S3.ll (Z5startii)

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

@visit = external dso_local global [2001 x [2001 x i8]], align 16
@xs = external dso_local global [4 x i32], align 16
@ys = external dso_local global [4 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z2okii(i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z2neiii(i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5startii(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [2001 x [2001 x i8]], ptr @visit, i64 0, i64 %7
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [2001 x i8], ptr %8, i64 0, i64 %10
  store i8 1, ptr %11, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %51, %2
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = icmp slt i32 %13, 4
  br i1 %14, label %16, label %15

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

16:                                               ; preds = %12
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [4 x i32], ptr @xs, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = add nsw i32 %17, %21
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [4 x i32], ptr @ys, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = add nsw i32 %23, %27
  %29 = call noundef i32 @_Z2okii(i32 noundef %22, i32 noundef %28)
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %50

31:                                               ; preds = %16
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = call noundef i32 @_Z2neiii(i32 noundef %32, i32 noundef %33, i32 noundef %34)
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %50

37:                                               ; preds = %31
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [4 x i32], ptr @xs, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = add nsw i32 %38, %42
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [4 x i32], ptr @ys, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = add nsw i32 %44, %48
  call void @_Z5startii(i32 noundef %43, i32 noundef %49)
  br label %50

50:                                               ; preds = %37, %31, %16
  br label %51

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

54:                                               ; preds = %15
  ret void
}

; 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

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 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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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

@visit = external dso_local local_unnamed_addr global [2001 x [2001 x i8]], align 16
@xs = external dso_local local_unnamed_addr global [4 x i32], align 16
@ys = external dso_local local_unnamed_addr global [4 x i32], align 16

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5startii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %52, %2
  %.tr = phi i32 [ %0, %2 ], [ %54, %52 ]
  %.tr18 = phi i32 [ %1, %2 ], [ %56, %52 ]
  %3 = sext i32 %.tr to i64
  %4 = sext i32 %.tr18 to i64
  %5 = getelementptr inbounds [2001 x [2001 x i8]], ptr @visit, i64 0, i64 %3, i64 %4
  store i8 1, ptr %5, align 1, !tbaa !5
  %6 = load i32, ptr @xs, align 16, !tbaa !9
  %7 = add nsw i32 %6, %.tr
  %8 = load i32, ptr @ys, align 16, !tbaa !9
  %9 = add nsw i32 %8, %.tr18
  %10 = tail call noundef i32 @_Z2okii(i32 noundef %7, i32 noundef %9)
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %18, label %11

11:                                               ; preds = %tailrecurse
  %12 = tail call noundef i32 @_Z2neiii(i32 noundef %.tr, i32 noundef %.tr18, i32 noundef 0)
  %.not15 = icmp eq i32 %12, 0
  br i1 %.not15, label %18, label %13

13:                                               ; preds = %11
  %14 = load i32, ptr @xs, align 16, !tbaa !9
  %15 = add nsw i32 %14, %.tr
  %16 = load i32, ptr @ys, align 16, !tbaa !9
  %17 = add nsw i32 %16, %.tr18
  tail call void @_Z5startii(i32 noundef %15, i32 noundef %17)
  br label %18

18:                                               ; preds = %tailrecurse, %11, %13
  %19 = load i32, ptr getelementptr inbounds (i8, ptr @xs, i64 4), align 4, !tbaa !9
  %20 = add nsw i32 %19, %.tr
  %21 = load i32, ptr getelementptr inbounds (i8, ptr @ys, i64 4), align 4, !tbaa !9
  %22 = add nsw i32 %21, %.tr18
  %23 = tail call noundef i32 @_Z2okii(i32 noundef %20, i32 noundef %22)
  %.not.1 = icmp eq i32 %23, 0
  br i1 %.not.1, label %31, label %24

24:                                               ; preds = %18
  %25 = tail call noundef i32 @_Z2neiii(i32 noundef %.tr, i32 noundef %.tr18, i32 noundef 1)
  %.not15.1 = icmp eq i32 %25, 0
  br i1 %.not15.1, label %31, label %26

26:                                               ; preds = %24
  %27 = load i32, ptr getelementptr inbounds (i8, ptr @xs, i64 4), align 4, !tbaa !9
  %28 = add nsw i32 %27, %.tr
  %29 = load i32, ptr getelementptr inbounds (i8, ptr @ys, i64 4), align 4, !tbaa !9
  %30 = add nsw i32 %29, %.tr18
  tail call void @_Z5startii(i32 noundef %28, i32 noundef %30)
  br label %31

31:                                               ; preds = %26, %24, %18
  %32 = load i32, ptr getelementptr inbounds (i8, ptr @xs, i64 8), align 8, !tbaa !9
  %33 = add nsw i32 %32, %.tr
  %34 = load i32, ptr getelementptr inbounds (i8, ptr @ys, i64 8), align 8, !tbaa !9
  %35 = add nsw i32 %34, %.tr18
  %36 = tail call noundef i32 @_Z2okii(i32 noundef %33, i32 noundef %35)
  %.not.2 = icmp eq i32 %36, 0
  br i1 %.not.2, label %44, label %37

37:                                               ; preds = %31
  %38 = tail call noundef i32 @_Z2neiii(i32 noundef %.tr, i32 noundef %.tr18, i32 noundef 2)
  %.not15.2 = icmp eq i32 %38, 0
  br i1 %.not15.2, label %44, label %39

39:                                               ; preds = %37
  %40 = load i32, ptr getelementptr inbounds (i8, ptr @xs, i64 8), align 8, !tbaa !9
  %41 = add nsw i32 %40, %.tr
  %42 = load i32, ptr getelementptr inbounds (i8, ptr @ys, i64 8), align 8, !tbaa !9
  %43 = add nsw i32 %42, %.tr18
  tail call void @_Z5startii(i32 noundef %41, i32 noundef %43)
  br label %44

44:                                               ; preds = %39, %37, %31
  %45 = load i32, ptr getelementptr inbounds (i8, ptr @xs, i64 12), align 4, !tbaa !9
  %46 = add nsw i32 %45, %.tr
  %47 = load i32, ptr getelementptr inbounds (i8, ptr @ys, i64 12), align 4, !tbaa !9
  %48 = add nsw i32 %47, %.tr18
  %49 = tail call noundef i32 @_Z2okii(i32 noundef %46, i32 noundef %48)
  %.not.3 = icmp eq i32 %49, 0
  br i1 %.not.3, label %57, label %50

50:                                               ; preds = %44
  %51 = tail call noundef i32 @_Z2neiii(i32 noundef %.tr, i32 noundef %.tr18, i32 noundef 3)
  %.not15.3 = icmp eq i32 %51, 0
  br i1 %.not15.3, label %57, label %52

52:                                               ; preds = %50
  %53 = load i32, ptr getelementptr inbounds (i8, ptr @xs, i64 12), align 4, !tbaa !9
  %54 = add nsw i32 %53, %.tr
  %55 = load i32, ptr getelementptr inbounds (i8, ptr @ys, i64 12), align 4, !tbaa !9
  %56 = add nsw i32 %55, %.tr18
  br label %tailrecurse

57:                                               ; preds = %50, %44
  ret void
}

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

!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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass