; LLVM IR from Tunghohin/Competitive_Coding :: Luogu/p3372.ll (Z9push_downi)

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

@tr = external dso_local global [400040 x %struct.Node], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z9push_downi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [400040 x %struct.Node], ptr @tr, i64 0, i64 %7
  store ptr %8, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = shl i32 %9, 1
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [400040 x %struct.Node], ptr @tr, i64 0, i64 %11
  store ptr %12, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = shl i32 %13, 1
  %15 = or i32 %14, 1
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [400040 x %struct.Node], ptr @tr, i64 0, i64 %16
  store ptr %17, ptr %5, align 8, !tbaa !9
  %18 = load ptr, ptr %3, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.Node, ptr %18, i32 0, i32 2
  %20 = load i64, ptr %19, align 8, !tbaa !11
  %21 = icmp ne i64 %20, 0
  br i1 %21, label %22, label %73

22:                                               ; preds = %1
  %23 = load ptr, ptr %3, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.Node, ptr %23, i32 0, i32 2
  %25 = load i64, ptr %24, align 8, !tbaa !11
  %26 = load ptr, ptr %4, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.Node, ptr %26, i32 0, i32 2
  %28 = load i64, ptr %27, align 8, !tbaa !11
  %29 = add nsw i64 %28, %25
  store i64 %29, ptr %27, align 8, !tbaa !11
  %30 = load ptr, ptr %4, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.Node, ptr %30, i32 0, i32 1
  %32 = load i32, ptr %31, align 4, !tbaa !14
  %33 = load ptr, ptr %4, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.Node, ptr %33, i32 0, i32 0
  %35 = load i32, ptr %34, align 8, !tbaa !15
  %36 = sub nsw i32 %32, %35
  %37 = add nsw i32 %36, 1
  %38 = sext i32 %37 to i64
  %39 = load ptr, ptr %3, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.Node, ptr %39, i32 0, i32 2
  %41 = load i64, ptr %40, align 8, !tbaa !11
  %42 = mul nsw i64 %38, %41
  %43 = load ptr, ptr %4, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.Node, ptr %43, i32 0, i32 3
  %45 = load i64, ptr %44, align 8, !tbaa !16
  %46 = add nsw i64 %45, %42
  store i64 %46, ptr %44, align 8, !tbaa !16
  %47 = load ptr, ptr %3, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.Node, ptr %47, i32 0, i32 2
  %49 = load i64, ptr %48, align 8, !tbaa !11
  %50 = load ptr, ptr %5, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.Node, ptr %50, i32 0, i32 2
  %52 = load i64, ptr %51, align 8, !tbaa !11
  %53 = add nsw i64 %52, %49
  store i64 %53, ptr %51, align 8, !tbaa !11
  %54 = load ptr, ptr %5, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.Node, ptr %54, i32 0, i32 1
  %56 = load i32, ptr %55, align 4, !tbaa !14
  %57 = load ptr, ptr %5, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.Node, ptr %57, i32 0, i32 0
  %59 = load i32, ptr %58, align 8, !tbaa !15
  %60 = sub nsw i32 %56, %59
  %61 = add nsw i32 %60, 1
  %62 = sext i32 %61 to i64
  %63 = load ptr, ptr %3, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.Node, ptr %63, i32 0, i32 2
  %65 = load i64, ptr %64, align 8, !tbaa !11
  %66 = mul nsw i64 %62, %65
  %67 = load ptr, ptr %5, align 8, !tbaa !9
  %68 = getelementptr inbounds %struct.Node, ptr %67, i32 0, i32 3
  %69 = load i64, ptr %68, align 8, !tbaa !16
  %70 = add nsw i64 %69, %66
  store i64 %70, ptr %68, align 8, !tbaa !16
  %71 = load ptr, ptr %3, align 8, !tbaa !9
  %72 = getelementptr inbounds %struct.Node, ptr %71, i32 0, i32 2
  store i64 0, ptr %72, align 8, !tbaa !11
  br label %73

73:                                               ; preds = %22, %1
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  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 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"_ZTS4Node", !6, i64 0, !6, i64 4, !13, i64 8, !13, i64 16}
!13 = !{!"long long", !7, i64 0}
!14 = !{!12, !6, i64 4}
!15 = !{!12, !6, i64 0}
!16 = !{!12, !13, i64 16}


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

@tr = external dso_local local_unnamed_addr global [400040 x %struct.Node], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z9push_downi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [400040 x %struct.Node], ptr @tr, i64 0, i64 %2, i32 2
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %40, label %5

5:                                                ; preds = %1
  %6 = shl i32 %0, 1
  %7 = or disjoint i32 %6, 1
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [400040 x %struct.Node], ptr @tr, i64 0, i64 %8
  %10 = sext i32 %6 to i64
  %11 = getelementptr inbounds [400040 x %struct.Node], ptr @tr, i64 0, i64 %10
  %12 = getelementptr inbounds i8, ptr %11, i64 8
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = add nsw i64 %13, %4
  store i64 %14, ptr %12, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %11, i64 4
  %16 = load i32, ptr %15, align 4, !tbaa !11
  %17 = load i32, ptr %11, align 16, !tbaa !12
  %18 = add i32 %16, 1
  %19 = sub i32 %18, %17
  %20 = sext i32 %19 to i64
  %21 = load i64, ptr %3, align 8, !tbaa !5
  %22 = mul nsw i64 %21, %20
  %23 = getelementptr inbounds i8, ptr %11, i64 16
  %24 = load i64, ptr %23, align 16, !tbaa !13
  %25 = add nsw i64 %22, %24
  store i64 %25, ptr %23, align 16, !tbaa !13
  %26 = getelementptr inbounds i8, ptr %9, i64 8
  %27 = load i64, ptr %26, align 16, !tbaa !5
  %28 = add nsw i64 %27, %21
  store i64 %28, ptr %26, align 16, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %9, i64 4
  %30 = load i32, ptr %29, align 4, !tbaa !11
  %31 = load i32, ptr %9, align 8, !tbaa !12
  %32 = add i32 %30, 1
  %33 = sub i32 %32, %31
  %34 = sext i32 %33 to i64
  %35 = load i64, ptr %3, align 8, !tbaa !5
  %36 = mul nsw i64 %35, %34
  %37 = getelementptr inbounds i8, ptr %9, i64 16
  %38 = load i64, ptr %37, align 8, !tbaa !13
  %39 = add nsw i64 %36, %38
  store i64 %39, ptr %37, align 8, !tbaa !13
  store i64 0, ptr %3, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %5, %1
  ret void
}

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass