; LLVM IR from tangjz/acm-icpc :: codeforces/887B.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"

@n = external dso_local global i32, align 4
@a = external dso_local global [3 x [7 x i32]], align 16
@ord = external dso_local global [3 x i32], align 4
@vis = external dso_local global [1001 x i8], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsii(i32 noundef %0, i32 noundef %1) #0 {
  %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 = load i32, ptr @n, align 4, !tbaa !5
  %8 = icmp eq i32 %6, %7
  br i1 %8, label %9, label %13

9:                                                ; preds = %2
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [1001 x i8], ptr @vis, i64 0, i64 %11
  store i8 1, ptr %12, align 1, !tbaa !9
  br label %40

13:                                               ; preds = %2
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = add nsw i32 %14, 1
  %16 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %15, i32 noundef %16)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %37, %13
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = icmp slt i32 %18, 6
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %40

21:                                               ; preds = %17
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = mul nsw i32 %24, 10
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [3 x i32], ptr @ord, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [3 x [7 x i32]], ptr @a, i64 0, i64 %30
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [7 x i32], ptr %31, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = add nsw i32 %25, %35
  call void @_Z3dfsii(i32 noundef %23, i32 noundef %36)
  br label %37

37:                                               ; preds = %21
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %5, align 4, !tbaa !5
  br label %17, !llvm.loop !11

40:                                               ; preds = %20, %9
  ret void
}

; 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

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

@n = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local local_unnamed_addr global [3 x [7 x i32]], align 16
@ord = external dso_local local_unnamed_addr global [3 x i32], align 4
@vis = external dso_local local_unnamed_addr global [1001 x i8], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %.loopexit.loopexit, %2
  %.tr = phi i32 [ %0, %2 ], [ %7, %.loopexit.loopexit ]
  %.tr13 = phi i32 [ %1, %2 ], [ %40, %.loopexit.loopexit ]
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = icmp eq i32 %3, %.tr
  br i1 %4, label %.loopexit, label %.loopexit.loopexit

.loopexit:                                        ; preds = %tailrecurse
  %5 = sext i32 %.tr13 to i64
  %6 = getelementptr inbounds [1001 x i8], ptr @vis, i64 0, i64 %5
  store i8 1, ptr %6, align 1, !tbaa !9
  ret void

.loopexit.loopexit:                               ; preds = %tailrecurse
  %7 = add nsw i32 %.tr, 1
  tail call void @_Z3dfsii(i32 noundef %7, i32 noundef %.tr13)
  %8 = mul nsw i32 %.tr13, 10
  %9 = sext i32 %.tr to i64
  %10 = getelementptr inbounds [3 x i32], ptr @ord, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [3 x [7 x i32]], ptr @a, i64 0, i64 %12, i64 0
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = add nsw i32 %14, %8
  tail call void @_Z3dfsii(i32 noundef %7, i32 noundef %15)
  %16 = load i32, ptr %10, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [3 x [7 x i32]], ptr @a, i64 0, i64 %17, i64 1
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = add nsw i32 %19, %8
  tail call void @_Z3dfsii(i32 noundef %7, i32 noundef %20)
  %21 = load i32, ptr %10, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [3 x [7 x i32]], ptr @a, i64 0, i64 %22, i64 2
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = add nsw i32 %24, %8
  tail call void @_Z3dfsii(i32 noundef %7, i32 noundef %25)
  %26 = load i32, ptr %10, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [3 x [7 x i32]], ptr @a, i64 0, i64 %27, i64 3
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = add nsw i32 %29, %8
  tail call void @_Z3dfsii(i32 noundef %7, i32 noundef %30)
  %31 = load i32, ptr %10, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [3 x [7 x i32]], ptr @a, i64 0, i64 %32, i64 4
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = add nsw i32 %34, %8
  tail call void @_Z3dfsii(i32 noundef %7, i32 noundef %35)
  %36 = load i32, ptr %10, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [3 x [7 x i32]], ptr @a, i64 0, i64 %37, i64 5
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = add nsw i32 %39, %8
  br label %tailrecurse
}

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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}


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