; LLVM IR from Tunghohin/Competitive_Coding :: Uva/uva1400.ll (Z5buildxxx)

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

@arr = external dso_local global [500010 x i64], align 16
@tr = external dso_local global [2000040 x %struct.Node], 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: mustprogress nounwind uwtable
declare dso_local void @_ZNSt4pairIxxEC2IRxS2_TnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt4pairIxxEaSEOS0_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #1 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z7push_upx(i64 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5buildxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2) #2 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca %"struct.std::pair", align 8
  %8 = alloca i64, align 8
  store i64 %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !5
  %9 = load i64, ptr %5, align 8, !tbaa !5
  %10 = load i64, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %10
  %12 = getelementptr inbounds %struct.Node, ptr %11, i32 0, i32 0
  store i64 %9, ptr %12, align 16, !tbaa !9
  %13 = load i64, ptr %6, align 8, !tbaa !5
  %14 = load i64, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %14
  %16 = getelementptr inbounds %struct.Node, ptr %15, i32 0, i32 1
  store i64 %13, ptr %16, align 8, !tbaa !12
  %17 = load i64, ptr %5, align 8, !tbaa !5
  %18 = load i64, ptr %6, align 8, !tbaa !5
  %19 = icmp eq i64 %17, %18
  br i1 %19, label %20, label %50

20:                                               ; preds = %3
  %21 = load i64, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds [500010 x i64], ptr @arr, i64 0, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !5
  %24 = load i64, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %24
  %26 = getelementptr inbounds %struct.Node, ptr %25, i32 0, i32 2
  store i64 %23, ptr %26, align 16, !tbaa !13
  %27 = load i64, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds [500010 x i64], ptr @arr, i64 0, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !5
  %30 = load i64, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.Node, ptr %31, i32 0, i32 3
  store i64 %29, ptr %32, align 8, !tbaa !14
  %33 = load i64, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %33
  %35 = getelementptr inbounds %struct.Node, ptr %34, i32 0, i32 5
  store i64 %29, ptr %35, align 8, !tbaa !15
  %36 = load i64, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.Node, ptr %37, i32 0, i32 4
  store i64 %29, ptr %38, align 16, !tbaa !16
  %39 = load i64, ptr %5, align 8, !tbaa !5
  %40 = load i64, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %40
  %42 = getelementptr inbounds %struct.Node, ptr %41, i32 0, i32 8
  store i64 %39, ptr %42, align 8, !tbaa !17
  %43 = load i64, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %43
  %45 = getelementptr inbounds %struct.Node, ptr %44, i32 0, i32 7
  store i64 %39, ptr %45, align 16, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #3
  call void @_ZNSt4pairIxxEC2IRxS2_TnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 8 dereferenceable(16) %7, ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 8 dereferenceable(8) %6)
  %46 = load i64, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %46
  %48 = getelementptr inbounds %struct.Node, ptr %47, i32 0, i32 6
  %49 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt4pairIxxEaSEOS0_(ptr noundef nonnull align 8 dereferenceable(16) %48, ptr noundef nonnull align 8 dereferenceable(16) %7) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #3
  br label %66

50:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %51 = load i64, ptr %5, align 8, !tbaa !5
  %52 = load i64, ptr %6, align 8, !tbaa !5
  %53 = add nsw i64 %51, %52
  %54 = ashr i64 %53, 1
  store i64 %54, ptr %8, align 8, !tbaa !5
  %55 = load i64, ptr %4, align 8, !tbaa !5
  %56 = shl i64 %55, 1
  %57 = load i64, ptr %5, align 8, !tbaa !5
  %58 = load i64, ptr %8, align 8, !tbaa !5
  call void @_Z5buildxxx(i64 noundef %56, i64 noundef %57, i64 noundef %58)
  %59 = load i64, ptr %4, align 8, !tbaa !5
  %60 = shl i64 %59, 1
  %61 = or i64 %60, 1
  %62 = load i64, ptr %8, align 8, !tbaa !5
  %63 = add nsw i64 %62, 1
  %64 = load i64, ptr %6, align 8, !tbaa !5
  call void @_Z5buildxxx(i64 noundef %61, i64 noundef %63, i64 noundef %64)
  %65 = load i64, ptr %4, align 8, !tbaa !5
  call void @_Z7push_upx(i64 noundef %65)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %66

66:                                               ; preds = %50, %20
  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 = { 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 #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 = !{!"long long", !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 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !11, i64 48, !6, i64 64, !6, i64 72}
!11 = !{!"_ZTSSt4pairIxxE", !6, i64 0, !6, i64 8}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !6, i64 16}
!14 = !{!10, !6, i64 24}
!15 = !{!10, !6, i64 40}
!16 = !{!10, !6, i64 32}
!17 = !{!10, !6, i64 72}
!18 = !{!10, !6, i64 64}


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

@arr = external dso_local local_unnamed_addr global [500010 x i64], align 16
@tr = external dso_local global [2000040 x %struct.Node], align 16

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt4pairIxxEC2IRxS2_TnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt4pairIxxEaSEOS0_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z7push_upx(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5buildxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #2 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca %"struct.std::pair", align 8
  store i64 %1, ptr %4, align 8, !tbaa !5
  store i64 %2, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %0
  store i64 %1, ptr %7, align 16, !tbaa !9
  %8 = getelementptr inbounds i8, ptr %7, i64 8
  store i64 %2, ptr %8, align 8, !tbaa !12
  %9 = icmp eq i64 %1, %2
  br i1 %9, label %common.ret, label %19

common.ret:                                       ; preds = %3
  %10 = getelementptr inbounds [500010 x i64], ptr @arr, i64 0, i64 %1
  %11 = load i64, ptr %10, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %7, i64 16
  %13 = insertelement <4 x i64> poison, i64 %11, i64 0
  %14 = shufflevector <4 x i64> %13, <4 x i64> poison, <4 x i32> zeroinitializer
  store <4 x i64> %14, ptr %12, align 16, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %7, i64 72
  store i64 %1, ptr %15, align 8, !tbaa !13
  %16 = getelementptr inbounds i8, ptr %7, i64 64
  store i64 %1, ptr %16, align 16, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #3
  call void @_ZNSt4pairIxxEC2IRxS2_TnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %17 = getelementptr inbounds i8, ptr %7, i64 48
  %18 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt4pairIxxEaSEOS0_(ptr noundef nonnull align 8 dereferenceable(16) %17, ptr noundef nonnull align 8 dereferenceable(16) %6) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #3
  br label %common.ret15

common.ret15:                                     ; preds = %19, %common.ret
  ret void

19:                                               ; preds = %3
  %20 = add nsw i64 %2, %1
  %21 = ashr i64 %20, 1
  %22 = shl i64 %0, 1
  tail call void @_Z5buildxxx(i64 noundef %22, i64 noundef %1, i64 noundef %21)
  %23 = or disjoint i64 %22, 1
  %24 = add nsw i64 %21, 1
  tail call void @_Z5buildxxx(i64 noundef %23, i64 noundef %24, i64 noundef %2)
  tail call void @_Z7push_upx(i64 noundef %0)
  br label %common.ret15
}

attributes #0 = { mustprogress 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 = { 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 #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 = !{!"long long", !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 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !11, i64 48, !6, i64 64, !6, i64 72}
!11 = !{!"_ZTSSt4pairIxxE", !6, i64 0, !6, i64 8}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !6, i64 72}
!14 = !{!10, !6, i64 64}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass