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

; 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
@e = external dso_local global [51 x [52 x i8]], align 16

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

10:                                               ; preds = %39, %3
  %11 = load i32, ptr %9, align 4, !tbaa !5
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %42

15:                                               ; preds = %10
  %16 = load i32, ptr %9, align 4, !tbaa !5
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = icmp ne i32 %16, %17
  br i1 %18, label %19, label %38

19:                                               ; preds = %15
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [51 x [52 x i8]], ptr @e, i64 0, i64 %21
  %23 = load i32, ptr %9, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [52 x i8], ptr %22, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !11
  %27 = sext i8 %26 to i32
  %28 = icmp eq i32 %27, 89
  br i1 %28, label %29, label %38

29:                                               ; preds = %19
  %30 = load i32, ptr %9, align 4, !tbaa !5
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !9
  %33 = call noundef i32 @_Z3dfsiiRi(i32 noundef %30, i32 noundef %31, ptr noundef nonnull align 4 dereferenceable(4) %32)
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = add nsw i32 %34, %33
  store i32 %35, ptr %7, align 4, !tbaa !5
  %36 = load i32, ptr %8, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %8, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %29, %19, %15
  br label %39

39:                                               ; preds = %38
  %40 = load i32, ptr %9, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %9, align 4, !tbaa !5
  br label %10, !llvm.loop !12

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

46:                                               ; preds = %42
  %47 = load i32, ptr %8, align 4, !tbaa !5
  %48 = load i32, ptr %7, align 4, !tbaa !5
  %49 = sub nsw i32 %47, %48
  %50 = sub nsw i32 %49, 1
  %51 = load ptr, ptr %6, align 8, !tbaa !9
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = add nsw i32 %52, %50
  store i32 %53, ptr %51, align 4, !tbaa !5
  %54 = load i32, ptr %8, align 4, !tbaa !5
  %55 = sub nsw i32 %54, 1
  store i32 %55, ptr %7, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %46, %42
  %57 = load i32, ptr %7, align 4, !tbaa !5
  %58 = icmp sgt i32 %57, 0
  %59 = zext i1 %58 to i32
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret i32 %59
}

; 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 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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
@e = external dso_local local_unnamed_addr global [51 x [52 x i8]], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef range(i32 0, 2) i32 @_Z3dfsiiRi(i32 noundef %0, i32 noundef %1, ptr nocapture noundef nonnull align 4 dereferenceable(4) %2) local_unnamed_addr #0 {
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge.thread

.lr.ph:                                           ; preds = %3
  %6 = sext i32 %0 to i64
  %7 = zext i32 %1 to i64
  br label %9

._crit_edge:                                      ; preds = %20
  %8 = icmp slt i32 %.119, %.1
  br i1 %8, label %24, label %._crit_edge.thread

9:                                                ; preds = %.lr.ph, %20
  %10 = phi i32 [ %4, %.lr.ph ], [ %21, %20 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %20 ]
  %.01721 = phi i32 [ 0, %.lr.ph ], [ %.1, %20 ]
  %.01820 = phi i32 [ 0, %.lr.ph ], [ %.119, %20 ]
  %.not = icmp eq i64 %indvars.iv, %7
  br i1 %.not, label %20, label %11

11:                                               ; preds = %9
  %12 = getelementptr inbounds [51 x [52 x i8]], ptr @e, i64 0, i64 %6, i64 %indvars.iv
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %14 = icmp eq i8 %13, 89
  br i1 %14, label %15, label %20

15:                                               ; preds = %11
  %16 = trunc nuw nsw i64 %indvars.iv to i32
  %17 = tail call noundef i32 @_Z3dfsiiRi(i32 noundef %16, i32 noundef %0, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %18 = add nsw i32 %17, %.01820
  %19 = add nsw i32 %.01721, 1
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %9, %11, %15
  %21 = phi i32 [ %.pre, %15 ], [ %10, %11 ], [ %10, %9 ]
  %.119 = phi i32 [ %18, %15 ], [ %.01820, %11 ], [ %.01820, %9 ]
  %.1 = phi i32 [ %19, %15 ], [ %.01721, %11 ], [ %.01721, %9 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %22 = sext i32 %21 to i64
  %23 = icmp slt i64 %indvars.iv.next, %22
  br i1 %23, label %9, label %._crit_edge, !llvm.loop !10

24:                                               ; preds = %._crit_edge
  %25 = xor i32 %.119, -1
  %26 = add i32 %.1, %25
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = add nsw i32 %26, %27
  store i32 %28, ptr %2, align 4, !tbaa !5
  %29 = add nsw i32 %.1, -1
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %3, %24, %._crit_edge
  %.2 = phi i32 [ %29, %24 ], [ %.119, %._crit_edge ], [ 0, %3 ]
  %30 = icmp sgt i32 %.2, 0
  %31 = zext i1 %30 to i32
  ret i32 %31
}

attributes #0 = { mustprogress nofree nosync nounwind memory(read, argmem: readwrite, 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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