; LLVM IR from VastoLorde95/Competitive-Programming :: Hackerrank/Codeagon 2016/Problem E/E.ll (Z5queryxxxxx)

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

@k = external dso_local global %struct.bigint, align 8
@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: inlinehint mustprogress uwtable
declare dso_local void @_ZN6bigintC2ERKS_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #1 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5queryxxxxx(ptr dead_on_unwind noalias writable sret(%struct.bigint) align 8 %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %5) #3 personality ptr @__gxx_personality_v0 {
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca %struct.bigint, align 8
  %17 = alloca %struct.bigint, align 8
  %18 = alloca %struct.bigint, align 8
  %19 = alloca ptr, align 8
  %20 = alloca i32, align 4
  store ptr %0, ptr %7, align 8
  store i64 %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !5
  store i64 %3, ptr %10, align 8, !tbaa !5
  store i64 %4, ptr %11, align 8, !tbaa !5
  store i64 %5, ptr %12, align 8, !tbaa !5
  %21 = load i64, ptr %8, align 8, !tbaa !5
  %22 = load i64, ptr %12, align 8, !tbaa !5
  %23 = icmp sge i64 %21, %22
  br i1 %23, label %28, label %24

24:                                               ; preds = %6
  %25 = load i64, ptr %11, align 8, !tbaa !5
  %26 = load i64, ptr %9, align 8, !tbaa !5
  %27 = icmp sge i64 %25, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %24, %6
  call void @_ZN6bigintC2Ex(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef 1)
  br label %77

29:                                               ; preds = %24
  %30 = load i64, ptr %8, align 8, !tbaa !5
  %31 = load i64, ptr %11, align 8, !tbaa !5
  %32 = icmp sle i64 %30, %31
  br i1 %32, label %33, label %41

33:                                               ; preds = %29
  %34 = load i64, ptr %12, align 8, !tbaa !5
  %35 = load i64, ptr %9, align 8, !tbaa !5
  %36 = icmp sle i64 %34, %35
  br i1 %36, label %37, label %41

37:                                               ; preds = %33
  %38 = load i64, ptr %10, align 8, !tbaa !5
  %39 = getelementptr inbounds [262144 x %struct.node], ptr @tree, i64 0, i64 %38
  %40 = getelementptr inbounds %struct.node, ptr %39, i32 0, i32 0
  call void @_ZN6bigintC2ERKS_(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %40)
  br label %77

41:                                               ; preds = %33, %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %42 = load i64, ptr %10, align 8, !tbaa !5
  %43 = shl i64 %42, 1
  store i64 %43, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %44 = load i64, ptr %13, align 8, !tbaa !5
  %45 = add nsw i64 %44, 1
  store i64 %45, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %46 = load i64, ptr %11, align 8, !tbaa !5
  %47 = load i64, ptr %12, align 8, !tbaa !5
  %48 = add nsw i64 %46, %47
  %49 = ashr i64 %48, 1
  store i64 %49, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %16) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %17) #4
  %50 = load i64, ptr %8, align 8, !tbaa !5
  %51 = load i64, ptr %9, align 8, !tbaa !5
  %52 = load i64, ptr %13, align 8, !tbaa !5
  %53 = load i64, ptr %11, align 8, !tbaa !5
  %54 = load i64, ptr %15, align 8, !tbaa !5
  call void @_Z5queryxxxxx(ptr dead_on_unwind writable sret(%struct.bigint) align 8 %17, i64 noundef %50, i64 noundef %51, i64 noundef %52, i64 noundef %53, i64 noundef %54)
  call void @llvm.lifetime.start.p0(i64 32, ptr %18) #4
  %55 = load i64, ptr %8, align 8, !tbaa !5
  %56 = load i64, ptr %9, align 8, !tbaa !5
  %57 = load i64, ptr %14, align 8, !tbaa !5
  %58 = load i64, ptr %15, align 8, !tbaa !5
  %59 = load i64, ptr %12, align 8, !tbaa !5
  invoke void @_Z5queryxxxxx(ptr dead_on_unwind writable sret(%struct.bigint) align 8 %18, i64 noundef %55, i64 noundef %56, i64 noundef %57, i64 noundef %58, i64 noundef %59)
          to label %60 unwind label %63

60:                                               ; preds = %41
  invoke void @_ZNK6bigintmlERKS_(ptr dead_on_unwind writable sret(%struct.bigint) align 8 %16, ptr noundef nonnull align 8 dereferenceable(32) %17, ptr noundef nonnull align 8 dereferenceable(32) %18)
          to label %61 unwind label %67

61:                                               ; preds = %60
  invoke void @_ZNK6bigintrmERKS_(ptr dead_on_unwind writable sret(%struct.bigint) align 8 %0, ptr noundef nonnull align 8 dereferenceable(32) %16, ptr noundef nonnull align 8 dereferenceable(32) @k)
          to label %62 unwind label %71

62:                                               ; preds = %61
  call void @_ZN6bigintD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %16) #4
  call void @_ZN6bigintD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %18) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %18) #4
  call void @_ZN6bigintD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %17) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  br label %77

63:                                               ; preds = %41
  %64 = landingpad { ptr, i32 }
          cleanup
  %65 = extractvalue { ptr, i32 } %64, 0
  store ptr %65, ptr %19, align 8
  %66 = extractvalue { ptr, i32 } %64, 1
  store i32 %66, ptr %20, align 4
  br label %76

67:                                               ; preds = %60
  %68 = landingpad { ptr, i32 }
          cleanup
  %69 = extractvalue { ptr, i32 } %68, 0
  store ptr %69, ptr %19, align 8
  %70 = extractvalue { ptr, i32 } %68, 1
  store i32 %70, ptr %20, align 4
  br label %75

71:                                               ; preds = %61
  %72 = landingpad { ptr, i32 }
          cleanup
  %73 = extractvalue { ptr, i32 } %72, 0
  store ptr %73, ptr %19, align 8
  %74 = extractvalue { ptr, i32 } %72, 1
  store i32 %74, ptr %20, align 4
  call void @_ZN6bigintD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %16) #4
  br label %75

75:                                               ; preds = %71, %67
  call void @_ZN6bigintD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %18) #4
  br label %76

76:                                               ; preds = %75, %63
  call void @llvm.lifetime.end.p0(i64 32, ptr %18) #4
  call void @_ZN6bigintD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %17) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  br label %78

77:                                               ; preds = %62, %37, %28
  ret void

78:                                               ; preds = %76
  %79 = load ptr, ptr %19, align 8
  %80 = load i32, ptr %20, align 4
  %81 = insertvalue { ptr, i32 } poison, ptr %79, 0
  %82 = insertvalue { ptr, i32 } %81, i32 %80, 1
  resume { ptr, i32 } %82
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK6bigintmlERKS_(ptr dead_on_unwind noalias writable sret(%struct.bigint) align 8, ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK6bigintrmERKS_(ptr dead_on_unwind noalias writable sret(%struct.bigint) align 8, ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) #3 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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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 }

@k = external dso_local global %struct.bigint, align 8
@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: inlinehint mustprogress uwtable
declare dso_local void @_ZN6bigintC2ERKS_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #1 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5queryxxxxx(ptr dead_on_unwind noalias writable sret(%struct.bigint) align 8 %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %5) local_unnamed_addr #3 personality ptr @__gxx_personality_v0 {
  %7 = alloca %struct.bigint, align 8
  %8 = alloca %struct.bigint, align 8
  %9 = alloca %struct.bigint, align 8
  %.not = icmp slt i64 %1, %5
  %.not30 = icmp slt i64 %4, %2
  %or.cond = and i1 %.not30, %.not
  br i1 %or.cond, label %11, label %10

10:                                               ; preds = %6
  tail call void @_ZN6bigintC2Ex(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef 1)
  br label %30

11:                                               ; preds = %6
  %.not31 = icmp sgt i64 %1, %4
  %.not32 = icmp sgt i64 %5, %2
  %or.cond35 = or i1 %.not31, %.not32
  br i1 %or.cond35, label %14, label %12

12:                                               ; preds = %11
  %13 = getelementptr inbounds [262144 x %struct.node], ptr @tree, i64 0, i64 %3
  tail call void @_ZN6bigintC2ERKS_(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %13)
  br label %30

14:                                               ; preds = %11
  %15 = shl i64 %3, 1
  %16 = or disjoint i64 %15, 1
  %17 = add nsw i64 %5, %4
  %18 = ashr i64 %17, 1
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %7) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %8) #4
  call void @_Z5queryxxxxx(ptr dead_on_unwind nonnull writable sret(%struct.bigint) align 8 %8, i64 noundef %1, i64 noundef %2, i64 noundef %15, i64 noundef %4, i64 noundef %18)
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %9) #4
  invoke void @_Z5queryxxxxx(ptr dead_on_unwind nonnull writable sret(%struct.bigint) align 8 %9, i64 noundef %1, i64 noundef %2, i64 noundef %16, i64 noundef %18, i64 noundef %5)
          to label %19 unwind label %22

19:                                               ; preds = %14
  invoke void @_ZNK6bigintmlERKS_(ptr dead_on_unwind nonnull writable sret(%struct.bigint) align 8 %7, ptr noundef nonnull align 8 dereferenceable(32) %8, ptr noundef nonnull align 8 dereferenceable(32) %9)
          to label %20 unwind label %24

20:                                               ; preds = %19
  invoke void @_ZNK6bigintrmERKS_(ptr dead_on_unwind writable sret(%struct.bigint) align 8 %0, ptr noundef nonnull align 8 dereferenceable(32) %7, ptr noundef nonnull align 8 dereferenceable(32) @k)
          to label %21 unwind label %26

21:                                               ; preds = %20
  call void @_ZN6bigintD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %7) #4
  call void @_ZN6bigintD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %9) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %9) #4
  call void @_ZN6bigintD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %8) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %7) #4
  br label %30

22:                                               ; preds = %14
  %23 = landingpad { ptr, i32 }
          cleanup
  br label %29

24:                                               ; preds = %19
  %25 = landingpad { ptr, i32 }
          cleanup
  br label %28

26:                                               ; preds = %20
  %27 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN6bigintD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %7) #4
  br label %28

28:                                               ; preds = %26, %24
  %.pn = phi { ptr, i32 } [ %27, %26 ], [ %25, %24 ]
  call void @_ZN6bigintD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %9) #4
  br label %29

29:                                               ; preds = %28, %22
  %.pn.pn = phi { ptr, i32 } [ %.pn, %28 ], [ %23, %22 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %9) #4
  call void @_ZN6bigintD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %8) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %7) #4
  resume { ptr, i32 } %.pn.pn

30:                                               ; preds = %21, %12, %10
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK6bigintmlERKS_(ptr dead_on_unwind noalias writable sret(%struct.bigint) align 8, ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK6bigintrmERKS_(ptr dead_on_unwind noalias writable sret(%struct.bigint) align 8, ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #3 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 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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)"}


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