; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/122 Division 1/Problem A/A.ll (Z3dfsii)

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

@v = external dso_local global [50 x [50 x i32]], align 16
@cnt = external dso_local global i32, align 4

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsii(i32 noundef %0, i32 noundef %1) #1 {
  %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 [50 x [50 x i32]], ptr @v, i64 0, i64 %6
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [50 x i32], ptr %7, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = icmp eq i32 %11, 1
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  br label %59

14:                                               ; preds = %2
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [50 x [50 x i32]], ptr @v, i64 0, i64 %16
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [50 x i32], ptr %17, i64 0, i64 %19
  store i32 1, ptr %20, align 4, !tbaa !5
  %21 = load i32, ptr @cnt, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr @cnt, align 4, !tbaa !5
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = call noundef zeroext i1 @_Z7inrangeii(i32 noundef %24, i32 noundef %25)
  br i1 %26, label %27, label %31

27:                                               ; preds = %14
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  %30 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %29, i32 noundef %30)
  br label %31

31:                                               ; preds = %27, %14
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = sub nsw i32 %32, 1
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = call noundef zeroext i1 @_Z7inrangeii(i32 noundef %33, i32 noundef %34)
  br i1 %35, label %36, label %40

36:                                               ; preds = %31
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = sub nsw i32 %37, 1
  %39 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %38, i32 noundef %39)
  br label %40

40:                                               ; preds = %36, %31
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  %44 = call noundef zeroext i1 @_Z7inrangeii(i32 noundef %41, i32 noundef %43)
  br i1 %44, label %45, label %49

45:                                               ; preds = %40
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  call void @_Z3dfsii(i32 noundef %46, i32 noundef %48)
  br label %49

49:                                               ; preds = %45, %40
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = sub nsw i32 %51, 1
  %53 = call noundef zeroext i1 @_Z7inrangeii(i32 noundef %50, i32 noundef %52)
  br i1 %53, label %54, label %58

54:                                               ; preds = %49
  %55 = load i32, ptr %3, align 4, !tbaa !5
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = sub nsw i32 %56, 1
  call void @_Z3dfsii(i32 noundef %55, i32 noundef %57)
  br label %58

58:                                               ; preds = %54, %49
  br label %59

59:                                               ; preds = %58, %13
  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" }
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" }

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

@v = external dso_local local_unnamed_addr global [50 x [50 x i32]], align 16
@cnt = external dso_local local_unnamed_addr global i32, align 4

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %0 to i64
  %4 = add nsw i32 %0, 1
  %5 = add nsw i32 %0, -1
  %6 = sext i32 %1 to i64
  br label %tailrecurse

tailrecurse:                                      ; preds = %24, %2
  %indvars.iv = phi i64 [ %indvars.iv.next, %24 ], [ %6, %2 ]
  %7 = getelementptr inbounds [50 x [50 x i32]], ptr @v, i64 0, i64 %3, i64 %indvars.iv
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = icmp eq i32 %8, 1
  br i1 %9, label %27, label %10

10:                                               ; preds = %tailrecurse
  store i32 1, ptr %7, align 4, !tbaa !5
  %11 = load i32, ptr @cnt, align 4, !tbaa !5
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr @cnt, align 4, !tbaa !5
  %13 = trunc nsw i64 %indvars.iv to i32
  %14 = tail call noundef zeroext i1 @_Z7inrangeii(i32 noundef %4, i32 noundef %13)
  br i1 %14, label %15, label %16

15:                                               ; preds = %10
  tail call void @_Z3dfsii(i32 noundef %4, i32 noundef %13)
  br label %16

16:                                               ; preds = %15, %10
  %17 = tail call noundef zeroext i1 @_Z7inrangeii(i32 noundef %5, i32 noundef %13)
  br i1 %17, label %18, label %19

18:                                               ; preds = %16
  tail call void @_Z3dfsii(i32 noundef %5, i32 noundef %13)
  br label %19

19:                                               ; preds = %18, %16
  %20 = trunc i64 %indvars.iv to i32
  %21 = add i32 %20, 1
  %22 = tail call noundef zeroext i1 @_Z7inrangeii(i32 noundef %0, i32 noundef %21)
  br i1 %22, label %23, label %24

23:                                               ; preds = %19
  tail call void @_Z3dfsii(i32 noundef %0, i32 noundef %21)
  br label %24

24:                                               ; preds = %23, %19
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %25 = trunc nsw i64 %indvars.iv.next to i32
  %26 = tail call noundef zeroext i1 @_Z7inrangeii(i32 noundef %0, i32 noundef %25)
  br i1 %26, label %tailrecurse, label %27

27:                                               ; preds = %24, %tailrecurse
  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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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