; LLVM IR from tangjz/acm-icpc :: uvalive/6912.ll (Z3dfsiii)

; 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
@tot = external dso_local global i32, align 4
@seq = external dso_local global [12 x i32], align 16
@pow2 = external dso_local global [12 x i32], align 16
@tmp = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  %7 = load i32, ptr %4, align 4, !tbaa !5
  %8 = load i32, ptr @tot, align 4, !tbaa !5
  %9 = icmp eq i32 %7, %8
  br i1 %9, label %10, label %43

10:                                               ; preds = %3
  %11 = load i32, ptr %6, align 4, !tbaa !5
  %12 = and i32 %11, 1
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %26

14:                                               ; preds = %10
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = sub nsw i32 %15, 1
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [12 x i32], ptr @pow2, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = load i32, ptr @n, align 4, !tbaa !5
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = sdiv i32 %20, %21
  %23 = mul nsw i32 %19, %22
  %24 = load i32, ptr @tmp, align 4, !tbaa !5
  %25 = add nsw i32 %24, %23
  store i32 %25, ptr @tmp, align 4, !tbaa !5
  br label %42

26:                                               ; preds = %10
  %27 = load i32, ptr %6, align 4, !tbaa !5
  %28 = icmp sgt i32 %27, 0
  br i1 %28, label %29, label %41

29:                                               ; preds = %26
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = sub nsw i32 %30, 1
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [12 x i32], ptr @pow2, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = load i32, ptr @n, align 4, !tbaa !5
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = sdiv i32 %35, %36
  %38 = mul nsw i32 %34, %37
  %39 = load i32, ptr @tmp, align 4, !tbaa !5
  %40 = sub nsw i32 %39, %38
  store i32 %40, ptr @tmp, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %29, %26
  br label %42

42:                                               ; preds = %41, %14
  br label %58

43:                                               ; preds = %3
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z3dfsiii(i32 noundef %45, i32 noundef %46, i32 noundef %47)
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [12 x i32], ptr @seq, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = mul nsw i32 %50, %54
  %56 = load i32, ptr %6, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  call void @_Z3dfsiii(i32 noundef %49, i32 noundef %55, i32 noundef %57)
  br label %58

58:                                               ; preds = %43, %42
  ret void
}

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

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

@n = external dso_local local_unnamed_addr global i32, align 4
@tot = external dso_local local_unnamed_addr global i32, align 4
@seq = external dso_local local_unnamed_addr global [12 x i32], align 16
@pow2 = external dso_local local_unnamed_addr global [12 x i32], align 16
@tmp = 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 @_Z3dfsiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = load i32, ptr @tot, align 4, !tbaa !5
  %5 = icmp eq i32 %4, %0
  br i1 %5, label %tailrecurse._crit_edge, label %tailrecurse.preheader

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

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %3
  %.tr15.lcssa = phi i32 [ %1, %3 ], [ %33, %tailrecurse ]
  %.tr16.lcssa = phi i32 [ %2, %3 ], [ %34, %tailrecurse ]
  %7 = and i32 %.tr16.lcssa, 1
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %18, label %8

8:                                                ; preds = %tailrecurse._crit_edge
  %9 = add nsw i32 %.tr16.lcssa, -1
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [12 x i32], ptr @pow2, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = sdiv i32 %13, %.tr15.lcssa
  %15 = mul nsw i32 %14, %12
  %16 = load i32, ptr @tmp, align 4, !tbaa !5
  %17 = add nsw i32 %16, %15
  br label %.sink.split

18:                                               ; preds = %tailrecurse._crit_edge
  %19 = icmp sgt i32 %.tr16.lcssa, 0
  br i1 %19, label %20, label %37

20:                                               ; preds = %18
  %21 = add nsw i32 %.tr16.lcssa, -1
  %22 = zext nneg i32 %21 to i64
  %23 = getelementptr inbounds [12 x i32], ptr @pow2, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = load i32, ptr @n, align 4, !tbaa !5
  %26 = sdiv i32 %25, %.tr15.lcssa
  %27 = mul nsw i32 %26, %24
  %28 = load i32, ptr @tmp, align 4, !tbaa !5
  %29 = sub nsw i32 %28, %27
  br label %.sink.split

tailrecurse:                                      ; preds = %tailrecurse.preheader, %tailrecurse
  %indvars.iv = phi i64 [ %6, %tailrecurse.preheader ], [ %indvars.iv.next, %tailrecurse ]
  %.tr1619 = phi i32 [ %2, %tailrecurse.preheader ], [ %34, %tailrecurse ]
  %.tr1518 = phi i32 [ %1, %tailrecurse.preheader ], [ %33, %tailrecurse ]
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %30 = trunc nsw i64 %indvars.iv.next to i32
  tail call void @_Z3dfsiii(i32 noundef %30, i32 noundef %.tr1518, i32 noundef %.tr1619)
  %31 = getelementptr inbounds [12 x i32], ptr @seq, i64 0, i64 %indvars.iv
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = mul nsw i32 %32, %.tr1518
  %34 = add nsw i32 %.tr1619, 1
  %35 = load i32, ptr @tot, align 4, !tbaa !5
  %36 = icmp eq i32 %35, %30
  br i1 %36, label %tailrecurse._crit_edge, label %tailrecurse

.sink.split:                                      ; preds = %20, %8
  %.sink = phi i32 [ %17, %8 ], [ %29, %20 ]
  store i32 %.sink, ptr @tmp, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %.sink.split, %18
  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,IPSCCPPass,IndVarSimplifyPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass