; LLVM IR from tangjz/acm-icpc :: 51nod/1269.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"

@n = external dso_local global i32, align 4
@m = external dso_local global i64, align 8
@a = external dso_local global [21 x i64], align 16
@ans = external dso_local global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z1Cxi(i64 noundef, i32 noundef) #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
  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
  %7 = load i32, ptr %4, align 4, !tbaa !5
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = icmp eq i32 %7, %8
  br i1 %9, label %10, label %26

10:                                               ; preds = %3
  %11 = load i32, ptr %6, align 4, !tbaa !5
  %12 = load i64, ptr @m, align 8, !tbaa !9
  %13 = load i64, ptr %5, align 8, !tbaa !9
  %14 = sub nsw i64 %12, %13
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = add nsw i64 %14, %16
  %18 = sub nsw i64 %17, 1
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %20 = sub nsw i32 %19, 1
  %21 = call noundef i32 @_Z1Cxi(i64 noundef %18, i32 noundef %20)
  %22 = mul nsw i32 %11, %21
  %23 = sext i32 %22 to i64
  %24 = load i64, ptr @ans, align 8, !tbaa !9
  %25 = add nsw i64 %24, %23
  store i64 %25, ptr @ans, align 8, !tbaa !9
  br label %52

26:                                               ; preds = %3
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  %29 = load i64, ptr %5, align 8, !tbaa !9
  %30 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z3dfsixi(i32 noundef %28, i64 noundef %29, i32 noundef %30)
  %31 = load i64, ptr %5, align 8, !tbaa !9
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [21 x i64], ptr @a, i64 0, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !9
  %36 = add nsw i64 %31, %35
  %37 = add nsw i64 %36, 1
  %38 = load i64, ptr @m, align 8, !tbaa !9
  %39 = icmp sle i64 %37, %38
  br i1 %39, label %40, label %52

40:                                               ; preds = %26
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  %43 = load i64, ptr %5, align 8, !tbaa !9
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [21 x i64], ptr @a, i64 0, i64 %45
  %47 = load i64, ptr %46, align 8, !tbaa !9
  %48 = add nsw i64 %43, %47
  %49 = add nsw i64 %48, 1
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = sub nsw i32 0, %50
  call void @_Z3dfsixi(i32 noundef %42, i64 noundef %49, i32 noundef %51)
  br label %52

52:                                               ; preds = %40, %26, %10
  ret void
}

attributes #0 = { 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 #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" }

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


; 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
@m = external dso_local local_unnamed_addr global i64, align 8
@a = external dso_local local_unnamed_addr global [21 x i64], align 16
@ans = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z1Cxi(i64 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3dfsixi(i32 noundef %0, i64 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = icmp eq i32 %4, %0
  br i1 %5, label %.tailrecurse._crit_edge_crit_edge, label %.lr.ph.preheader

.tailrecurse._crit_edge_crit_edge:                ; preds = %3
  %.pre = load i64, ptr @m, align 8, !tbaa !9
  br label %tailrecurse._crit_edge

.lr.ph.preheader:                                 ; preds = %3
  %6 = sext i32 %0 to i64
  br label %.lr.ph

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %.tailrecurse._crit_edge_crit_edge
  %7 = phi i64 [ %.pre, %.tailrecurse._crit_edge_crit_edge ], [ %22, %tailrecurse ]
  %.tr14.lcssa = phi i64 [ %1, %.tailrecurse._crit_edge_crit_edge ], [ %23, %tailrecurse ]
  %.tr15.lcssa = phi i32 [ %2, %.tailrecurse._crit_edge_crit_edge ], [ %24, %tailrecurse ]
  %.lcssa = phi i32 [ %0, %.tailrecurse._crit_edge_crit_edge ], [ %18, %tailrecurse ]
  %8 = sext i32 %.lcssa to i64
  %9 = xor i64 %.tr14.lcssa, -1
  %10 = add i64 %9, %8
  %11 = add i64 %10, %7
  %12 = add nsw i32 %.lcssa, -1
  %13 = tail call noundef i32 @_Z1Cxi(i64 noundef %11, i32 noundef %12)
  %14 = mul nsw i32 %13, %.tr15.lcssa
  %15 = sext i32 %14 to i64
  %16 = load i64, ptr @ans, align 8, !tbaa !9
  %17 = add nsw i64 %16, %15
  store i64 %17, ptr @ans, align 8, !tbaa !9
  br label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph.preheader, %tailrecurse
  %indvars.iv = phi i64 [ %6, %.lr.ph.preheader ], [ %indvars.iv.next, %tailrecurse ]
  %.tr1521 = phi i32 [ %2, %.lr.ph.preheader ], [ %24, %tailrecurse ]
  %.tr1420 = phi i64 [ %1, %.lr.ph.preheader ], [ %23, %tailrecurse ]
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %18 = trunc nsw i64 %indvars.iv.next to i32
  tail call void @_Z3dfsixi(i32 noundef %18, i64 noundef %.tr1420, i32 noundef %.tr1521)
  %19 = getelementptr inbounds [21 x i64], ptr @a, i64 0, i64 %indvars.iv
  %20 = load i64, ptr %19, align 8, !tbaa !9
  %21 = add nsw i64 %20, %.tr1420
  %22 = load i64, ptr @m, align 8, !tbaa !9
  %.not.not = icmp slt i64 %21, %22
  br i1 %.not.not, label %tailrecurse, label %.loopexit

tailrecurse:                                      ; preds = %.lr.ph
  %23 = add nsw i64 %21, 1
  %24 = sub nsw i32 0, %.tr1521
  %25 = load i32, ptr @n, align 4, !tbaa !5
  %26 = icmp eq i32 %25, %18
  br i1 %26, label %tailrecurse._crit_edge, label %.lr.ph

.loopexit:                                        ; preds = %.lr.ph, %tailrecurse._crit_edge
  ret void
}

attributes #0 = { 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" }

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


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