; LLVM IR from AnneLivia/Competitive-Programming :: Online Judges/URI/Torre (OBI 2015)/main.ll (Z11runningVertii)

; 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
@vet = external dso_local global [1001 x [1001 x i32]], align 16
@sum = external dso_local global i32, align 4
@visited = external dso_local global [1001 x [1001 x i32]], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z11runningVertii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %5 = load i32, ptr %3, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds [1001 x [1001 x i32]], ptr @visited, i64 0, i64 %6
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [1001 x i32], ptr %7, i64 0, i64 %9
  store i32 1, ptr %10, align 4, !tbaa !5
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [1001 x [1001 x i32]], ptr @vet, i64 0, i64 %12
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [1001 x i32], ptr %13, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = load i32, ptr @sum, align 4, !tbaa !5
  %19 = add nsw i32 %18, %17
  store i32 %19, ptr @sum, align 4, !tbaa !5
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = sub nsw i32 %20, 1
  %22 = icmp sge i32 %21, 0
  br i1 %22, label %23, label %37

23:                                               ; preds = %2
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = sub nsw i32 %24, 1
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [1001 x [1001 x i32]], ptr @visited, i64 0, i64 %26
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [1001 x i32], ptr %27, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %37, label %33

33:                                               ; preds = %23
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = sub nsw i32 %34, 1
  %36 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z11runningVertii(i32 noundef %35, i32 noundef %36)
  br label %37

37:                                               ; preds = %33, %23, %2
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  %40 = load i32, ptr @n, align 4, !tbaa !5
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %42, label %56

42:                                               ; preds = %37
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [1001 x [1001 x i32]], ptr @visited, i64 0, i64 %45
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [1001 x i32], ptr %46, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %56, label %52

52:                                               ; preds = %42
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  %55 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z11runningVertii(i32 noundef %54, i32 noundef %55)
  br label %56

56:                                               ; preds = %52, %42, %37
  ret void
}

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

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


; 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 local_unnamed_addr global i32, align 4
@vet = external dso_local local_unnamed_addr global [1001 x [1001 x i32]], align 16
@sum = external dso_local local_unnamed_addr global i32, align 4
@visited = external dso_local local_unnamed_addr global [1001 x [1001 x i32]], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z11runningVertii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %1 to i64
  %4 = sext i32 %0 to i64
  %.pre18 = load i32, ptr @sum, align 4, !tbaa !5
  br label %tailrecurse

tailrecurse:                                      ; preds = %22, %2
  %5 = phi i32 [ %18, %22 ], [ %.pre18, %2 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %22 ], [ %4, %2 ]
  %6 = getelementptr inbounds [1001 x [1001 x i32]], ptr @visited, i64 0, i64 %indvars.iv, i64 %3
  store i32 1, ptr %6, align 4, !tbaa !5
  %7 = getelementptr inbounds [1001 x [1001 x i32]], ptr @vet, i64 0, i64 %indvars.iv, i64 %3
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = add nsw i32 %5, %8
  store i32 %9, ptr @sum, align 4, !tbaa !5
  %10 = add nsw i64 %indvars.iv, -1
  %11 = icmp sgt i64 %indvars.iv, 0
  br i1 %11, label %12, label %17

12:                                               ; preds = %tailrecurse
  %13 = getelementptr inbounds [1001 x [1001 x i32]], ptr @visited, i64 0, i64 %10, i64 %3
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %.not = icmp eq i32 %14, 0
  br i1 %.not, label %15, label %17

15:                                               ; preds = %12
  %16 = trunc nsw i64 %10 to i32
  tail call void @_Z11runningVertii(i32 noundef %16, i32 noundef %1)
  %.pre = load i32, ptr @sum, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %15, %12, %tailrecurse
  %18 = phi i32 [ %.pre, %15 ], [ %9, %12 ], [ %9, %tailrecurse ]
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = icmp slt i64 %indvars.iv.next, %20
  br i1 %21, label %22, label %25

22:                                               ; preds = %17
  %23 = getelementptr inbounds [1001 x [1001 x i32]], ptr @visited, i64 0, i64 %indvars.iv.next, i64 %3
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %.not15 = icmp eq i32 %24, 0
  br i1 %.not15, label %tailrecurse, label %25

25:                                               ; preds = %22, %17
  ret void
}

attributes #0 = { mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InstCombinePass,LICMPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass