; LLVM IR from tangjz/acm-icpc :: poj/2255.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"

@tot = external dso_local global i32, align 4
@pre = external dso_local global [27 x i8], align 16
@mid = external dso_local global [27 x i8], align 16
@suf = external dso_local global [27 x i8], align 16

; 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
  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
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %10 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %10, ptr %9, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %29, %4
  %12 = load i32, ptr %9, align 4, !tbaa !5
  %13 = load i32, ptr %8, align 4, !tbaa !5
  %14 = icmp sle i32 %12, %13
  br i1 %14, label %15, label %32

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

27:                                               ; preds = %15
  br label %32

28:                                               ; preds = %15
  br label %29

29:                                               ; preds = %28
  %30 = load i32, ptr %9, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %9, align 4, !tbaa !5
  br label %11, !llvm.loop !10

32:                                               ; preds = %27, %11
  %33 = load i32, ptr %9, align 4, !tbaa !5
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = icmp sgt i32 %33, %34
  br i1 %35, label %36, label %47

36:                                               ; preds = %32
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = load i32, ptr %9, align 4, !tbaa !5
  %41 = add nsw i32 %39, %40
  %42 = load i32, ptr %7, align 4, !tbaa !5
  %43 = sub nsw i32 %41, %42
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = load i32, ptr %9, align 4, !tbaa !5
  %46 = sub nsw i32 %45, 1
  call void @_Z3dfsiiii(i32 noundef %38, i32 noundef %43, i32 noundef %44, i32 noundef %46)
  br label %47

47:                                               ; preds = %36, %32
  %48 = load i32, ptr %9, align 4, !tbaa !5
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = icmp slt i32 %48, %49
  br i1 %50, label %51, label %62

51:                                               ; preds = %47
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = load i32, ptr %8, align 4, !tbaa !5
  %54 = sub nsw i32 %52, %53
  %55 = load i32, ptr %9, align 4, !tbaa !5
  %56 = add nsw i32 %54, %55
  %57 = add nsw i32 %56, 1
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = load i32, ptr %9, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  %61 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z3dfsiiii(i32 noundef %57, i32 noundef %58, i32 noundef %60, i32 noundef %61)
  br label %62

62:                                               ; preds = %51, %47
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [27 x i8], ptr @pre, i64 0, i64 %64
  %66 = load i8, ptr %65, align 1, !tbaa !9
  %67 = load i32, ptr @tot, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr @tot, align 4, !tbaa !5
  %69 = sext i32 %67 to i64
  %70 = getelementptr inbounds [27 x i8], ptr @suf, i64 0, i64 %69
  store i8 %66, ptr %70, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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"

@tot = external dso_local local_unnamed_addr global i32, align 4
@pre = external dso_local local_unnamed_addr global [27 x i8], align 16
@mid = external dso_local local_unnamed_addr global [27 x i8], align 16
@suf = external dso_local local_unnamed_addr global [27 x i8], align 16

; 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 {
  %.not26 = icmp sgt i32 %2, %3
  br i1 %.not26, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %5 = sext i32 %0 to i64
  %6 = getelementptr inbounds [27 x i8], ptr @pre, i64 0, i64 %5
  %7 = load i8, ptr %6, align 1, !tbaa !5
  %8 = sext i32 %2 to i64
  %9 = add i32 %3, 1
  br label %10

10:                                               ; preds = %.lr.ph, %14
  %indvars.iv = phi i64 [ %8, %.lr.ph ], [ %indvars.iv.next, %14 ]
  %11 = getelementptr inbounds [27 x i8], ptr @mid, i64 0, i64 %indvars.iv
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %13 = icmp eq i8 %12, %7
  br i1 %13, label %._crit_edge.split.loop.exit33, label %14

14:                                               ; preds = %10
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %lftr.wideiv = trunc i64 %indvars.iv.next to i32
  %exitcond.not = icmp eq i32 %9, %lftr.wideiv
  br i1 %exitcond.not, label %._crit_edge, label %10, !llvm.loop !8

._crit_edge.split.loop.exit33:                    ; preds = %10
  %15 = trunc nsw i64 %indvars.iv to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %14, %._crit_edge.split.loop.exit33
  %.0.lcssa = phi i32 [ %15, %._crit_edge.split.loop.exit33 ], [ %9, %14 ]
  %16 = icmp sgt i32 %.0.lcssa, %2
  br i1 %16, label %17, label %._crit_edge.thread

17:                                               ; preds = %._crit_edge
  %18 = add nsw i32 %0, 1
  %19 = sub i32 %0, %2
  %20 = add i32 %19, %.0.lcssa
  %21 = add nsw i32 %.0.lcssa, -1
  tail call void @_Z3dfsiiii(i32 noundef %18, i32 noundef %20, i32 noundef %2, i32 noundef %21)
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %4, %17, %._crit_edge
  %.0.lcssa32 = phi i32 [ %.0.lcssa, %17 ], [ %.0.lcssa, %._crit_edge ], [ %2, %4 ]
  %22 = icmp slt i32 %.0.lcssa32, %3
  br i1 %22, label %23, label %28

23:                                               ; preds = %._crit_edge.thread
  %24 = add i32 %1, 1
  %25 = sub i32 %24, %3
  %26 = add i32 %25, %.0.lcssa32
  %27 = add nsw i32 %.0.lcssa32, 1
  tail call void @_Z3dfsiiii(i32 noundef %26, i32 noundef %1, i32 noundef %27, i32 noundef %3)
  br label %28

28:                                               ; preds = %23, %._crit_edge.thread
  %29 = sext i32 %0 to i64
  %30 = getelementptr inbounds [27 x i8], ptr @pre, i64 0, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !5
  %32 = load i32, ptr @tot, align 4, !tbaa !10
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr @tot, align 4, !tbaa !10
  %34 = sext i32 %32 to i64
  %35 = getelementptr inbounds [27 x i8], ptr @suf, i64 0, i64 %34
  store i8 %31, ptr %35, align 1, !tbaa !5
  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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, i64 0}


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