; LLVM IR from Tunghohin/Competitive_Coding :: Luogu/p2023.ll (Z5buildiii)

; 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 { i32, i32, i64, i64, i64 }

@mod = external dso_local global i32, align 4
@a = external dso_local global [100010 x i32], align 16
@tr = external dso_local global [400040 x %struct.Node], align 16

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

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

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

61:                                               ; preds = %31, %13
  ret void
}

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z7push_upi(i32 noundef) #4

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { inlinehint 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 #5 = { 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 = !{!"int", !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 4, !11, i64 8, !11, i64 16, !11, i64 24}
!11 = !{!"long long", !7, i64 0}
!12 = !{!10, !6, i64 4}
!13 = !{!10, !11, i64 8}
!14 = !{!10, !11, i64 16}
!15 = !{!10, !11, i64 24}
!16 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 8, !17, i64 16, i64 8, !17, i64 24, i64 8, !17}
!17 = !{!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"

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

@mod = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local local_unnamed_addr global [100010 x i32], align 16
@tr = external dso_local local_unnamed_addr global [400040 x %struct.Node], align 16

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

common.ret:                                       ; preds = %3
  %5 = sext i32 %1 to i64
  %6 = getelementptr inbounds [100010 x i32], ptr @a, i64 0, i64 %5
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = load i32, ptr @mod, align 4, !tbaa !5
  %9 = srem i32 %7, %8
  %10 = sext i32 %9 to i64
  %11 = sext i32 %0 to i64
  %12 = getelementptr inbounds [400040 x %struct.Node], ptr @tr, i64 0, i64 %11
  store i32 %1, ptr %12, align 16, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 4
  store i32 %1, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !5
  %.sroa.53.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 8
  store i64 0, ptr %.sroa.53.0..sroa_idx, align 8, !tbaa !9
  %.sroa.64.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 16
  store i64 1, ptr %.sroa.64.0..sroa_idx, align 16, !tbaa !9
  %.sroa.7.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 24
  store i64 %10, ptr %.sroa.7.0..sroa_idx, align 8, !tbaa !9
  br label %common.ret24

common.ret24:                                     ; preds = %13, %common.ret
  ret void

13:                                               ; preds = %3
  %14 = sext i32 %0 to i64
  %15 = getelementptr inbounds [400040 x %struct.Node], ptr @tr, i64 0, i64 %14
  store i32 %1, ptr %15, align 16, !tbaa !5
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %15, i64 4
  store i32 %2, ptr %.sroa.5.0..sroa_idx, align 4, !tbaa !5
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %15, i64 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %.sroa.6.0..sroa_idx, i8 0, i64 24, i1 false)
  %16 = getelementptr inbounds i8, ptr %15, i64 16
  store i64 1, ptr %16, align 16, !tbaa !11
  %17 = add nsw i32 %2, %1
  %18 = ashr i32 %17, 1
  %19 = shl i32 %0, 1
  tail call void @_Z5buildiii(i32 noundef %19, i32 noundef %1, i32 noundef %18)
  %20 = or disjoint i32 %19, 1
  %21 = add nsw i32 %18, 1
  tail call void @_Z5buildiii(i32 noundef %20, i32 noundef %21, i32 noundef %2)
  tail call void @_Z7push_upi(i32 noundef %0)
  br label %common.ret24
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z7push_upi(i32 noundef) local_unnamed_addr #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { inlinehint 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}
!11 = !{!12, !10, i64 16}
!12 = !{!"_ZTS4Node", !6, i64 0, !6, i64 4, !10, i64 8, !10, i64 16, !10, i64 24}


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