; LLVM IR from DionysiosB/CodeForces :: 0500-0599 (559C-GeraldAndGiantChess)

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

%"struct.std::pair" = type { i64, i64 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z10countPathsRKSt4pairIxxES2_RKSt6vectorIxSaIxEES7_RKx(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 8 dereferenceable(8) %4) #0 {
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  %18 = alloca i32, align 4
  %19 = alloca i64, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds %"struct.std::pair", ptr %20, i32 0, i32 0
  %22 = load i64, ptr %21, align 8, !tbaa !9
  store i64 %22, ptr %12, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %"struct.std::pair", ptr %23, i32 0, i32 1
  %25 = load i64, ptr %24, align 8, !tbaa !13
  store i64 %25, ptr %13, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #2
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = getelementptr inbounds %"struct.std::pair", ptr %26, i32 0, i32 0
  %28 = load i64, ptr %27, align 8, !tbaa !9
  store i64 %28, ptr %14, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #2
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = getelementptr inbounds %"struct.std::pair", ptr %29, i32 0, i32 1
  %31 = load i64, ptr %30, align 8, !tbaa !13
  store i64 %31, ptr %15, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #2
  %32 = load i64, ptr %14, align 8, !tbaa !12
  %33 = load i64, ptr %12, align 8, !tbaa !12
  %34 = sub nsw i64 %32, %33
  store i64 %34, ptr %16, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #2
  %35 = load i64, ptr %15, align 8, !tbaa !12
  %36 = load i64, ptr %13, align 8, !tbaa !12
  %37 = sub nsw i64 %35, %36
  store i64 %37, ptr %17, align 8, !tbaa !12
  %38 = load i64, ptr %16, align 8, !tbaa !12
  %39 = icmp slt i64 %38, 0
  br i1 %39, label %43, label %40

40:                                               ; preds = %5
  %41 = load i64, ptr %17, align 8, !tbaa !12
  %42 = icmp slt i64 %41, 0
  br i1 %42, label %43, label %44

43:                                               ; preds = %40, %5
  store i64 0, ptr %6, align 8
  store i32 1, ptr %18, align 4
  br label %83

44:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #2
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = load i64, ptr %16, align 8, !tbaa !12
  %47 = load i64, ptr %17, align 8, !tbaa !12
  %48 = add nsw i64 %46, %47
  %49 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %45, i64 noundef %48) #2
  %50 = load i64, ptr %49, align 8, !tbaa !12
  store i64 %50, ptr %19, align 8, !tbaa !12
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = load i64, ptr %51, align 8, !tbaa !12
  %53 = load i64, ptr %19, align 8, !tbaa !12
  %54 = srem i64 %53, %52
  store i64 %54, ptr %19, align 8, !tbaa !12
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = load i64, ptr %16, align 8, !tbaa !12
  %57 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %55, i64 noundef %56) #2
  %58 = load i64, ptr %57, align 8, !tbaa !12
  %59 = load i64, ptr %19, align 8, !tbaa !12
  %60 = mul nsw i64 %59, %58
  store i64 %60, ptr %19, align 8, !tbaa !12
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = load i64, ptr %61, align 8, !tbaa !12
  %63 = load i64, ptr %19, align 8, !tbaa !12
  %64 = srem i64 %63, %62
  store i64 %64, ptr %19, align 8, !tbaa !12
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  %66 = load i64, ptr %17, align 8, !tbaa !12
  %67 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %65, i64 noundef %66) #2
  %68 = load i64, ptr %67, align 8, !tbaa !12
  %69 = load i64, ptr %19, align 8, !tbaa !12
  %70 = mul nsw i64 %69, %68
  store i64 %70, ptr %19, align 8, !tbaa !12
  %71 = load ptr, ptr %11, align 8, !tbaa !5
  %72 = load i64, ptr %71, align 8, !tbaa !12
  %73 = load i64, ptr %19, align 8, !tbaa !12
  %74 = srem i64 %73, %72
  store i64 %74, ptr %19, align 8, !tbaa !12
  %75 = load i64, ptr %19, align 8, !tbaa !12
  %76 = load ptr, ptr %11, align 8, !tbaa !5
  %77 = load i64, ptr %76, align 8, !tbaa !12
  %78 = add nsw i64 %75, %77
  %79 = load ptr, ptr %11, align 8, !tbaa !5
  %80 = load i64, ptr %79, align 8, !tbaa !12
  %81 = srem i64 %78, %80
  store i64 %81, ptr %19, align 8, !tbaa !12
  %82 = load i64, ptr %19, align 8, !tbaa !12
  store i64 %82, ptr %6, align 8
  store i32 1, ptr %18, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #2
  br label %83

83:                                               ; preds = %44, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  %84 = load i64, ptr %6, align 8
  ret i64 %84
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #0 align 2

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

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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTSSt4pairIxxE", !11, i64 0, !11, i64 8}
!11 = !{!"long long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 8}


; 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 nounwind uwtable
define dso_local noundef i64 @_Z10countPathsRKSt4pairIxxES2_RKSt6vectorIxSaIxEES7_RKx(ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %1, ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef nonnull align 8 dereferenceable(24) %3, ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %4) local_unnamed_addr #0 {
  %6 = load i64, ptr %0, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load i64, ptr %7, align 8, !tbaa !10
  %9 = load i64, ptr %1, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  %11 = load i64, ptr %10, align 8, !tbaa !10
  %12 = sub nsw i64 %9, %6
  %13 = sub nsw i64 %11, %8
  %14 = icmp slt i64 %12, 0
  %15 = icmp slt i64 %13, 0
  %or.cond = select i1 %14, i1 true, i1 %15
  br i1 %or.cond, label %34, label %16

16:                                               ; preds = %5
  %17 = add nuw nsw i64 %13, %12
  %18 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %2, i64 noundef %17) #1
  %19 = load i64, ptr %18, align 8, !tbaa !11
  %20 = load i64, ptr %4, align 8, !tbaa !11
  %21 = srem i64 %19, %20
  %22 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %12) #1
  %23 = load i64, ptr %22, align 8, !tbaa !11
  %24 = mul nsw i64 %23, %21
  %25 = load i64, ptr %4, align 8, !tbaa !11
  %26 = srem i64 %24, %25
  %27 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %13) #1
  %28 = load i64, ptr %27, align 8, !tbaa !11
  %29 = mul nsw i64 %28, %26
  %30 = load i64, ptr %4, align 8, !tbaa !11
  %31 = srem i64 %29, %30
  %32 = add nsw i64 %31, %30
  %33 = srem i64 %32, %30
  br label %34

34:                                               ; preds = %5, %16
  %.0 = phi i64 [ %33, %16 ], [ 0, %5 ]
  ret i64 %.0
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

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 = { 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, !7, i64 0}
!6 = !{!"_ZTSSt4pairIxxE", !7, i64 0, !7, i64 8}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass