; LLVM IR from tangjz/acm-icpc :: lydsy/4253.ll (Z3dfsix)

; 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
@sum = external dso_local global i32, align 4
@n = external dso_local global i64, align 8
@pp = external dso_local global [16 x i64], align 16
@sei = external dso_local global [16 x i64], align 16
@ans = external dso_local global [65536 x i64], align 16

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsix(i32 noundef %0, i64 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %5 = load i32, ptr %3, align 4, !tbaa !5
  %6 = load i32, ptr @cnt, align 4, !tbaa !5
  %7 = icmp eq i32 %5, %6
  br i1 %7, label %8, label %14

8:                                                ; preds = %2
  %9 = load i64, ptr %4, align 8, !tbaa !9
  %10 = load i32, ptr @sum, align 4, !tbaa !5
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr @sum, align 4, !tbaa !5
  %12 = sext i32 %10 to i64
  %13 = getelementptr inbounds [65536 x i64], ptr @ans, i64 0, i64 %12
  store i64 %9, ptr %13, align 8, !tbaa !9
  br label %94

14:                                               ; preds = %2
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  %17 = load i64, ptr %4, align 8, !tbaa !9
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [16 x i64], ptr @sei, i64 0, i64 %19
  %21 = load i64, ptr %20, align 8, !tbaa !9
  %22 = load i64, ptr @n, align 8, !tbaa !9
  %23 = call noundef i64 @_Z7mod_addxxx(i64 noundef %17, i64 noundef %21, i64 noundef %22)
  call void @_Z3dfsix(i32 noundef %16, i64 noundef %23)
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [16 x i64], ptr @pp, i64 0, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !9
  %28 = icmp ne i64 %27, 2
  br i1 %28, label %29, label %46

29:                                               ; preds = %14
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  %32 = load i64, ptr %4, align 8, !tbaa !9
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [16 x i64], ptr @pp, i64 0, i64 %34
  %36 = load i64, ptr %35, align 8, !tbaa !9
  %37 = sub nsw i64 %36, 1
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [16 x i64], ptr @sei, i64 0, i64 %39
  %41 = load i64, ptr %40, align 8, !tbaa !9
  %42 = load i64, ptr @n, align 8, !tbaa !9
  %43 = call noundef i64 @_Z7mod_mulxxx(i64 noundef %37, i64 noundef %41, i64 noundef %42)
  %44 = load i64, ptr @n, align 8, !tbaa !9
  %45 = call noundef i64 @_Z7mod_addxxx(i64 noundef %32, i64 noundef %43, i64 noundef %44)
  call void @_Z3dfsix(i32 noundef %31, i64 noundef %45)
  br label %46

46:                                               ; preds = %29, %14
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [16 x i64], ptr @pp, i64 0, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !9
  %51 = and i64 %50, 1
  %52 = icmp ne i64 %51, 0
  br i1 %52, label %94, label %53

53:                                               ; preds = %46
  %54 = load i32, ptr %3, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [16 x i64], ptr @pp, i64 0, i64 %55
  %57 = load i64, ptr %56, align 8, !tbaa !9
  %58 = icmp sgt i64 %57, 4
  br i1 %58, label %59, label %94

59:                                               ; preds = %53
  %60 = load i32, ptr %3, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  %62 = load i64, ptr %4, align 8, !tbaa !9
  %63 = load i32, ptr %3, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [16 x i64], ptr @pp, i64 0, i64 %64
  %66 = load i64, ptr %65, align 8, !tbaa !9
  %67 = ashr i64 %66, 1
  %68 = add nsw i64 %67, 1
  %69 = load i32, ptr %3, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [16 x i64], ptr @sei, i64 0, i64 %70
  %72 = load i64, ptr %71, align 8, !tbaa !9
  %73 = load i64, ptr @n, align 8, !tbaa !9
  %74 = call noundef i64 @_Z7mod_mulxxx(i64 noundef %68, i64 noundef %72, i64 noundef %73)
  %75 = load i64, ptr @n, align 8, !tbaa !9
  %76 = call noundef i64 @_Z7mod_addxxx(i64 noundef %62, i64 noundef %74, i64 noundef %75)
  call void @_Z3dfsix(i32 noundef %61, i64 noundef %76)
  %77 = load i32, ptr %3, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  %79 = load i64, ptr %4, align 8, !tbaa !9
  %80 = load i32, ptr %3, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [16 x i64], ptr @pp, i64 0, i64 %81
  %83 = load i64, ptr %82, align 8, !tbaa !9
  %84 = ashr i64 %83, 1
  %85 = sub nsw i64 %84, 1
  %86 = load i32, ptr %3, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [16 x i64], ptr @sei, i64 0, i64 %87
  %89 = load i64, ptr %88, align 8, !tbaa !9
  %90 = load i64, ptr @n, align 8, !tbaa !9
  %91 = call noundef i64 @_Z7mod_mulxxx(i64 noundef %85, i64 noundef %89, i64 noundef %90)
  %92 = load i64, ptr @n, align 8, !tbaa !9
  %93 = call noundef i64 @_Z7mod_addxxx(i64 noundef %79, i64 noundef %91, i64 noundef %92)
  call void @_Z3dfsix(i32 noundef %78, i64 noundef %93)
  br label %94

94:                                               ; preds = %59, %53, %46, %8
  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"

@cnt = external dso_local local_unnamed_addr global i32, align 4
@sum = external dso_local local_unnamed_addr global i32, align 4
@n = external dso_local local_unnamed_addr global i64, align 8
@pp = external dso_local local_unnamed_addr global [16 x i64], align 16
@sei = external dso_local local_unnamed_addr global [16 x i64], align 16
@ans = external dso_local local_unnamed_addr global [65536 x i64], align 16

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

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

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

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

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %2
  %.tr23.lcssa = phi i64 [ %1, %2 ], [ %40, %tailrecurse ]
  %6 = load i32, ptr @sum, align 4, !tbaa !5
  %7 = add nsw i32 %6, 1
  store i32 %7, ptr @sum, align 4, !tbaa !5
  %8 = sext i32 %6 to i64
  %9 = getelementptr inbounds [65536 x i64], ptr @ans, i64 0, i64 %8
  store i64 %.tr23.lcssa, ptr %9, align 8, !tbaa !9
  br label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph.preheader, %tailrecurse
  %indvars.iv = phi i64 [ %5, %.lr.ph.preheader ], [ %indvars.iv.next, %tailrecurse ]
  %.tr2326 = phi i64 [ %1, %.lr.ph.preheader ], [ %40, %tailrecurse ]
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %10 = getelementptr inbounds [16 x i64], ptr @sei, i64 0, i64 %indvars.iv
  %11 = load i64, ptr %10, align 8, !tbaa !9
  %12 = load i64, ptr @n, align 8, !tbaa !9
  %13 = tail call noundef i64 @_Z7mod_addxxx(i64 noundef %.tr2326, i64 noundef %11, i64 noundef %12)
  %14 = trunc nsw i64 %indvars.iv.next to i32
  tail call void @_Z3dfsix(i32 noundef %14, i64 noundef %13)
  %15 = getelementptr inbounds [16 x i64], ptr @pp, i64 0, i64 %indvars.iv
  %16 = load i64, ptr %15, align 8, !tbaa !9
  %.not = icmp eq i64 %16, 2
  br i1 %.not, label %.loopexit, label %17

17:                                               ; preds = %.lr.ph
  %18 = add nsw i64 %16, -1
  %19 = load i64, ptr %10, align 8, !tbaa !9
  %20 = load i64, ptr @n, align 8, !tbaa !9
  %21 = tail call noundef i64 @_Z7mod_mulxxx(i64 noundef %18, i64 noundef %19, i64 noundef %20)
  %22 = load i64, ptr @n, align 8, !tbaa !9
  %23 = tail call noundef i64 @_Z7mod_addxxx(i64 noundef %.tr2326, i64 noundef %21, i64 noundef %22)
  tail call void @_Z3dfsix(i32 noundef %14, i64 noundef %23)
  %.pre = load i64, ptr %15, align 8, !tbaa !9
  %24 = and i64 %.pre, 1
  %.not22 = icmp eq i64 %24, 0
  %25 = icmp sgt i64 %.pre, 4
  %or.cond = and i1 %25, %.not22
  br i1 %or.cond, label %tailrecurse, label %.loopexit

tailrecurse:                                      ; preds = %17
  %26 = lshr exact i64 %.pre, 1
  %27 = add nuw nsw i64 %26, 1
  %28 = load i64, ptr %10, align 8, !tbaa !9
  %29 = load i64, ptr @n, align 8, !tbaa !9
  %30 = tail call noundef i64 @_Z7mod_mulxxx(i64 noundef %27, i64 noundef %28, i64 noundef %29)
  %31 = load i64, ptr @n, align 8, !tbaa !9
  %32 = tail call noundef i64 @_Z7mod_addxxx(i64 noundef %.tr2326, i64 noundef %30, i64 noundef %31)
  tail call void @_Z3dfsix(i32 noundef %14, i64 noundef %32)
  %33 = load i64, ptr %15, align 8, !tbaa !9
  %34 = ashr i64 %33, 1
  %35 = add nsw i64 %34, -1
  %36 = load i64, ptr %10, align 8, !tbaa !9
  %37 = load i64, ptr @n, align 8, !tbaa !9
  %38 = tail call noundef i64 @_Z7mod_mulxxx(i64 noundef %35, i64 noundef %36, i64 noundef %37)
  %39 = load i64, ptr @n, align 8, !tbaa !9
  %40 = tail call noundef i64 @_Z7mod_addxxx(i64 noundef %.tr2326, i64 noundef %38, i64 noundef %39)
  %41 = load i32, ptr @cnt, align 4, !tbaa !5
  %42 = icmp eq i32 %41, %14
  br i1 %42, label %tailrecurse._crit_edge, label %.lr.ph

.loopexit:                                        ; preds = %.lr.ph, %17, %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,IPSCCPPass,IndVarSimplifyPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass