; LLVM IR from tangjz/acm-icpc :: TDL_training/2016-04-04/B - Vector Field - tjz.ll (Z3deli)

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

@e = external dso_local global [3010 x %struct.Node], align 16

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

9:                                                ; preds = %1
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [3010 x %struct.Node], ptr @e, i64 0, i64 %11
  %13 = getelementptr inbounds %struct.Node, ptr %12, i32 0, i32 4
  %14 = load i32, ptr %13, align 4, !tbaa !11
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [3010 x %struct.Node], ptr @e, i64 0, i64 %16
  %18 = getelementptr inbounds %struct.Node, ptr %17, i32 0, i32 3
  %19 = load i32, ptr %18, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [3010 x %struct.Node], ptr @e, i64 0, i64 %20
  %22 = getelementptr inbounds %struct.Node, ptr %21, i32 0, i32 4
  store i32 %14, ptr %22, align 4, !tbaa !11
  br label %23

23:                                               ; preds = %9, %1
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [3010 x %struct.Node], ptr @e, i64 0, i64 %25
  %27 = getelementptr inbounds %struct.Node, ptr %26, i32 0, i32 4
  %28 = load i32, ptr %27, align 4, !tbaa !11
  %29 = icmp ne i32 %28, -1
  br i1 %29, label %30, label %44

30:                                               ; preds = %23
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [3010 x %struct.Node], ptr @e, i64 0, i64 %32
  %34 = getelementptr inbounds %struct.Node, ptr %33, i32 0, i32 3
  %35 = load i32, ptr %34, align 4, !tbaa !9
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [3010 x %struct.Node], ptr @e, i64 0, i64 %37
  %39 = getelementptr inbounds %struct.Node, ptr %38, i32 0, i32 4
  %40 = load i32, ptr %39, align 4, !tbaa !11
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [3010 x %struct.Node], ptr @e, i64 0, i64 %41
  %43 = getelementptr inbounds %struct.Node, ptr %42, i32 0, i32 3
  store i32 %35, ptr %43, align 4, !tbaa !9
  br label %44

44:                                               ; preds = %30, %23
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [3010 x %struct.Node], ptr @e, i64 0, i64 %46
  %48 = getelementptr inbounds %struct.Node, ptr %47, i32 0, i32 5
  %49 = load i32, ptr %48, align 4, !tbaa !12
  %50 = icmp ne i32 %49, -1
  br i1 %50, label %51, label %65

51:                                               ; preds = %44
  %52 = load i32, ptr %2, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [3010 x %struct.Node], ptr @e, i64 0, i64 %53
  %55 = getelementptr inbounds %struct.Node, ptr %54, i32 0, i32 6
  %56 = load i32, ptr %55, align 4, !tbaa !13
  %57 = load i32, ptr %2, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [3010 x %struct.Node], ptr @e, i64 0, i64 %58
  %60 = getelementptr inbounds %struct.Node, ptr %59, i32 0, i32 5
  %61 = load i32, ptr %60, align 4, !tbaa !12
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [3010 x %struct.Node], ptr @e, i64 0, i64 %62
  %64 = getelementptr inbounds %struct.Node, ptr %63, i32 0, i32 6
  store i32 %56, ptr %64, align 4, !tbaa !13
  br label %65

65:                                               ; preds = %51, %44
  %66 = load i32, ptr %2, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [3010 x %struct.Node], ptr @e, i64 0, i64 %67
  %69 = getelementptr inbounds %struct.Node, ptr %68, i32 0, i32 6
  %70 = load i32, ptr %69, align 4, !tbaa !13
  %71 = icmp ne i32 %70, -1
  br i1 %71, label %72, label %86

72:                                               ; preds = %65
  %73 = load i32, ptr %2, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [3010 x %struct.Node], ptr @e, i64 0, i64 %74
  %76 = getelementptr inbounds %struct.Node, ptr %75, i32 0, i32 5
  %77 = load i32, ptr %76, align 4, !tbaa !12
  %78 = load i32, ptr %2, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [3010 x %struct.Node], ptr @e, i64 0, i64 %79
  %81 = getelementptr inbounds %struct.Node, ptr %80, i32 0, i32 6
  %82 = load i32, ptr %81, align 4, !tbaa !13
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [3010 x %struct.Node], ptr @e, i64 0, i64 %83
  %85 = getelementptr inbounds %struct.Node, ptr %84, i32 0, i32 5
  store i32 %77, ptr %85, align 4, !tbaa !12
  br label %86

86:                                               ; preds = %72, %65
  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 12}
!10 = !{!"_ZTS4Node", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24}
!11 = !{!10, !6, i64 16}
!12 = !{!10, !6, i64 20}
!13 = !{!10, !6, i64 24}


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

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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3deli(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [3010 x %struct.Node], ptr @e, i64 0, i64 %2
  %4 = getelementptr inbounds i8, ptr %3, i64 12
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %.not = icmp eq i32 %5, -1
  %.phi.trans.insert = getelementptr inbounds i8, ptr %3, i64 16
  %.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !10
  br i1 %.not, label %._crit_edge, label %6

6:                                                ; preds = %1
  %7 = sext i32 %5 to i64
  %8 = getelementptr inbounds [3010 x %struct.Node], ptr @e, i64 0, i64 %7, i32 4
  store i32 %.pre, ptr %8, align 4, !tbaa !10
  br label %._crit_edge

._crit_edge:                                      ; preds = %1, %6
  %.not15 = icmp eq i32 %.pre, -1
  br i1 %.not15, label %12, label %9

9:                                                ; preds = %._crit_edge
  %10 = sext i32 %.pre to i64
  %11 = getelementptr inbounds [3010 x %struct.Node], ptr @e, i64 0, i64 %10, i32 3
  store i32 %5, ptr %11, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %9, %._crit_edge
  %13 = getelementptr inbounds i8, ptr %3, i64 20
  %14 = load i32, ptr %13, align 4, !tbaa !11
  %.not16 = icmp eq i32 %14, -1
  %.phi.trans.insert19 = getelementptr inbounds i8, ptr %3, i64 24
  %.pre20 = load i32, ptr %.phi.trans.insert19, align 4, !tbaa !12
  br i1 %.not16, label %._crit_edge18, label %15

15:                                               ; preds = %12
  %16 = sext i32 %14 to i64
  %17 = getelementptr inbounds [3010 x %struct.Node], ptr @e, i64 0, i64 %16, i32 6
  store i32 %.pre20, ptr %17, align 4, !tbaa !12
  br label %._crit_edge18

._crit_edge18:                                    ; preds = %12, %15
  %.not17 = icmp eq i32 %.pre20, -1
  br i1 %.not17, label %21, label %18

18:                                               ; preds = %._crit_edge18
  %19 = sext i32 %.pre20 to i64
  %20 = getelementptr inbounds [3010 x %struct.Node], ptr @e, i64 0, i64 %19, i32 5
  store i32 %14, ptr %20, align 4, !tbaa !11
  br label %21

21:                                               ; preds = %18, %._crit_edge18
  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 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 16}
!11 = !{!6, !7, i64 20}
!12 = !{!6, !7, i64 24}


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