; LLVM IR from reyadussalahin/problem-solving :: graph/dfs/codeforces/F1294F/Solution.ll (Z6updateP5ChainS_)

; 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.Chain = type { i32, i32 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6updateP5ChainS_(ptr noundef %0, i64 %1) #0 {
  %3 = alloca %struct.Chain, align 4
  %4 = alloca ptr, align 8
  store i64 %1, ptr %3, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.Chain, ptr %3, i32 0, i32 1
  %6 = load i32, ptr %5, align 4, !tbaa !9
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.Chain, ptr %7, i64 0
  %9 = getelementptr inbounds %struct.Chain, ptr %8, i32 0, i32 1
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = icmp sge i32 %6, %10
  br i1 %11, label %12, label %23

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.Chain, ptr %13, i64 1
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.Chain, ptr %15, i64 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %16, ptr align 4 %14, i64 8, i1 false), !tbaa.struct !12
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.Chain, ptr %17, i64 0
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.Chain, ptr %19, i64 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %20, ptr align 4 %18, i64 8, i1 false), !tbaa.struct !12
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.Chain, ptr %21, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %22, ptr align 4 %3, i64 8, i1 false), !tbaa.struct !12
  br label %51

23:                                               ; preds = %2
  %24 = getelementptr inbounds %struct.Chain, ptr %3, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.Chain, ptr %26, i64 1
  %28 = getelementptr inbounds %struct.Chain, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = icmp sge i32 %25, %29
  br i1 %30, label %31, label %38

31:                                               ; preds = %23
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.Chain, ptr %32, i64 1
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.Chain, ptr %34, i64 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %35, ptr align 4 %33, i64 8, i1 false), !tbaa.struct !12
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.Chain, ptr %36, i64 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %37, ptr align 4 %3, i64 8, i1 false), !tbaa.struct !12
  br label %50

38:                                               ; preds = %23
  %39 = getelementptr inbounds %struct.Chain, ptr %3, i32 0, i32 1
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.Chain, ptr %41, i64 2
  %43 = getelementptr inbounds %struct.Chain, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %43, align 4, !tbaa !9
  %45 = icmp sgt i32 %40, %44
  br i1 %45, label %46, label %49

46:                                               ; preds = %38
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.Chain, ptr %47, i64 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %48, ptr align 4 %3, i64 8, i1 false), !tbaa.struct !12
  br label %49

49:                                               ; preds = %46, %38
  br label %50

50:                                               ; preds = %49, %31
  br label %51

51:                                               ; preds = %50, %12
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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 nounwind willreturn memory(argmem: readwrite) }

!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 4}
!10 = !{!"_ZTS5Chain", !11, i64 0, !11, i64 4}
!11 = !{!"int", !7, i64 0}
!12 = !{i64 0, i64 4, !13, i64 4, i64 4, !13}
!13 = !{!11, !11, 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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z6updateP5ChainS_(ptr nocapture noundef %0, i64 %1) local_unnamed_addr #0 {
  %.sroa.0.0.extract.trunc = trunc i64 %1 to i32
  %.sroa.4.0.extract.shift = lshr i64 %1, 32
  %.sroa.4.0.extract.trunc = trunc nuw i64 %.sroa.4.0.extract.shift to i32
  %3 = getelementptr inbounds i8, ptr %0, i64 4
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %.not = icmp sgt i32 %4, %.sroa.4.0.extract.trunc
  br i1 %.not, label %8, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load <2 x i64>, ptr %0, align 4
  store <2 x i64> %7, ptr %6, align 4
  br label %.sink.split

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %0, i64 12
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %.not20 = icmp sgt i32 %10, %.sroa.4.0.extract.trunc
  br i1 %.not20, label %15, label %11

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  %14 = load i64, ptr %12, align 4
  store i64 %14, ptr %13, align 4
  br label %.sink.split

15:                                               ; preds = %8
  %16 = getelementptr inbounds i8, ptr %0, i64 20
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = icmp slt i32 %17, %.sroa.4.0.extract.trunc
  br i1 %18, label %19, label %21

19:                                               ; preds = %15
  %20 = getelementptr inbounds i8, ptr %0, i64 16
  br label %.sink.split

.sink.split:                                      ; preds = %5, %19, %11
  %.sink21 = phi ptr [ %12, %11 ], [ %20, %19 ], [ %0, %5 ]
  %.sink = phi ptr [ %9, %11 ], [ %16, %19 ], [ %3, %5 ]
  store i32 %.sroa.0.0.extract.trunc, ptr %.sink21, align 4, !tbaa !10
  store i32 %.sroa.4.0.extract.trunc, ptr %.sink, align 4, !tbaa !10
  br label %21

21:                                               ; preds = %.sink.split, %15
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, 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, !7, i64 4}
!6 = !{!"_ZTS5Chain", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!7, !7, i64 0}


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