; LLVM IR from lzyrapx/Competitive-Programming :: 百度之星/百度之星2017-资格赛/02（pb_ds）.ll (Z5mergeii)

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

@edge = external dso_local global [444444 x %struct.Edge], align 16
@head = external dso_local global [3333 x i32], 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 @_Z5mergeii(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %7 = load i32, ptr %4, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [3333 x i32], ptr @head, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  store i32 %10, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  br label %11

11:                                               ; preds = %14, %2
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = icmp ne i32 %12, -1
  br i1 %13, label %14, label %42

14:                                               ; preds = %11
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [444444 x %struct.Edge], ptr @edge, i64 0, i64 %16
  %18 = getelementptr inbounds %struct.Edge, ptr %17, i32 0, i32 2
  %19 = load i32, ptr %18, align 4, !tbaa !9
  store i32 %19, ptr %6, align 4, !tbaa !5
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [3333 x i32], ptr @head, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [444444 x %struct.Edge], ptr @edge, i64 0, i64 %25
  %27 = getelementptr inbounds %struct.Edge, ptr %26, i32 0, i32 2
  store i32 %23, ptr %27, align 4, !tbaa !9
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [3333 x i32], ptr @head, i64 0, i64 %30
  store i32 %28, ptr %31, align 4, !tbaa !5
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [444444 x %struct.Edge], ptr @edge, i64 0, i64 %34
  %36 = getelementptr inbounds %struct.Edge, ptr %35, i32 0, i32 3
  %37 = load i32, ptr %36, align 8, !tbaa !12
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [444444 x %struct.Edge], ptr @edge, i64 0, i64 %38
  %40 = getelementptr inbounds %struct.Edge, ptr %39, i32 0, i32 1
  store i32 %32, ptr %40, align 8, !tbaa !13
  %41 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %41, ptr %5, align 4, !tbaa !5
  br label %11, !llvm.loop !14

42:                                               ; preds = %11
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [3333 x i32], ptr @head, i64 0, i64 %44
  store i32 -2, ptr %45, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  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 12}
!10 = !{!"_ZTS4Edge", !11, i64 0, !6, i64 8, !6, i64 12, !6, i64 16}
!11 = !{!"long long", !7, i64 0}
!12 = !{!10, !6, i64 16}
!13 = !{!10, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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

@edge = external dso_local local_unnamed_addr global [444444 x %struct.Edge], align 16
@head = external dso_local local_unnamed_addr global [3333 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z5mergeii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %1 to i64
  %4 = getelementptr inbounds [3333 x i32], ptr @head, i64 0, i64 %3
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %.not11 = icmp eq i32 %5, -1
  br i1 %.not11, label %17, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %6 = sext i32 %0 to i64
  %7 = getelementptr inbounds [3333 x i32], ptr @head, i64 0, i64 %6
  %.promoted = load i32, ptr %7, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %.lr.ph, %8
  %.01213 = phi i32 [ %.promoted, %.lr.ph ], [ %.012, %8 ]
  %.012 = phi i32 [ %5, %.lr.ph ], [ %12, %8 ]
  %9 = sext i32 %.012 to i64
  %10 = getelementptr inbounds [444444 x %struct.Edge], ptr @edge, i64 0, i64 %9
  %11 = getelementptr inbounds i8, ptr %10, i64 12
  %12 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %.01213, ptr %11, align 4, !tbaa !9
  %13 = getelementptr inbounds i8, ptr %10, i64 16
  %14 = load i32, ptr %13, align 8, !tbaa !12
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [444444 x %struct.Edge], ptr @edge, i64 0, i64 %15, i32 1
  store i32 %0, ptr %16, align 8, !tbaa !13
  %.not = icmp eq i32 %12, -1
  br i1 %.not, label %._crit_edge, label %8, !llvm.loop !14

._crit_edge:                                      ; preds = %8
  store i32 %.012, ptr %7, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %._crit_edge, %2
  store i32 -2, ptr %4, align 4, !tbaa !5
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 12}
!10 = !{!"_ZTS4Edge", !11, i64 0, !6, i64 8, !6, i64 12, !6, i64 16}
!11 = !{!"long long", !7, i64 0}
!12 = !{!10, !6, i64 16}
!13 = !{!10, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass