; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2016-17/Feb 2017/Plat/17 Feb P3 (Segtree).ll (Z7getnodeii)

; 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.std::pair.0" = type { i32, %"struct.std::pair" }
%"struct.std::pair" = type { i32, i32 }

@nex = external dso_local global i32, align 4
@segbit = external dso_local global [20000000 x %"struct.std::pair.0"], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z7getnodeii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %8, label %31

8:                                                ; preds = %2
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [20000000 x %"struct.std::pair.0"], ptr @segbit, i64 0, i64 %10
  %12 = getelementptr inbounds %"struct.std::pair.0", ptr %11, i32 0, i32 1
  %13 = getelementptr inbounds %"struct.std::pair", ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %24, label %16

16:                                               ; preds = %8
  %17 = load i32, ptr @nex, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr @nex, align 4, !tbaa !5
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [20000000 x %"struct.std::pair.0"], ptr @segbit, i64 0, i64 %20
  %22 = getelementptr inbounds %"struct.std::pair.0", ptr %21, i32 0, i32 1
  %23 = getelementptr inbounds %"struct.std::pair", ptr %22, i32 0, i32 0
  store i32 %17, ptr %23, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %16, %8
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [20000000 x %"struct.std::pair.0"], ptr @segbit, i64 0, i64 %26
  %28 = getelementptr inbounds %"struct.std::pair.0", ptr %27, i32 0, i32 1
  %29 = getelementptr inbounds %"struct.std::pair", ptr %28, i32 0, i32 0
  %30 = load i32, ptr %29, align 4, !tbaa !9
  store i32 %30, ptr %3, align 4
  br label %54

31:                                               ; preds = %2
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [20000000 x %"struct.std::pair.0"], ptr @segbit, i64 0, i64 %33
  %35 = getelementptr inbounds %"struct.std::pair.0", ptr %34, i32 0, i32 1
  %36 = getelementptr inbounds %"struct.std::pair", ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !12
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %47, label %39

39:                                               ; preds = %31
  %40 = load i32, ptr @nex, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr @nex, align 4, !tbaa !5
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [20000000 x %"struct.std::pair.0"], ptr @segbit, i64 0, i64 %43
  %45 = getelementptr inbounds %"struct.std::pair.0", ptr %44, i32 0, i32 1
  %46 = getelementptr inbounds %"struct.std::pair", ptr %45, i32 0, i32 1
  store i32 %40, ptr %46, align 4, !tbaa !12
  br label %47

47:                                               ; preds = %39, %31
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [20000000 x %"struct.std::pair.0"], ptr @segbit, i64 0, i64 %49
  %51 = getelementptr inbounds %"struct.std::pair.0", ptr %50, i32 0, i32 1
  %52 = getelementptr inbounds %"struct.std::pair", ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !12
  store i32 %53, ptr %3, align 4
  br label %54

54:                                               ; preds = %47, %24
  %55 = load i32, ptr %3, align 4
  ret i32 %55
}

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 4}
!10 = !{!"_ZTSSt4pairIiS_IiiEE", !6, i64 0, !11, i64 4}
!11 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!12 = !{!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.std::pair.0" = type { i32, %"struct.std::pair" }
%"struct.std::pair" = type { i32, i32 }

@nex = external dso_local local_unnamed_addr global i32, align 4
@segbit = external dso_local local_unnamed_addr global [20000000 x %"struct.std::pair.0"], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: write, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_Z7getnodeii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq i32 %1, 0
  %4 = sext i32 %0 to i64
  br i1 %3, label %5, label %8

5:                                                ; preds = %2
  %6 = getelementptr inbounds [20000000 x %"struct.std::pair.0"], ptr @segbit, i64 0, i64 %4, i32 1
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %.not8 = icmp eq i32 %7, 0
  br i1 %.not8, label %.sink.split, label %13

8:                                                ; preds = %2
  %9 = getelementptr inbounds [20000000 x %"struct.std::pair.0"], ptr @segbit, i64 0, i64 %4, i32 1, i32 1
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %.sink.split, label %13

.sink.split:                                      ; preds = %8, %5
  %.sink10 = phi ptr [ %6, %5 ], [ %9, %8 ]
  %11 = load i32, ptr @nex, align 4, !tbaa !5
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr @nex, align 4, !tbaa !5
  store i32 %11, ptr %.sink10, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %.sink.split, %8, %5
  %.0 = phi i32 [ %7, %5 ], [ %10, %8 ], [ %11, %.sink.split ]
  ret i32 %.0
}

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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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