; LLVM IR from Tunghohin/Competitive_Coding :: Luogu/p2894.ll (Z7push_upi)

; 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: mustprogress uwtable
define dso_local void @_Z7push_upi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %8
  store ptr %9, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = shl i32 %10, 1
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %12
  store ptr %13, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = shl i32 %14, 1
  %16 = or i32 %15, 1
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %17
  store ptr %18, ptr %5, align 8, !tbaa !9
  %19 = load ptr, ptr %4, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.Node, ptr %19, i32 0, i32 3
  %21 = load i32, ptr %20, align 4, !tbaa !11
  %22 = load ptr, ptr %4, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.Node, ptr %22, i32 0, i32 2
  %24 = load i32, ptr %23, align 4, !tbaa !13
  %25 = icmp eq i32 %21, %24
  br i1 %25, label %26, label %36

26:                                               ; preds = %1
  %27 = load ptr, ptr %4, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.Node, ptr %27, i32 0, i32 3
  %29 = load i32, ptr %28, align 4, !tbaa !11
  %30 = load ptr, ptr %5, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.Node, ptr %30, i32 0, i32 4
  %32 = load i32, ptr %31, align 4, !tbaa !14
  %33 = add nsw i32 %29, %32
  %34 = load ptr, ptr %3, align 8, !tbaa !9
  %35 = getelementptr inbounds %struct.Node, ptr %34, i32 0, i32 4
  store i32 %33, ptr %35, align 4, !tbaa !14
  br label %42

36:                                               ; preds = %1
  %37 = load ptr, ptr %4, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.Node, ptr %37, i32 0, i32 4
  %39 = load i32, ptr %38, align 4, !tbaa !14
  %40 = load ptr, ptr %3, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.Node, ptr %40, i32 0, i32 4
  store i32 %39, ptr %41, align 4, !tbaa !14
  br label %42

42:                                               ; preds = %36, %26
  %43 = load ptr, ptr %5, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.Node, ptr %43, i32 0, i32 3
  %45 = load i32, ptr %44, align 4, !tbaa !11
  %46 = load ptr, ptr %5, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.Node, ptr %46, i32 0, i32 2
  %48 = load i32, ptr %47, align 4, !tbaa !13
  %49 = icmp eq i32 %45, %48
  br i1 %49, label %50, label %60

50:                                               ; preds = %42
  %51 = load ptr, ptr %5, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.Node, ptr %51, i32 0, i32 3
  %53 = load i32, ptr %52, align 4, !tbaa !11
  %54 = load ptr, ptr %4, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.Node, ptr %54, i32 0, i32 5
  %56 = load i32, ptr %55, align 4, !tbaa !15
  %57 = add nsw i32 %53, %56
  %58 = load ptr, ptr %3, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.Node, ptr %58, i32 0, i32 5
  store i32 %57, ptr %59, align 4, !tbaa !15
  br label %66

60:                                               ; preds = %42
  %61 = load ptr, ptr %5, align 8, !tbaa !9
  %62 = getelementptr inbounds %struct.Node, ptr %61, i32 0, i32 5
  %63 = load i32, ptr %62, align 4, !tbaa !15
  %64 = load ptr, ptr %3, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.Node, ptr %64, i32 0, i32 5
  store i32 %63, ptr %65, align 4, !tbaa !15
  br label %66

