; LLVM IR from DionysiosB/CodeForces :: 0700-0799/768B-CodeFor1.ll (Z5countxxxxx)

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z5countxxxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4) #0 {
  %6 = alloca i64, align 8
  %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
  store i64 %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !5
  store i64 %3, ptr %10, align 8, !tbaa !5
  store i64 %4, ptr %11, align 8, !tbaa !5
  %13 = load i64, ptr %9, align 8, !tbaa !5
  %14 = load i64, ptr %10, align 8, !tbaa !5
  %15 = icmp slt i64 %13, %14
  br i1 %15, label %23, label %16

16:                                               ; preds = %5
  %17 = load i64, ptr %8, align 8, !tbaa !5
  %18 = load i64, ptr %11, align 8, !tbaa !5
  %19 = icmp sgt i64 %17, %18
  br i1 %19, label %23, label %20

20:                                               ; preds = %16
  %21 = load i64, ptr %7, align 8, !tbaa !5
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %20, %16, %5
  store i64 0, ptr %6, align 8
  br label %58

24:                                               ; preds = %20
  %25 = load i64, ptr %7, align 8, !tbaa !5
  %26 = icmp eq i64 %25, 1
  br i1 %26, label %27, label %28

27:                                               ; preds = %24
  store i64 1, ptr %6, align 8
  br label %58

28:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %29 = load i64, ptr %10, align 8, !tbaa !5
  %30 = load i64, ptr %11, align 8, !tbaa !5
  %31 = add nsw i64 %29, %30
  %32 = sdiv i64 %31, 2
  store i64 %32, ptr %12, align 8, !tbaa !5
  %33 = load i64, ptr %7, align 8, !tbaa !5
  %34 = sdiv i64 %33, 2
  %35 = load i64, ptr %8, align 8, !tbaa !5
  %36 = load i64, ptr %9, align 8, !tbaa !5
  %37 = load i64, ptr %10, align 8, !tbaa !5
  %38 = load i64, ptr %12, align 8, !tbaa !5
  %39 = sub nsw i64 %38, 1
  %40 = call noundef i64 @_Z5countxxxxx(i64 noundef %34, i64 noundef %35, i64 noundef %36, i64 noundef %37, i64 noundef %39)
  %41 = load i64, ptr %7, align 8, !tbaa !5
  %42 = srem i64 %41, 2
  %43 = load i64, ptr %8, align 8, !tbaa !5
  %44 = load i64, ptr %9, align 8, !tbaa !5
  %45 = load i64, ptr %12, align 8, !tbaa !5
  %46 = load i64, ptr %12, align 8, !tbaa !5
  %47 = call noundef i64 @_Z5countxxxxx(i64 noundef %42, i64 noundef %43, i64 noundef %44, i64 noundef %45, i64 noundef %46)
  %48 = add nsw i64 %40, %47
  %49 = load i64, ptr %7, align 8, !tbaa !5
  %50 = sdiv i64 %49, 2
  %51 = load i64, ptr %8, align 8, !tbaa !5
  %52 = load i64, ptr %9, align 8, !tbaa !5
  %53 = load i64, ptr %12, align 8, !tbaa !5
  %54 = add nsw i64 %53, 1
  %55 = load i64, ptr %11, align 8, !tbaa !5
  %56 = call noundef i64 @_Z5countxxxxx(i64 noundef %50, i64 noundef %51, i64 noundef %52, i64 noundef %54, i64 noundef %55)
  %57 = add nsw i64 %48, %56
  store i64 %57, ptr %6, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %58

58:                                               ; preds = %28, %27, %23
  %59 = load i64, ptr %6, align 8
  ret i64 %59
}

; 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 = !{!"long long", !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"

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none) uwtable
define dso_local noundef i64 @_Z5countxxxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4) local_unnamed_addr #0 {
  %6 = icmp slt i64 %2, %3
  %7 = icmp sgt i64 %1, %4
  %or.cond = or i1 %6, %7
  br i1 %or.cond, label %._crit_edge, label %.lr.ph.split

.lr.ph.split:                                     ; preds = %5, %tailrecurse
  %.tr3236 = phi i64 [ %15, %tailrecurse ], [ %3, %5 ]
  %.tr35 = phi i64 [ %10, %tailrecurse ], [ %0, %5 ]
  %accumulator.tr34 = phi i64 [ %17, %tailrecurse ], [ 0, %5 ]
  %switch = icmp ult i64 %.tr35, 2
  br i1 %switch, label %._crit_edge.loopexit, label %tailrecurse

tailrecurse:                                      ; preds = %.lr.ph.split
  %8 = add nsw i64 %.tr3236, %4
  %9 = sdiv i64 %8, 2
  %10 = sdiv i64 %.tr35, 2
  %11 = add nsw i64 %9, -1
  %12 = tail call noundef i64 @_Z5countxxxxx(i64 noundef %10, i64 noundef %1, i64 noundef %2, i64 noundef %.tr3236, i64 noundef %11)
  %13 = srem i64 %.tr35, 2
  %14 = tail call noundef i64 @_Z5countxxxxx(i64 noundef %13, i64 noundef %1, i64 noundef %2, i64 noundef %9, i64 noundef %9)
  %15 = add nsw i64 %9, 1
  %16 = add i64 %12, %accumulator.tr34
  %17 = add i64 %16, %14
  %.not = icmp slt i64 %9, %2
  br i1 %.not, label %.lr.ph.split, label %._crit_edge.loopexit

._crit_edge.loopexit:                             ; preds = %tailrecurse, %.lr.ph.split
  %accumulator.tr.lcssa.ph = phi i64 [ %accumulator.tr34, %.lr.ph.split ], [ %17, %tailrecurse ]
  %.0.ph = phi i64 [ %.tr35, %.lr.ph.split ], [ 0, %tailrecurse ]
  %18 = add nsw i64 %.0.ph, %accumulator.tr.lcssa.ph
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %5
  %accumulator.ret.tr = phi i64 [ 0, %5 ], [ %18, %._crit_edge.loopexit ]
  ret i64 %accumulator.ret.tr
}

attributes #0 = { mustprogress nofree nosync nounwind willreturn memory(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)"}


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