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

@n = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@cnt = external dso_local global i32, align 4
@_ZL5prime = external hidden constant [11 x i32], 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
  %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 @cnt, align 4, !tbaa !5
  %12 = load i32, ptr %8, align 4, !tbaa !5
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %22, label %14

14:                                               ; preds = %4
  %15 = load i32, ptr @cnt, align 4, !tbaa !5
  %16 = load i32, ptr %8, align 4, !tbaa !5
  %17 = icmp eq i32 %15, %16
  br i1 %17, label %18, label %25

18:                                               ; preds = %14
  %19 = load i32, ptr %7, align 4, !tbaa !5
  %20 = load i32, ptr @ans, align 4, !tbaa !5
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %22, label %25

22:                                               ; preds = %18, %4
  %23 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %23, ptr @cnt, align 4, !tbaa !5
  %24 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %24, ptr @ans, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %22, %18, %14
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = icmp sgt i32 %26, 10
  br i1 %27, label %28, label %29

28:                                               ; preds = %25
  br label %68

29:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %64, %29
  %31 = load i32, ptr %9, align 4, !tbaa !5
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = icmp sle i32 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  store i32 2, ptr %10, align 4
  br label %67

35:                                               ; preds = %30
  %36 = load i32, ptr %7, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [11 x i32], ptr @_ZL5prime, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = mul nsw i64 %37, %42
  %44 = load i32, ptr @n, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = icmp sle i64 %43, %45
  br i1 %46, label %47, label %62

47:                                               ; preds = %35
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [11 x i32], ptr @_ZL5prime, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = mul nsw i32 %52, %51
  store i32 %53, ptr %7, align 4, !tbaa !5
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  %56 = load i32, ptr %9, align 4, !tbaa !5
  %57 = load i32, ptr %7, align 4, !tbaa !5
  %58 = load i32, ptr %8, align 4, !tbaa !5
  %59 = load i32, ptr %9, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  %61 = mul nsw i32 %58, %60
  call void @_Z3dfsiiii(i32 noundef %55, i32 noundef %56, i32 noundef %57, i32 noundef %61)
  br label %63

62:                                               ; preds = %35
  store i32 2, ptr %10, align 4
  br label %67

63:                                               ; preds = %47
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %9, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %9, align 4, !tbaa !5
  br label %30, !llvm.loop !9

67:                                               ; preds = %62, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %68

68:                                               ; preds = %67, %28
  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 = distinct !{!9, !10}
!10 = !{!"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
@ans = external dso_local local_unnamed_addr global i32, align 4
@cnt = external dso_local local_unnamed_addr global i32, align 4
@_ZL5prime = external hidden local_unnamed_addr constant [11 x i32], 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 {
  %5 = load i32, ptr @cnt, align 4, !tbaa !5
  %6 = icmp slt i32 %5, %3
  br i1 %6, label %11, label %7

7:                                                ; preds = %4
  %8 = icmp eq i32 %5, %3
  %9 = load i32, ptr @ans, align 4
  %10 = icmp sgt i32 %9, %2
  %or.cond = select i1 %8, i1 %10, i1 false
  br i1 %or.cond, label %11, label %12

11:                                               ; preds = %7, %4
  store i32 %3, ptr @cnt, align 4, !tbaa !5
  store i32 %2, ptr @ans, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %11, %7
  %13 = icmp sgt i32 %0, 10
  %.not24 = icmp slt i32 %1, 1
  %or.cond28 = or i1 %13, %.not24
  br i1 %or.cond28, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %12
  %14 = sext i32 %0 to i64
  %15 = getelementptr inbounds [11 x i32], ptr @_ZL5prime, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = add nsw i32 %0, 1
  br label %19

19:                                               ; preds = %.lr.ph, %24
  %.026 = phi i32 [ 1, %.lr.ph ], [ %26, %24 ]
  %.01825 = phi i32 [ %2, %.lr.ph ], [ %25, %24 ]
  %20 = sext i32 %.01825 to i64
  %21 = mul nsw i64 %17, %20
  %22 = load i32, ptr @n, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %.not22 = icmp sgt i64 %21, %23
  br i1 %.not22, label %.loopexit, label %24

24:                                               ; preds = %19
  %25 = mul nsw i32 %16, %.01825
  %26 = add nuw i32 %.026, 1
  %27 = mul nsw i32 %26, %3
  tail call void @_Z3dfsiiii(i32 noundef %18, i32 noundef %.026, i32 noundef %25, i32 noundef %27)
  %exitcond.not = icmp eq i32 %.026, %1
  br i1 %exitcond.not, label %.loopexit, label %19, !llvm.loop !9

.loopexit:                                        ; preds = %19, %24, %12
  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"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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