; LLVM IR from tangjz/acm-icpc :: 51nod/1967.ll (Z3delii)

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

@p = external dso_local global [100005 x i32], align 16
@e = external dso_local global [800011 x %struct.Node], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3delii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds [800011 x %struct.Node], ptr @e, i64 0, i64 %6
  %8 = getelementptr inbounds %struct.Node, ptr %7, i32 0, i32 0
  %9 = load i32, ptr %8, align 16, !tbaa !9
  %10 = icmp eq i32 %9, -1
  br i1 %10, label %11, label %20

11:                                               ; preds = %2
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [800011 x %struct.Node], ptr @e, i64 0, i64 %13
  %15 = getelementptr inbounds %struct.Node, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 4, !tbaa !11
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [100005 x i32], ptr @p, i64 0, i64 %18
  store i32 %16, ptr %19, align 4, !tbaa !5
  br label %34

20:                                               ; preds = %2
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [800011 x %struct.Node], ptr @e, i64 0, i64 %22
  %24 = getelementptr inbounds %struct.Node, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !11
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [800011 x %struct.Node], ptr @e, i64 0, i64 %27
  %29 = getelementptr inbounds %struct.Node, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %29, align 16, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [800011 x %struct.Node], ptr @e, i64 0, i64 %31
  %33 = getelementptr inbounds %struct.Node, ptr %32, i32 0, i32 1
  store i32 %25, ptr %33, align 4, !tbaa !11
  br label %34

34:                                               ; preds = %20, %11
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [800011 x %struct.Node], ptr @e, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.Node, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 4, !tbaa !11
  %40 = icmp ne i32 %39, -1
  br i1 %40, label %41, label %55

41:                                               ; preds = %34
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [800011 x %struct.Node], ptr @e, i64 0, i64 %43
  %45 = getelementptr inbounds %struct.Node, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 16, !tbaa !9
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [800011 x %struct.Node], ptr @e, i64 0, i64 %48
  %50 = getelementptr inbounds %struct.Node, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %50, align 4, !tbaa !11
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [800011 x %struct.Node], ptr @e, i64 0, i64 %52
  %54 = getelementptr inbounds %struct.Node, ptr %53, i32 0, i32 0
  store i32 %46, ptr %54, align 16, !tbaa !9
  br label %55

55:                                               ; preds = %41, %34
  ret void
}

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

!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, !6, i64 8, !6, i64 12}
!11 = !{!10, !6, i64 4}


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

@p = external dso_local local_unnamed_addr global [100005 x i32], align 16
@e = external dso_local local_unnamed_addr global [800011 x %struct.Node], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: write, inaccessiblemem: none) uwtable
define dso_local void @_Z3delii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %1 to i64
  %4 = getelementptr inbounds [800011 x %struct.Node], ptr @e, i64 0, i64 %3
  %5 = load i32, ptr %4, align 16, !tbaa !5
  %6 = icmp eq i32 %5, -1
  %7 = getelementptr inbounds i8, ptr %4, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !10
  %9 = sext i32 %5 to i64
  %10 = getelementptr inbounds [800011 x %struct.Node], ptr @e, i64 0, i64 %9, i32 1
  %11 = sext i32 %0 to i64
  %12 = getelementptr inbounds [100005 x i32], ptr @p, i64 0, i64 %11
  %.sink = select i1 %6, ptr %12, ptr %10
  store i32 %8, ptr %.sink, align 4, !tbaa !11
  %.not = icmp eq i32 %8, -1
  br i1 %.not, label %16, label %13

13:                                               ; preds = %2
  %14 = sext i32 %8 to i64
  %15 = getelementptr inbounds [800011 x %struct.Node], ptr @e, i64 0, i64 %14
  store i32 %5, ptr %15, align 16, !tbaa !5
  br label %16

16:                                               ; preds = %13, %2
  ret void
}

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


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass