; LLVM IR from tangjz/acm-icpc :: 51nod/1400.ll (Z3dfsiii)

; 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 [50 x i32], align 16
@b = external dso_local global [50 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z3dfsiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i1, align 1
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  %8 = load i32, ptr %5, align 4, !tbaa !5
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = icmp eq i32 %8, %9
  br i1 %10, label %11, label %15

11:                                               ; preds = %3
  %12 = load i32, ptr %6, align 4, !tbaa !5
  %13 = load i32, ptr %7, align 4, !tbaa !5
  %14 = icmp eq i32 %12, %13
  store i1 %14, ptr %4, align 1
  br label %54

15:                                               ; preds = %3
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [50 x i32], ptr @a, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [50 x i32], ptr @b, i64 0, i64 %21
  store i32 %19, ptr %22, align 4, !tbaa !5
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = call noundef zeroext i1 @_Z3dfsiii(i32 noundef %24, i32 noundef %26, i32 noundef %27)
  br i1 %28, label %52, label %29

29:                                               ; preds = %15
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = load i32, ptr %7, align 4, !tbaa !5
  %32 = icmp sgt i32 %30, %31
  br i1 %32, label %33, label %50

33:                                               ; preds = %29
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [50 x i32], ptr @a, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [50 x i32], ptr @b, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = icmp eq i32 %37, %41
  br i1 %42, label %43, label %50

43:                                               ; preds = %33
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  %46 = load i32, ptr %6, align 4, !tbaa !5
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  %49 = call noundef zeroext i1 @_Z3dfsiii(i32 noundef %45, i32 noundef %46, i32 noundef %48)
  br label %50

50:                                               ; preds = %43, %33, %29
  %51 = phi i1 [ false, %33 ], [ false, %29 ], [ %49, %43 ]
  br label %52

52:                                               ; preds = %50, %15
  %53 = phi i1 [ true, %15 ], [ %51, %50 ]
  store i1 %53, ptr %4, align 1
  br label %54

54:                                               ; preds = %52, %11
  %55 = load i1, ptr %4, align 1
  ret i1 %55
}

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
@a = external dso_local local_unnamed_addr global [50 x i32], align 16
@b = external dso_local local_unnamed_addr global [50 x i32], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_Z3dfsiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = icmp eq i32 %4, %0
  br i1 %5, label %tailrecurse._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %6 = sext i32 %1 to i64
  %7 = getelementptr inbounds [50 x i32], ptr @b, i64 0, i64 %6
  %8 = add nsw i32 %1, 1
  %9 = sext i32 %2 to i64
  %10 = sext i32 %0 to i64
  %smax = tail call i32 @llvm.smax.i32(i32 %2, i32 %1)
  %wide.trip.count = sext i32 %smax to i64
  br label %13

tailrecurse._crit_edge.loopexit:                  ; preds = %tailrecurse
  %11 = trunc nsw i64 %indvars.iv.next to i32
  br label %tailrecurse._crit_edge

tailrecurse._crit_edge:                           ; preds = %tailrecurse._crit_edge.loopexit, %3
  %.tr19.lcssa = phi i32 [ %2, %3 ], [ %11, %tailrecurse._crit_edge.loopexit ]
  %12 = icmp eq i32 %.tr19.lcssa, %1
  br label %.loopexit

13:                                               ; preds = %.lr.ph, %tailrecurse
  %indvars.iv23 = phi i64 [ %10, %.lr.ph ], [ %indvars.iv.next24, %tailrecurse ]
  %indvars.iv = phi i64 [ %9, %.lr.ph ], [ %indvars.iv.next, %tailrecurse ]
  %14 = getelementptr inbounds [50 x i32], ptr @a, i64 0, i64 %indvars.iv23
  %15 = load i32, ptr %14, align 4, !tbaa !5
  store i32 %15, ptr %7, align 4, !tbaa !5
  %indvars.iv.next24 = add nsw i64 %indvars.iv23, 1
  %16 = trunc nsw i64 %indvars.iv to i32
  %17 = trunc nsw i64 %indvars.iv.next24 to i32
  %18 = tail call noundef zeroext i1 @_Z3dfsiii(i32 noundef %17, i32 noundef %8, i32 noundef %16)
  %exitcond.not = icmp eq i64 %indvars.iv, %wide.trip.count
  %or.cond = or i1 %18, %exitcond.not
  br i1 %or.cond, label %.loopexit, label %19

19:                                               ; preds = %13
  %20 = load i32, ptr %14, align 4, !tbaa !5
  %21 = getelementptr inbounds [50 x i32], ptr @b, i64 0, i64 %indvars.iv
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = icmp eq i32 %20, %22
  br i1 %23, label %tailrecurse, label %.loopexit

tailrecurse:                                      ; preds = %19
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %24 = load i32, ptr @n, align 4, !tbaa !5
  %25 = icmp eq i32 %24, %17
  br i1 %25, label %tailrecurse._crit_edge.loopexit, label %13

.loopexit:                                        ; preds = %13, %19, %tailrecurse._crit_edge
  %.0 = phi i1 [ %12, %tailrecurse._crit_edge ], [ %18, %19 ], [ %18, %13 ]
  ret i1 %.0
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #1

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" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass