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

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

@cnt = external dso_local global i32, align 4
@d = external dso_local global [11 x i32], align 16
@qL = external dso_local global i32, align 4
@qR = external dso_local global i32, align 4
@T = external dso_local global i64, align 8
@tmp = external dso_local global i64, align 8

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsixi(i32 noundef %0, i64 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = load i32, ptr @cnt, align 4, !tbaa !5
  %17 = icmp sgt i32 %15, %16
  br i1 %17, label %18, label %67

18:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %19 = load i32, ptr @qL, align 4, !tbaa !5
  %20 = sub nsw i32 %19, 1
  %21 = sext i32 %20 to i64
  %22 = load i64, ptr %5, align 8, !tbaa !9
  %23 = sdiv i64 %21, %22
  store i64 %23, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %24 = load i32, ptr @qR, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = load i64, ptr %5, align 8, !tbaa !9
  %27 = sdiv i64 %25, %26
  store i64 %27, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %28 = load i64, ptr @T, align 8, !tbaa !9
  %29 = load i64, ptr %5, align 8, !tbaa !9
  %30 = sdiv i64 %28, %29
  store i64 %30, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %31 = load i64, ptr %9, align 8, !tbaa !9
  %32 = load i64, ptr %8, align 8, !tbaa !9
  %33 = sdiv i64 %31, %32
  store i64 %33, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  store i64 1, ptr %12, align 8, !tbaa !9
  %34 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %11, ptr noundef nonnull align 8 dereferenceable(8) %12)
  %35 = load i64, ptr %34, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  store i64 %35, ptr %10, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %63, %18
  %37 = load i64, ptr %10, align 8, !tbaa !9
  %38 = load i64, ptr %9, align 8, !tbaa !9
  %39 = load i64, ptr %7, align 8, !tbaa !9
  %40 = sdiv i64 %38, %39
  %41 = icmp sle i64 %37, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %66

43:                                               ; preds = %36
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = load i64, ptr %10, align 8, !tbaa !9
  %47 = mul nsw i64 %45, %46
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %48 = load i64, ptr %9, align 8, !tbaa !9
  %49 = load i64, ptr %10, align 8, !tbaa !9
  %50 = sdiv i64 %48, %49
  store i64 %50, ptr %13, align 8, !tbaa !9
  %51 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %13, ptr noundef nonnull align 8 dereferenceable(8) %8)
  %52 = load i64, ptr %51, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %53 = load i64, ptr %9, align 8, !tbaa !9
  %54 = load i64, ptr %10, align 8, !tbaa !9
  %55 = add nsw i64 %54, 1
  %56 = sdiv i64 %53, %55
  store i64 %56, ptr %14, align 8, !tbaa !9
  %57 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %14, ptr noundef nonnull align 8 dereferenceable(8) %7)
  %58 = load i64, ptr %57, align 8, !tbaa !9
  %59 = sub nsw i64 %52, %58
  %60 = mul nsw i64 %47, %59
  %61 = load i64, ptr @tmp, align 8, !tbaa !9
  %62 = add nsw i64 %61, %60
  store i64 %62, ptr @tmp, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %63

63:                                               ; preds = %43
  %64 = load i64, ptr %10, align 8, !tbaa !9
  %65 = add nsw i64 %64, 1
  store i64 %65, ptr %10, align 8, !tbaa !9
  br label %36, !llvm.loop !11

66:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %83

67:                                               ; preds = %3
  %68 = load i32, ptr %4, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  %70 = load i64, ptr %5, align 8, !tbaa !9
  %71 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z3dfsixi(i32 noundef %69, i64 noundef %70, i32 noundef %71)
  %72 = load i32, ptr %4, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  %74 = load i64, ptr %5, align 8, !tbaa !9
  %75 = load i32, ptr %4, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [11 x i32], ptr @d, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = mul nsw i64 %74, %79
  %81 = load i32, ptr %6, align 4, !tbaa !5
  %82 = sub nsw i32 0, %81
  call void @_Z3dfsixi(i32 noundef %73, i64 noundef %80, i32 noundef %82)
  br label %83

83:                                               ; preds = %67, %66
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { inlinehint mustprogress nounwind 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 #3 = { 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 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@cnt = external dso_local local_unnamed_addr global i32, align 4
@d = external dso_local local_unnamed_addr global [11 x i32], align 16
@qL = external dso_local local_unnamed_addr global i32, align 4
@qR = external dso_local local_unnamed_addr global i32, align 4
@T = external dso_local local_unnamed_addr global i64, align 8
@tmp = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3dfsixi(i32 noundef %0, i64 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = load i32, ptr @cnt, align 4, !tbaa !5
  %11 = icmp slt i32 %10, %0
  br i1 %11, label %tailrecurse._crit_edge, label %tailrecurse.preheader

tailrecurse.preheader:                            ; preds = %3
  %12 = sext i32 %0 to i64
  br label %tailrecurse

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %3
  %.tr22.lcssa = phi i64 [ %1, %3 ], [ %46, %tailrecurse ]
  %.tr23.lcssa = phi i32 [ %2, %3 ], [ %47, %tailrecurse ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  %13 = load i32, ptr @qL, align 4, !tbaa !5
  %14 = add nsw i32 %13, -1
  %15 = sext i32 %14 to i64
  %16 = sdiv i64 %15, %.tr22.lcssa
  store i64 %16, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  %17 = load i32, ptr @qR, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = sdiv i64 %18, %.tr22.lcssa
  store i64 %19, ptr %5, align 8, !tbaa !9
  %20 = load i64, ptr @T, align 8, !tbaa !9
  %21 = sdiv i64 %20, %.tr22.lcssa
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  %22 = sdiv i64 %21, %19
  store i64 %22, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #3
  store i64 1, ptr %7, align 8, !tbaa !9
  %23 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %6, ptr noundef nonnull align 8 dereferenceable(8) %7)
  %24 = load i64, ptr %23, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  %25 = sdiv i64 %21, %16
  %.not28 = icmp sgt i64 %24, %25
  br i1 %.not28, label %._crit_edge, label %.lr.ph30

.lr.ph30:                                         ; preds = %tailrecurse._crit_edge
  %26 = sext i32 %.tr23.lcssa to i64
  br label %27

._crit_edge:                                      ; preds = %27, %tailrecurse._crit_edge
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  ret void

27:                                               ; preds = %.lr.ph30, %27
  %.029 = phi i64 [ %24, %.lr.ph30 ], [ %32, %27 ]
  %28 = mul nsw i64 %.029, %26
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #3
  %29 = sdiv i64 %21, %.029
  store i64 %29, ptr %8, align 8, !tbaa !9
  %30 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %8, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %31 = load i64, ptr %30, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #3
  %32 = add nsw i64 %.029, 1
  %33 = sdiv i64 %21, %32
  store i64 %33, ptr %9, align 8, !tbaa !9
  %34 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %9, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %35 = load i64, ptr %34, align 8, !tbaa !9
  %36 = sub nsw i64 %31, %35
  %37 = mul nsw i64 %28, %36
  %38 = load i64, ptr @tmp, align 8, !tbaa !9
  %39 = add nsw i64 %37, %38
  store i64 %39, ptr @tmp, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #3
  %40 = load i64, ptr %4, align 8, !tbaa !9
  %41 = sdiv i64 %21, %40
  %.not.not = icmp slt i64 %.029, %41
  br i1 %.not.not, label %27, label %._crit_edge, !llvm.loop !11

tailrecurse:                                      ; preds = %tailrecurse.preheader, %tailrecurse
  %indvars.iv = phi i64 [ %12, %tailrecurse.preheader ], [ %indvars.iv.next, %tailrecurse ]
  %.tr2326 = phi i32 [ %2, %tailrecurse.preheader ], [ %47, %tailrecurse ]
  %.tr2225 = phi i64 [ %1, %tailrecurse.preheader ], [ %46, %tailrecurse ]
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %42 = trunc nsw i64 %indvars.iv.next to i32
  tail call void @_Z3dfsixi(i32 noundef %42, i64 noundef %.tr2225, i32 noundef %.tr2326)
  %43 = getelementptr inbounds [11 x i32], ptr @d, i64 0, i64 %indvars.iv
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = mul nsw i64 %.tr2225, %45
  %47 = sub nsw i32 0, %.tr2326
  %48 = load i32, ptr @cnt, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %.not31 = icmp slt i64 %indvars.iv, %49
  br i1 %.not31, label %tailrecurse, label %tailrecurse._crit_edge
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nounwind 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 #2 = { inlinehint mustprogress nounwind 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 #3 = { 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 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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