; LLVM IR from Tunghohin/Competitive_Coding :: Codeforces/cf1691_D.ll (Z5buildxxx)

; 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.Node = type { i64, i64, i64, i64, i64, i64 }

@a = external dso_local global [200010 x i64], align 16
@tr = external dso_local global [800040 x %struct.Node], align 16

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z7push_upx(i64 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5buildxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2) #1 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca %struct.Node, align 8
  %8 = alloca %struct.Node, align 8
  %9 = alloca i64, align 8
  store i64 %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !5
  %10 = load i64, ptr %5, align 8, !tbaa !5
  %11 = load i64, ptr %6, align 8, !tbaa !5
  %12 = icmp eq i64 %10, %11
  br i1 %12, label %13, label %36

13:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 48, ptr %7) #3
  %14 = getelementptr inbounds %struct.Node, ptr %7, i32 0, i32 0
  %15 = load i64, ptr %5, align 8, !tbaa !5
  store i64 %15, ptr %14, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.Node, ptr %7, i32 0, i32 1
  %17 = load i64, ptr %6, align 8, !tbaa !5
  store i64 %17, ptr %16, align 8, !tbaa !11
  %18 = getelementptr inbounds %struct.Node, ptr %7, i32 0, i32 2
  %19 = load i64, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds [200010 x i64], ptr @a, i64 0, i64 %19
  %21 = load i64, ptr %20, align 8, !tbaa !5
  store i64 %21, ptr %18, align 8, !tbaa !12
  %22 = getelementptr inbounds %struct.Node, ptr %7, i32 0, i32 3
  %23 = load i64, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds [200010 x i64], ptr @a, i64 0, i64 %23
  %25 = load i64, ptr %24, align 8, !tbaa !5
  store i64 %25, ptr %22, align 8, !tbaa !13
  %26 = getelementptr inbounds %struct.Node, ptr %7, i32 0, i32 4
  %27 = load i64, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds [200010 x i64], ptr @a, i64 0, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !5
  store i64 %29, ptr %26, align 8, !tbaa !14
  %30 = getelementptr inbounds %struct.Node, ptr %7, i32 0, i32 5
  %31 = load i64, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds [200010 x i64], ptr @a, i64 0, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !5
  store i64 %33, ptr %30, align 8, !tbaa !15
  %34 = load i64, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds [800040 x %struct.Node], ptr @tr, i64 0, i64 %34
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %35, ptr align 8 %7, i64 48, i1 false), !tbaa.struct !16
  call void @llvm.lifetime.end.p0(i64 48, ptr %7) #3
  br label %62

36:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 48, ptr %8) #3
  %37 = getelementptr inbounds %struct.Node, ptr %8, i32 0, i32 0
  %38 = load i64, ptr %5, align 8, !tbaa !5
  store i64 %38, ptr %37, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.Node, ptr %8, i32 0, i32 1
  %40 = load i64, ptr %6, align 8, !tbaa !5
  store i64 %40, ptr %39, align 8, !tbaa !11
  %41 = getelementptr inbounds %struct.Node, ptr %8, i32 0, i32 2
  store i64 0, ptr %41, align 8, !tbaa !12
  %42 = getelementptr inbounds %struct.Node, ptr %8, i32 0, i32 3
  store i64 0, ptr %42, align 8, !tbaa !13
  %43 = getelementptr inbounds %struct.Node, ptr %8, i32 0, i32 4
  store i64 0, ptr %43, align 8, !tbaa !14
  %44 = getelementptr inbounds %struct.Node, ptr %8, i32 0, i32 5
  store i64 0, ptr %44, align 8, !tbaa !15
  %45 = load i64, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds [800040 x %struct.Node], ptr @tr, i64 0, i64 %45
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %46, ptr align 8 %8, i64 48, i1 false), !tbaa.struct !16
  call void @llvm.lifetime.end.p0(i64 48, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %47 = load i64, ptr %5, align 8, !tbaa !5
  %48 = load i64, ptr %6, align 8, !tbaa !5
  %49 = add nsw i64 %47, %48
  %50 = ashr i64 %49, 1
  store i64 %50, ptr %9, align 8, !tbaa !5
  %51 = load i64, ptr %4, align 8, !tbaa !5
  %52 = shl i64 %51, 1
  %53 = load i64, ptr %5, align 8, !tbaa !5
  %54 = load i64, ptr %9, align 8, !tbaa !5
  call void @_Z5buildxxx(i64 noundef %52, i64 noundef %53, i64 noundef %54)
  %55 = load i64, ptr %4, align 8, !tbaa !5
  %56 = shl i64 %55, 1
  %57 = or i64 %56, 1
  %58 = load i64, ptr %9, align 8, !tbaa !5
  %59 = add nsw i64 %58, 1
  %60 = load i64, ptr %6, align 8, !tbaa !5
  call void @_Z5buildxxx(i64 noundef %57, i64 noundef %59, i64 noundef %60)
  %61 = load i64, ptr %4, align 8, !tbaa !5
  call void @_Z7push_upx(i64 noundef %61)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %62

62:                                               ; preds = %36, %13
  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) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS4Node", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!11 = !{!10, !6, i64 8}
!12 = !{!10, !6, i64 16}
!13 = !{!10, !6, i64 24}
!14 = !{!10, !6, i64 32}
!15 = !{!10, !6, i64 40}
!16 = !{i64 0, i64 8, !5, i64 8, i64 8, !5, i64 16, i64 8, !5, i64 24, i64 8, !5, i64 32, i64 8, !5, i64 40, i64 8, !5}


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

%struct.Node = type { i64, i64, i64, i64, i64, i64 }

@a = external dso_local local_unnamed_addr global [200010 x i64], align 16
@tr = external dso_local local_unnamed_addr global [800040 x %struct.Node], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z7push_upx(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5buildxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq i64 %1, %2
  br i1 %4, label %common.ret, label %10

common.ret:                                       ; preds = %3
  %5 = getelementptr inbounds [200010 x i64], ptr @a, i64 0, i64 %1
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds [800040 x %struct.Node], ptr @tr, i64 0, i64 %0
  store i64 %1, ptr %7, align 16, !tbaa !5
  %.sroa.43.0..sroa_idx = getelementptr inbounds i8, ptr %7, i64 8
  store i64 %1, ptr %.sroa.43.0..sroa_idx, align 8, !tbaa !5
  %.sroa.54.0..sroa_idx = getelementptr inbounds i8, ptr %7, i64 16
  %8 = insertelement <4 x i64> poison, i64 %6, i64 0
  %9 = shufflevector <4 x i64> %8, <4 x i64> poison, <4 x i32> zeroinitializer
  store <4 x i64> %9, ptr %.sroa.54.0..sroa_idx, align 16, !tbaa !5
  br label %common.ret29

common.ret29:                                     ; preds = %10, %common.ret
  ret void

10:                                               ; preds = %3
  %11 = getelementptr inbounds [800040 x %struct.Node], ptr @tr, i64 0, i64 %0
  store i64 %1, ptr %11, align 16, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %11, i64 8
  store i64 %2, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !5
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %11, i64 16
  %12 = add nsw i64 %2, %1
  %13 = ashr i64 %12, 1
  %14 = shl i64 %0, 1
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %.sroa.5.0..sroa_idx, i8 0, i64 32, i1 false)
  tail call void @_Z5buildxxx(i64 noundef %14, i64 noundef %1, i64 noundef %13)
  %15 = or disjoint i64 %14, 1
  %16 = add nsw i64 %13, 1
  tail call void @_Z5buildxxx(i64 noundef %15, i64 noundef %16, i64 noundef %2)
  tail call void @_Z7push_upx(i64 noundef %0)
  br label %common.ret29
}

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

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass