; LLVM IR from tangjz/acm-icpc :: buaa/oj3rd/765.ll (Z3dfsi)

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

@e = external dso_local global [501 x [501 x i32]], align 16
@match = external dso_local global [501 x i32], align 16
@vis = external dso_local global [501 x i8], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z3dfsi(i32 noundef %0) #0 {
  %2 = alloca i1, align 1
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  br label %7

7:                                                ; preds = %50, %1
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [501 x [501 x i32]], ptr @e, i64 0, i64 %10
  %12 = getelementptr inbounds [501 x i32], ptr %11, i64 0, i64 0
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = icmp sle i32 %8, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %7
  store i32 2, ptr %6, align 4
  br label %53

16:                                               ; preds = %7
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [501 x [501 x i32]], ptr @e, i64 0, i64 %18
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [501 x i32], ptr %19, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  store i32 %23, ptr %5, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [501 x i8], ptr @vis, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !9, !range !11, !noundef !12
  %27 = trunc i8 %26 to i1
  br i1 %27, label %49, label %28

28:                                               ; preds = %16
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [501 x i8], ptr @vis, i64 0, i64 %30
  store i8 1, ptr %31, align 1, !tbaa !9
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [501 x i32], ptr @match, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %43

37:                                               ; preds = %28
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [501 x i32], ptr @match, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = call noundef zeroext i1 @_Z3dfsi(i32 noundef %41)
  br i1 %42, label %43, label %48

43:                                               ; preds = %37, %28
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [501 x i32], ptr @match, i64 0, i64 %46
  store i32 %44, ptr %47, align 4, !tbaa !5
  store i1 true, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %53

48:                                               ; preds = %37
  br label %49

49:                                               ; preds = %48, %16
  br label %50

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

53:                                               ; preds = %43, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %54 = load i32, ptr %6, align 4
  switch i32 %54, label %58 [
    i32 2, label %55
    i32 1, label %56
  ]

55:                                               ; preds = %53
  store i1 false, ptr %2, align 1
  br label %56

56:                                               ; preds = %55, %53
  %57 = load i1, ptr %2, align 1
  ret i1 %57

58:                                               ; preds = %53
  unreachable
}

; 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 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@e = external dso_local local_unnamed_addr global [501 x [501 x i32]], align 16
@match = external dso_local local_unnamed_addr global [501 x i32], align 16
@vis = external dso_local local_unnamed_addr global [501 x i8], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_Z3dfsi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [501 x [501 x i32]], ptr @e, i64 0, i64 %2
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %.not18 = icmp sgt i32 %4, 0
  br i1 %.not18, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %1, %19
  %5 = phi i32 [ %20, %19 ], [ %4, %1 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %19 ], [ 1, %1 ]
  %6 = getelementptr inbounds [501 x [501 x i32]], ptr @e, i64 0, i64 %2, i64 %indvars.iv
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [501 x i8], ptr @vis, i64 0, i64 %8
  %10 = load i8, ptr %9, align 1, !tbaa !9, !range !11, !noundef !12
  %11 = trunc nuw i8 %10 to i1
  br i1 %11, label %19, label %12

12:                                               ; preds = %.lr.ph
  store i8 1, ptr %9, align 1, !tbaa !9
  %13 = getelementptr inbounds [501 x i32], ptr @match, i64 0, i64 %8
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %.not14 = icmp eq i32 %14, 0
  br i1 %.not14, label %17, label %15

15:                                               ; preds = %12
  %16 = tail call noundef zeroext i1 @_Z3dfsi(i32 noundef %14)
  br i1 %16, label %17, label %._crit_edge

._crit_edge:                                      ; preds = %15
  %.pre = load i32, ptr %3, align 4, !tbaa !5
  br label %19

17:                                               ; preds = %15, %12
  %18 = getelementptr inbounds [501 x i32], ptr @match, i64 0, i64 %8
  store i32 %0, ptr %18, align 4, !tbaa !5
  br label %.loopexit

19:                                               ; preds = %._crit_edge, %.lr.ph
  %20 = phi i32 [ %.pre, %._crit_edge ], [ %5, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %21 = sext i32 %20 to i64
  %.not = icmp slt i64 %indvars.iv, %21
  br i1 %.not, label %.lr.ph, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %19, %1, %17
  %.not16 = phi i1 [ true, %17 ], [ false, %1 ], [ false, %19 ]
  ret i1 %.not16
}

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}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass