; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/346 Division 2/Problem F/F.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"

@active = external dso_local global [1002001 x i32], align 16
@taken = external dso_local global [1002001 x i32], align 16
@to_get = external dso_local global i64, align 8
@dx = external dso_local global [4 x i32], align 16
@dy = external dso_local global [4 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3getii(i32 noundef, i32 noundef) #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 nounwind uwtable
declare dso_local noundef zeroext i1 @_Z4goodii(i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsii(i32 noundef %0, i32 noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = call noundef i32 @_Z3getii(i32 noundef %8, i32 noundef %9)
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [1002001 x i32], ptr @active, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %16, label %15

15:                                               ; preds = %2
  br label %69

16:                                               ; preds = %2
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = call noundef i32 @_Z3getii(i32 noundef %17, i32 noundef %18)
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [1002001 x i32], ptr @taken, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %16
  br label %69

25:                                               ; preds = %16
  %26 = load i64, ptr @to_get, align 8, !tbaa !9
  %27 = icmp eq i64 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %25
  br label %69

29:                                               ; preds = %25
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = call noundef i32 @_Z3getii(i32 noundef %30, i32 noundef %31)
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [1002001 x i32], ptr @taken, i64 0, i64 %33
  store i32 1, ptr %34, align 4, !tbaa !5
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = call noundef i32 @_Z3getii(i32 noundef %35, i32 noundef %36)
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [1002001 x i32], ptr @active, i64 0, i64 %38
  store i32 0, ptr %39, align 4, !tbaa !5
  %40 = load i64, ptr @to_get, align 8, !tbaa !9
  %41 = add nsw i64 %40, -1
  store i64 %41, ptr @to_get, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %66, %29
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = icmp slt i32 %43, 4
  br i1 %44, label %46, label %45

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

46:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [4 x i32], ptr @dx, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = add nsw i32 %47, %51
  store i32 %52, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [4 x i32], ptr @dy, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = add nsw i32 %53, %57
  store i32 %58, ptr %7, align 4, !tbaa !5
  %59 = load i32, ptr %6, align 4, !tbaa !5
  %60 = load i32, ptr %7, align 4, !tbaa !5
  %61 = call noundef zeroext i1 @_Z4goodii(i32 noundef %59, i32 noundef %60)
  br i1 %61, label %62, label %65

62:                                               ; preds = %46
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = load i32, ptr %7, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %63, i32 noundef %64)
  br label %65

65:                                               ; preds = %62, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %5, align 4, !tbaa !5
  br label %42, !llvm.loop !11

69:                                               ; preds = %45, %28, %24, %15
  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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"long long", !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"

@active = external dso_local local_unnamed_addr global [1002001 x i32], align 16
@taken = external dso_local local_unnamed_addr global [1002001 x i32], align 16
@to_get = external dso_local local_unnamed_addr global i64, align 8
@dx = external dso_local local_unnamed_addr global [4 x i32], align 16
@dy = external dso_local local_unnamed_addr global [4 x i32], align 16

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z4goodii(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 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %44, %2
  %.tr = phi i32 [ %0, %2 ], [ %46, %44 ]
  %.tr21 = phi i32 [ %1, %2 ], [ %48, %44 ]
  %3 = tail call noundef i32 @_Z3getii(i32 noundef %.tr, i32 noundef %.tr21)
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds [1002001 x i32], ptr @active, i64 0, i64 %4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %.loopexit, label %7

7:                                                ; preds = %tailrecurse
  %8 = tail call noundef i32 @_Z3getii(i32 noundef %.tr, i32 noundef %.tr21)
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [1002001 x i32], ptr @taken, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = icmp ne i32 %11, 0
  %13 = load i64, ptr @to_get, align 8
  %14 = icmp eq i64 %13, 0
  %or.cond = select i1 %12, i1 true, i1 %14
  br i1 %or.cond, label %.loopexit, label %15

15:                                               ; preds = %7
  %16 = tail call noundef i32 @_Z3getii(i32 noundef %.tr, i32 noundef %.tr21)
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [1002001 x i32], ptr @taken, i64 0, i64 %17
  store i32 1, ptr %18, align 4, !tbaa !5
  %19 = tail call noundef i32 @_Z3getii(i32 noundef %.tr, i32 noundef %.tr21)
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [1002001 x i32], ptr @active, i64 0, i64 %20
  store i32 0, ptr %21, align 4, !tbaa !5
  %22 = load i64, ptr @to_get, align 8, !tbaa !9
  %23 = add nsw i64 %22, -1
  store i64 %23, ptr @to_get, align 8, !tbaa !9
  %24 = load i32, ptr @dx, align 16, !tbaa !5
  %25 = add nsw i32 %24, %.tr
  %26 = load i32, ptr @dy, align 16, !tbaa !5
  %27 = add nsw i32 %26, %.tr21
  %28 = tail call noundef zeroext i1 @_Z4goodii(i32 noundef %25, i32 noundef %27)
  br i1 %28, label %29, label %30

29:                                               ; preds = %15
  tail call void @_Z3dfsii(i32 noundef %25, i32 noundef %27)
  br label %30

30:                                               ; preds = %29, %15
  %31 = load i32, ptr getelementptr inbounds (i8, ptr @dx, i64 4), align 4, !tbaa !5
  %32 = add nsw i32 %31, %.tr
  %33 = load i32, ptr getelementptr inbounds (i8, ptr @dy, i64 4), align 4, !tbaa !5
  %34 = add nsw i32 %33, %.tr21
  %35 = tail call noundef zeroext i1 @_Z4goodii(i32 noundef %32, i32 noundef %34)
  br i1 %35, label %36, label %37

36:                                               ; preds = %30
  tail call void @_Z3dfsii(i32 noundef %32, i32 noundef %34)
  br label %37

37:                                               ; preds = %36, %30
  %38 = load i32, ptr getelementptr inbounds (i8, ptr @dx, i64 8), align 8, !tbaa !5
  %39 = add nsw i32 %38, %.tr
  %40 = load i32, ptr getelementptr inbounds (i8, ptr @dy, i64 8), align 8, !tbaa !5
  %41 = add nsw i32 %40, %.tr21
  %42 = tail call noundef zeroext i1 @_Z4goodii(i32 noundef %39, i32 noundef %41)
  br i1 %42, label %43, label %44

43:                                               ; preds = %37
  tail call void @_Z3dfsii(i32 noundef %39, i32 noundef %41)
  br label %44

44:                                               ; preds = %43, %37
  %45 = load i32, ptr getelementptr inbounds (i8, ptr @dx, i64 12), align 4, !tbaa !5
  %46 = add nsw i32 %45, %.tr
  %47 = load i32, ptr getelementptr inbounds (i8, ptr @dy, i64 12), align 4, !tbaa !5
  %48 = add nsw i32 %47, %.tr21
  %49 = tail call noundef zeroext i1 @_Z4goodii(i32 noundef %46, i32 noundef %48)
  br i1 %49, label %tailrecurse, label %.loopexit

.loopexit:                                        ; preds = %44, %7, %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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}


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