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

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

@pre = external dso_local global [10001 x i32], align 16
@suf = external dso_local global [10001 x i32], align 16
@pid = external dso_local global [10001 x i32], align 16
@sid = external dso_local global [10001 x i32], align 16
@cnt = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = 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
  store i32 %3, ptr %8, align 4, !tbaa !5
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = load i32, ptr %6, align 4, !tbaa !5
  %13 = icmp eq i32 %11, %12
  br i1 %13, label %14, label %15

14:                                               ; preds = %4
  br label %65

15:                                               ; preds = %4
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [10001 x i32], ptr @pre, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = load i32, ptr %8, align 4, !tbaa !5
  %22 = sub nsw i32 %21, 1
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [10001 x i32], ptr @suf, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = icmp eq i32 %20, %25
  br i1 %26, label %27, label %36

27:                                               ; preds = %15
  %28 = load i32, ptr @cnt, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr @cnt, align 4, !tbaa !5
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = load i32, ptr %8, align 4, !tbaa !5
  %35 = sub nsw i32 %34, 1
  call void @_Z3dfsiiii(i32 noundef %31, i32 noundef %32, i32 noundef %33, i32 noundef %35)
  br label %65

36:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %37 = load i32, ptr %8, align 4, !tbaa !5
  %38 = sub nsw i32 %37, 1
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [10001 x i32], ptr @suf, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [10001 x i32], ptr @pid, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  store i32 %44, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [10001 x i32], ptr @pre, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [10001 x i32], ptr @sid, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  store i32 %52, ptr %10, align 4, !tbaa !5
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  %55 = load i32, ptr %9, align 4, !tbaa !5
  %56 = sub nsw i32 %55, 1
  %57 = load i32, ptr %7, align 4, !tbaa !5
  %58 = load i32, ptr %10, align 4, !tbaa !5
  call void @_Z3dfsiiii(i32 noundef %54, i32 noundef %56, i32 noundef %57, i32 noundef %58)
  %59 = load i32, ptr %9, align 4, !tbaa !5
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = load i32, ptr %10, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  %63 = load i32, ptr %8, align 4, !tbaa !5
  %64 = sub nsw i32 %63, 1
  call void @_Z3dfsiiii(i32 noundef %59, i32 noundef %60, i32 noundef %62, i32 noundef %64)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %65

65:                                               ; preds = %36, %27, %14
  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"}


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

@pre = external dso_local local_unnamed_addr global [10001 x i32], align 16
@suf = external dso_local local_unnamed_addr global [10001 x i32], align 16
@pid = external dso_local local_unnamed_addr global [10001 x i32], align 16
@sid = external dso_local local_unnamed_addr global [10001 x i32], align 16
@cnt = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3dfsiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq i32 %0, %1
  br i1 %5, label %tailrecurse.outer._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %4
  %sext = sext i32 %1 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %tailrecurse.outer
  %.tr23.ph32 = phi i32 [ %18, %tailrecurse.outer ], [ %3, %.lr.ph.preheader ]
  %.tr22.ph31 = phi i32 [ %26, %tailrecurse.outer ], [ %2, %.lr.ph.preheader ]
  %.tr.ph30 = phi i32 [ %21, %tailrecurse.outer ], [ %0, %.lr.ph.preheader ]
  %cnt.promoted33 = load i32, ptr @cnt, align 4, !tbaa !5
  %6 = sext i32 %.tr23.ph32 to i64
  %7 = sext i32 %.tr.ph30 to i64
  br label %8

8:                                                ; preds = %.lr.ph, %tailrecurse
  %indvars.iv42 = phi i64 [ %7, %.lr.ph ], [ %indvars.iv.next43, %tailrecurse ]
  %indvars.iv = phi i64 [ %6, %.lr.ph ], [ %indvars.iv.next, %tailrecurse ]
  %9 = phi i32 [ %cnt.promoted33, %.lr.ph ], [ %15, %tailrecurse ]
  %indvars.iv.next43 = add nsw i64 %indvars.iv42, 1
  %10 = getelementptr inbounds [10001 x i32], ptr @pre, i64 0, i64 %indvars.iv.next43
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %12 = getelementptr inbounds [10001 x i32], ptr @suf, i64 0, i64 %indvars.iv.next
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = icmp eq i32 %11, %13
  br i1 %14, label %tailrecurse, label %tailrecurse.outer

tailrecurse:                                      ; preds = %8
  %15 = add nsw i32 %9, 1
  store i32 %15, ptr @cnt, align 4, !tbaa !5
  %16 = icmp eq i64 %indvars.iv.next43, %sext
  br i1 %16, label %tailrecurse.outer._crit_edge, label %8

tailrecurse.outer:                                ; preds = %8
  %17 = trunc nsw i64 %indvars.iv.next43 to i32
  %18 = trunc nsw i64 %indvars.iv.next to i32
  %19 = sext i32 %13 to i64
  %20 = getelementptr inbounds [10001 x i32], ptr @pid, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = sext i32 %11 to i64
  %23 = getelementptr inbounds [10001 x i32], ptr @sid, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = add nsw i32 %21, -1
  tail call void @_Z3dfsiiii(i32 noundef %17, i32 noundef %25, i32 noundef %.tr22.ph31, i32 noundef %24)
  %26 = add nsw i32 %24, 1
  %27 = icmp eq i32 %21, %1
  br i1 %27, label %tailrecurse.outer._crit_edge, label %.lr.ph

tailrecurse.outer._crit_edge:                     ; preds = %tailrecurse.outer, %tailrecurse, %4
  ret void
}

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


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