; LLVM IR from Tunghohin/Competitive_Coding :: Luogu/p2894.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, i32, i32, i32, i32, i32 }

@tr = external dso_local global [2000040 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 nounwind uwtable
define dso_local void @_Z9push_downi(i32 noundef %0) #1 {
  %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
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %7
  %9 = getelementptr inbounds %struct.Node, ptr %8, i32 0, i32 6
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %13, label %12

12:                                               ; preds = %1
  br label %78

13:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %15
  store ptr %16, ptr %3, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = shl i32 %17, 1
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %19
  store ptr %20, ptr %4, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = shl i32 %21, 1
  %23 = or i32 %22, 1
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %24
  store ptr %25, ptr %5, align 8, !tbaa !11
  %26 = load ptr, ptr %3, align 8, !tbaa !11
  %27 = getelementptr inbounds %struct.Node, ptr %26, i32 0, i32 6
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %29 = icmp eq i32 %28, 1
  br i1 %29, label %30, label %47

30:                                               ; preds = %13
  %31 = load ptr, ptr %5, align 8, !tbaa !11
  %32 = getelementptr inbounds %struct.Node, ptr %31, i32 0, i32 6
  store i32 1, ptr %32, align 4, !tbaa !9
  %33 = load ptr, ptr %4, align 8, !tbaa !11
  %34 = getelementptr inbounds %struct.Node, ptr %33, i32 0, i32 6
  store i32 1, ptr %34, align 4, !tbaa !9
  %35 = load ptr, ptr %4, align 8, !tbaa !11
  %36 = getelementptr inbounds %struct.Node, ptr %35, i32 0, i32 5
  store i32 0, ptr %36, align 4, !tbaa !13
  %37 = load ptr, ptr %4, align 8, !tbaa !11
  %38 = getelementptr inbounds %struct.Node, ptr %37, i32 0, i32 4
  store i32 0, ptr %38, align 4, !tbaa !14
  %39 = load ptr, ptr %4, align 8, !tbaa !11
  %40 = getelementptr inbounds %struct.Node, ptr %39, i32 0, i32 3
  store i32 0, ptr %40, align 4, !tbaa !15
  %41 = load ptr, ptr %5, align 8, !tbaa !11
  %42 = getelementptr inbounds %struct.Node, ptr %41, i32 0, i32 5
  store i32 0, ptr %42, align 4, !tbaa !13
  %43 = load ptr, ptr %5, align 8, !tbaa !11
  %44 = getelementptr inbounds %struct.Node, ptr %43, i32 0, i32 4
  store i32 0, ptr %44, align 4, !tbaa !14
  %45 = load ptr, ptr %5, align 8, !tbaa !11
  %46 = getelementptr inbounds %struct.Node, ptr %45, i32 0, i32 3
  store i32 0, ptr %46, align 4, !tbaa !15
  br label %47

47:                                               ; preds = %30, %13
  %48 = load ptr, ptr %3, align 8, !tbaa !11
  %49 = getelementptr inbounds %struct.Node, ptr %48, i32 0, i32 6
  %50 = load i32, ptr %49, align 4, !tbaa !9
  %51 = icmp eq i32 %50, 2
  br i1 %51, label %52, label %75

52:                                               ; preds = %47
  %53 = load ptr, ptr %5, align 8, !tbaa !11
  %54 = getelementptr inbounds %struct.Node, ptr %53, i32 0, i32 6
  store i32 2, ptr %54, align 4, !tbaa !9
  %55 = load ptr, ptr %4, align 8, !tbaa !11
  %56 = getelementptr inbounds %struct.Node, ptr %55, i32 0, i32 6
  store i32 2, ptr %56, align 4, !tbaa !9
  %57 = load ptr, ptr %4, align 8, !tbaa !11
  %58 = getelementptr inbounds %struct.Node, ptr %57, i32 0, i32 2
  %59 = load i32, ptr %58, align 4, !tbaa !16
  %60 = load ptr, ptr %4, align 8, !tbaa !11
  %61 = getelementptr inbounds %struct.Node, ptr %60, i32 0, i32 5
  store i32 %59, ptr %61, align 4, !tbaa !13
  %62 = load ptr, ptr %4, align 8, !tbaa !11
  %63 = getelementptr inbounds %struct.Node, ptr %62, i32 0, i32 4
  store i32 %59, ptr %63, align 4, !tbaa !14
  %64 = load ptr, ptr %4, align 8, !tbaa !11
  %65 = getelementptr inbounds %struct.Node, ptr %64, i32 0, i32 3
  store i32 %59, ptr %65, align 4, !tbaa !15
  %66 = load ptr, ptr %5, align 8, !tbaa !11
  %67 = getelementptr inbounds %struct.Node, ptr %66, i32 0, i32 2
  %68 = load i32, ptr %67, align 4, !tbaa !16
  %69 = load ptr, ptr %5, align 8, !tbaa !11
  %70 = getelementptr inbounds %struct.Node, ptr %69, i32 0, i32 5
  store i32 %68, ptr %70, align 4, !tbaa !13
  %71 = load ptr, ptr %5, align 8, !tbaa !11
  %72 = getelementptr inbounds %struct.Node, ptr %71, i32 0, i32 4
  store i32 %68, ptr %72, align 4, !tbaa !14
  %73 = load ptr, ptr %5, align 8, !tbaa !11
  %74 = getelementptr inbounds %struct.Node, ptr %73, i32 0, i32 3
  store i32 %68, ptr %74, align 4, !tbaa !15
  br label %75

75:                                               ; preds = %52, %47
  %76 = load ptr, ptr %3, align 8, !tbaa !11
  %77 = getelementptr inbounds %struct.Node, ptr %76, i32 0, i32 6
  store i32 0, ptr %77, align 4, !tbaa !9
  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
  br label %78

78:                                               ; preds = %75, %12
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !6, i64 24}
!10 = !{!"_ZTS4Node", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!10, !6, i64 20}
!14 = !{!10, !6, i64 16}
!15 = !{!10, !6, i64 12}
!16 = !{!10, !6, 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"

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

@tr = external dso_local local_unnamed_addr global [2000040 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 [2000040 x %struct.Node], ptr @tr, i64 0, i64 %2, i32 6
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %33, label %5

5:                                                ; preds = %1
  %6 = shl i32 %0, 1
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %7
  %9 = or disjoint i32 %6, 1
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %10
  %12 = icmp eq i32 %4, 1
  br i1 %12, label %13, label %16

13:                                               ; preds = %5
  %14 = getelementptr inbounds i8, ptr %8, i64 12
  store <4 x i32> <i32 0, i32 0, i32 0, i32 1>, ptr %14, align 4, !tbaa !10
  %15 = getelementptr inbounds i8, ptr %11, i64 12
  store <4 x i32> <i32 0, i32 0, i32 0, i32 1>, ptr %15, align 8, !tbaa !10
  %.pre = load i32, ptr %3, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %13, %5
  %17 = phi i32 [ %.pre, %13 ], [ %4, %5 ]
  %18 = icmp eq i32 %17, 2
  br i1 %18, label %19, label %32

19:                                               ; preds = %16
  %20 = getelementptr inbounds i8, ptr %11, i64 24
  store i32 2, ptr %20, align 4, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %8, i64 24
  store i32 2, ptr %21, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %8, i64 8
  %23 = load i32, ptr %22, align 8, !tbaa !11
  %24 = getelementptr inbounds i8, ptr %8, i64 20
  store i32 %23, ptr %24, align 4, !tbaa !12
  %25 = getelementptr inbounds i8, ptr %8, i64 16
  store i32 %23, ptr %25, align 8, !tbaa !13
  %26 = getelementptr inbounds i8, ptr %8, i64 12
  store i32 %23, ptr %26, align 4, !tbaa !14
  %27 = getelementptr inbounds i8, ptr %11, i64 8
  %28 = load i32, ptr %27, align 4, !tbaa !11
  %29 = getelementptr inbounds i8, ptr %11, i64 20
  store i32 %28, ptr %29, align 8, !tbaa !12
  %30 = getelementptr inbounds i8, ptr %11, i64 16
  store i32 %28, ptr %30, align 4, !tbaa !13
  %31 = getelementptr inbounds i8, ptr %11, i64 12
  store i32 %28, ptr %31, align 8, !tbaa !14
  br label %32

32:                                               ; preds = %19, %16
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %1, %32
  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, !7, i64 24}
!6 = !{!"_ZTS4Node", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!6, !7, i64 20}
!13 = !{!6, !7, i64 16}
!14 = !{!6, !7, i64 12}


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