; LLVM IR from VastoLorde95/Competitive-Programming :: Hackerrank/Codeagon 2016/Problem E/E.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.bigint = type { %"class.std::vector", i64 }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%struct.node = type { %struct.bigint }

@a = external dso_local global [131072 x %struct.bigint], align 16
@tree = external dso_local global [262144 x %struct.node], align 16

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN6bigintD2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5buildxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2) #1 personality ptr @__gxx_personality_v0 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca %struct.bigint, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = 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
  %13 = load i64, ptr %5, align 8, !tbaa !5
  %14 = add nsw i64 %13, 1
  %15 = load i64, ptr %6, align 8, !tbaa !5
  %16 = icmp eq i64 %14, %15
  br i1 %16, label %17, label %27

17:                                               ; preds = %3
  %18 = load i64, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds [262144 x %struct.node], ptr @tree, i64 0, i64 %18
  %20 = load i64, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds [131072 x %struct.bigint], ptr @a, i64 0, i64 %20
  call void @_ZN6bigintC2ERKS_(ptr noundef nonnull align 8 dereferenceable(32) %7, ptr noundef nonnull align 8 dereferenceable(32) %21)
  invoke void @_ZN4node6assignE6bigint(ptr noundef nonnull align 8 dereferenceable(32) %19, ptr noundef %7)
          to label %22 unwind label %23

22:                                               ; preds = %17
  call void @_ZN6bigintD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %7) #4
  br label %48

23:                                               ; preds = %17
  %24 = landingpad { ptr, i32 }
          cleanup
  %25 = extractvalue { ptr, i32 } %24, 0
  store ptr %25, ptr %8, align 8
  %26 = extractvalue { ptr, i32 } %24, 1
  store i32 %26, ptr %9, align 4
  call void @_ZN6bigintD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %7) #4
  br label %49

27:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %28 = load i64, ptr %4, align 8, !tbaa !5
  %29 = shl i64 %28, 1
  store i64 %29, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %30 = load i64, ptr %10, align 8, !tbaa !5
  %31 = add nsw i64 %30, 1
  store i64 %31, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %32 = load i64, ptr %5, align 8, !tbaa !5
  %33 = load i64, ptr %6, align 8, !tbaa !5
  %34 = add nsw i64 %32, %33
  %35 = ashr i64 %34, 1
  store i64 %35, ptr %12, align 8, !tbaa !5
  %36 = load i64, ptr %10, align 8, !tbaa !5
  %37 = load i64, ptr %5, align 8, !tbaa !5
  %38 = load i64, ptr %12, align 8, !tbaa !5
  call void @_Z5buildxxx(i64 noundef %36, i64 noundef %37, i64 noundef %38)
  %39 = load i64, ptr %11, align 8, !tbaa !5
  %40 = load i64, ptr %12, align 8, !tbaa !5
  %41 = load i64, ptr %6, align 8, !tbaa !5
  call void @_Z5buildxxx(i64 noundef %39, i64 noundef %40, i64 noundef %41)
  %42 = load i64, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds [262144 x %struct.node], ptr @tree, i64 0, i64 %42
  %44 = load i64, ptr %10, align 8, !tbaa !5
  %45 = getelementptr inbounds [262144 x %struct.node], ptr @tree, i64 0, i64 %44
  %46 = load i64, ptr %11, align 8, !tbaa !5
  %47 = getelementptr inbounds [262144 x %struct.node], ptr @tree, i64 0, i64 %46
  call void @_ZN4node7combineERS_S0_(ptr noundef nonnull align 8 dereferenceable(32) %43, ptr noundef nonnull align 8 dereferenceable(32) %45, ptr noundef nonnull align 8 dereferenceable(32) %47)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %48

48:                                               ; preds = %27, %22
  ret void

49:                                               ; preds = %23
  %50 = load ptr, ptr %8, align 8
  %51 = load i32, ptr %9, align 4
  %52 = insertvalue { ptr, i32 } poison, ptr %50, 0
  %53 = insertvalue { ptr, i32 } %52, i32 %51, 1
  resume { ptr, i32 } %53
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4node6assignE6bigint(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef) #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN6bigintC2ERKS_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #2 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4node7combineERS_S0_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) #1 align 2

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

attributes #0 = { inlinehint 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 #1 = { 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 #2 = { inlinehint 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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"}


; 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.bigint = type { %"class.std::vector", i64 }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%struct.node = type { %struct.bigint }

@a = external dso_local global [131072 x %struct.bigint], align 16
@tree = external dso_local global [262144 x %struct.node], align 16

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN6bigintD2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5buildxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #1 personality ptr @__gxx_personality_v0 {
  %4 = alloca %struct.bigint, align 8
  %5 = add nsw i64 %1, 1
  %6 = icmp eq i64 %5, %2
  br i1 %6, label %7, label %12

7:                                                ; preds = %3
  %8 = getelementptr inbounds [262144 x %struct.node], ptr @tree, i64 0, i64 %0
  %9 = getelementptr inbounds [131072 x %struct.bigint], ptr @a, i64 0, i64 %1
  call void @_ZN6bigintC2ERKS_(ptr noundef nonnull align 8 dereferenceable(32) %4, ptr noundef nonnull align 8 dereferenceable(32) %9)
  invoke void @_ZN4node6assignE6bigint(ptr noundef nonnull align 8 dereferenceable(32) %8, ptr noundef nonnull %4)
          to label %common.ret unwind label %10

common.ret:                                       ; preds = %7
  call void @_ZN6bigintD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %4) #3
  br label %common.ret18

10:                                               ; preds = %7
  %11 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN6bigintD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %4) #3
  resume { ptr, i32 } %11

common.ret18:                                     ; preds = %12, %common.ret
  ret void

12:                                               ; preds = %3
  %13 = shl i64 %0, 1
  %14 = or disjoint i64 %13, 1
  %15 = add nsw i64 %2, %1
  %16 = ashr i64 %15, 1
  tail call void @_Z5buildxxx(i64 noundef %13, i64 noundef %1, i64 noundef %16)
  tail call void @_Z5buildxxx(i64 noundef %14, i64 noundef %16, i64 noundef %2)
  %17 = getelementptr inbounds [262144 x %struct.node], ptr @tree, i64 0, i64 %0
  %18 = getelementptr inbounds [262144 x %struct.node], ptr @tree, i64 0, i64 %13
  %19 = getelementptr inbounds [262144 x %struct.node], ptr @tree, i64 0, i64 %14
  tail call void @_ZN4node7combineERS_S0_(ptr noundef nonnull align 8 dereferenceable(32) %17, ptr noundef nonnull align 8 dereferenceable(32) %18, ptr noundef nonnull align 8 dereferenceable(32) %19)
  br label %common.ret18
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4node6assignE6bigint(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN6bigintC2ERKS_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4node7combineERS_S0_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

attributes #0 = { inlinehint 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 #1 = { 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 #2 = { inlinehint 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)"}


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