66:                                               ; preds = %60, %50
  %67 = load ptr, ptr %4, align 8, !tbaa !9
  %68 = getelementptr inbounds %struct.Node, ptr %67, i32 0, i32 3
  %69 = load ptr, ptr %5, align 8, !tbaa !9
  %70 = getelementptr inbounds %struct.Node, ptr %69, i32 0, i32 3
  %71 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %68, ptr noundef nonnull align 4 dereferenceable(4) %70)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %72 = load ptr, ptr %4, align 8, !tbaa !9
  %73 = getelementptr inbounds %struct.Node, ptr %72, i32 0, i32 5
  %74 = load i32, ptr %73, align 4, !tbaa !15
  %75 = load ptr, ptr %5, align 8, !tbaa !9
  %76 = getelementptr inbounds %struct.Node, ptr %75, i32 0, i32 4
  %77 = load i32, ptr %76, align 4, !tbaa !14
  %78 = add nsw i32 %74, %77
  store i32 %78, ptr %6, align 4, !tbaa !5
  %79 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %71, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %80 = load i32, ptr %79, align 4, !tbaa !5
  %81 = load ptr, ptr %3, align 8, !tbaa !9
  %82 = getelementptr inbounds %struct.Node, ptr %81, i32 0, i32 3
  store i32 %80, ptr %82, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = !{!"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, !6, i64 12}
!12 = !{!"_ZTS4Node", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !6, i64 16}
!15 = !{!12, !6, i64 20}


; 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 global [2000040 x %struct.Node], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z7push_upi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = alloca i32, align 4
  %3 = sext i32 %0 to i64
  %4 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %3
  %5 = shl i32 %0, 1
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %6
  %8 = or disjoint i32 %5, 1
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %9
  %11 = getelementptr inbounds i8, ptr %7, i64 12
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %7, i64 8
  %14 = load i32, ptr %13, align 8, !tbaa !10
  %15 = icmp eq i32 %12, %14
  br i1 %15, label %16, label %20

16:                                               ; preds = %1
  %17 = getelementptr inbounds i8, ptr %10, i64 16
  %18 = load i32, ptr %17, align 4, !tbaa !11
  %19 = add nsw i32 %18, %12
  br label %23

20:                                               ; preds = %1
  %21 = getelementptr inbounds i8, ptr %7, i64 16
  %22 = load i32, ptr %21, align 8, !tbaa !11
  br label %23

23:                                               ; preds = %20, %16
  %.sink = phi i32 [ %19, %16 ], [ %22, %20 ]
  %24 = getelementptr inbounds i8, ptr %4, i64 16
  store i32 %.sink, ptr %24, align 4
  %25 = getelementptr inbounds i8, ptr %10, i64 12
  %26 = load i32, ptr %25, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %10, i64 8
  %28 = load i32, ptr %27, align 4, !tbaa !10
  %29 = icmp eq i32 %26, %28
  br i1 %29, label %30, label %34

30:                                               ; preds = %23
  %31 = getelementptr inbounds i8, ptr %7, i64 20
  %32 = load i32, ptr %31, align 4, !tbaa !12
  %33 = add nsw i32 %32, %26
  br label %37

34:                                               ; preds = %23
  %35 = getelementptr inbounds i8, ptr %10, i64 20
  %36 = load i32, ptr %35, align 8, !tbaa !12
  br label %37

37:                                               ; preds = %34, %30
  %.sink22 = phi i32 [ %33, %30 ], [ %36, %34 ]
  %38 = getelementptr inbounds i8, ptr %4, i64 20
  store i32 %.sink22, ptr %38, align 4
  %39 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %11, ptr noundef nonnull align 4 dereferenceable(4) %25)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  %40 = getelementptr inbounds i8, ptr %7, i64 20
  %41 = load i32, ptr %40, align 4, !tbaa !12
  %42 = getelementptr inbounds i8, ptr %10, i64 16
  %43 = load i32, ptr %42, align 4, !tbaa !11
  %44 = add nsw i32 %43, %41
  store i32 %44, ptr %2, align 4, !tbaa !13
  %45 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %39, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %46 = load i32, ptr %45, align 4, !tbaa !13
  %47 = getelementptr inbounds i8, ptr %4, i64 12
  store i32 %46, ptr %47, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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, !7, i64 12}
!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 = !{!6, !7, i64 8}
!11 = !{!6, !7, i64 16}
!12 = !{!6, !7, i64 20}
!13 = !{!7, !7, i64 0}


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