; LLVM IR from ritikbanger/Hacktoberfest2022-DSA :: 01. Mathematics/childrenholiday.ll (Z4goodx)

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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<triplet, std::allocator<triplet>>::_Vector_impl" }
%"struct.std::_Vector_base<triplet, std::allocator<triplet>>::_Vector_impl" = type { %"struct.std::_Vector_base<triplet, std::allocator<triplet>>::_Vector_impl_data" }
%"struct.std::_Vector_base<triplet, std::allocator<triplet>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%struct.triplet = type { i64, i64, i64 }

@m = external dso_local global i64, align 8
@n = external dso_local global i64, align 8
@arr = external dso_local global %"class.std::vector", align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z4goodx(i64 noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 0, ptr %4, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %57, %1
  %7 = load i64, ptr %4, align 8, !tbaa !5
  %8 = load i64, ptr @n, align 8, !tbaa !5
  %9 = icmp slt i64 %7, %8
  br i1 %9, label %11, label %10

10:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %60

11:                                               ; preds = %6
  %12 = load i64, ptr %2, align 8, !tbaa !5
  %13 = load i64, ptr %4, align 8, !tbaa !5
  %14 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI7tripletSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @arr, i64 noundef %13) #4
  %15 = getelementptr inbounds %struct.triplet, ptr %14, i32 0, i32 0
  %16 = load i64, ptr %15, align 8, !tbaa !9
  %17 = load i64, ptr %4, align 8, !tbaa !5
  %18 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI7tripletSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @arr, i64 noundef %17) #4
  %19 = getelementptr inbounds %struct.triplet, ptr %18, i32 0, i32 1
  %20 = load i64, ptr %19, align 8, !tbaa !11
  %21 = mul nsw i64 %16, %20
  %22 = load i64, ptr %4, align 8, !tbaa !5
  %23 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI7tripletSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @arr, i64 noundef %22) #4
  %24 = getelementptr inbounds %struct.triplet, ptr %23, i32 0, i32 2
  %25 = load i64, ptr %24, align 8, !tbaa !12
  %26 = add nsw i64 %21, %25
  %27 = sdiv i64 %12, %26
  %28 = load i64, ptr %4, align 8, !tbaa !5
  %29 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI7tripletSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @arr, i64 noundef %28) #4
  %30 = getelementptr inbounds %struct.triplet, ptr %29, i32 0, i32 1
  %31 = load i64, ptr %30, align 8, !tbaa !11
  %32 = mul nsw i64 %27, %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %33 = load i64, ptr %2, align 8, !tbaa !5
  %34 = load i64, ptr %4, align 8, !tbaa !5
  %35 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI7tripletSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @arr, i64 noundef %34) #4
  %36 = getelementptr inbounds %struct.triplet, ptr %35, i32 0, i32 0
  %37 = load i64, ptr %36, align 8, !tbaa !9
  %38 = load i64, ptr %4, align 8, !tbaa !5
  %39 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI7tripletSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @arr, i64 noundef %38) #4
  %40 = getelementptr inbounds %struct.triplet, ptr %39, i32 0, i32 2
  %41 = load i64, ptr %40, align 8, !tbaa !12
  %42 = add nsw i64 %37, %41
  %43 = srem i64 %33, %42
  %44 = load i64, ptr %4, align 8, !tbaa !5
  %45 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI7tripletSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @arr, i64 noundef %44) #4
  %46 = getelementptr inbounds %struct.triplet, ptr %45, i32 0, i32 0
  %47 = load i64, ptr %46, align 8, !tbaa !9
  %48 = sdiv i64 %43, %47
  store i64 %48, ptr %5, align 8, !tbaa !5
  %49 = load i64, ptr %4, align 8, !tbaa !5
  %50 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI7tripletSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @arr, i64 noundef %49) #4
  %51 = getelementptr inbounds %struct.triplet, ptr %50, i32 0, i32 1
  %52 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 8 dereferenceable(8) %51)
  %53 = load i64, ptr %52, align 8, !tbaa !5
  %54 = add nsw i64 %32, %53
  %55 = load i64, ptr %3, align 8, !tbaa !5
  %56 = add nsw i64 %55, %54
  store i64 %56, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %57

57:                                               ; preds = %11
  %58 = load i64, ptr %4, align 8, !tbaa !5
  %59 = add nsw i64 %58, 1
  store i64 %59, ptr %4, align 8, !tbaa !5
  br label %6, !llvm.loop !13

60:                                               ; preds = %10
  %61 = load i64, ptr %3, align 8, !tbaa !5
  %62 = load i64, ptr @m, align 8, !tbaa !5
  %63 = icmp sge i64 %61, %62
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret i1 %63
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI7tripletSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #3

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #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"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS7triplet", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!10, !6, i64 8}
!12 = !{!10, !6, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<triplet, std::allocator<triplet>>::_Vector_impl" }
%"struct.std::_Vector_base<triplet, std::allocator<triplet>>::_Vector_impl" = type { %"struct.std::_Vector_base<triplet, std::allocator<triplet>>::_Vector_impl_data" }
%"struct.std::_Vector_base<triplet, std::allocator<triplet>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@m = external dso_local local_unnamed_addr global i64, align 8
@n = external dso_local local_unnamed_addr global i64, align 8
@arr = external dso_local global %"class.std::vector", align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z4goodx(i64 noundef %0) local_unnamed_addr #0 {
  %2 = alloca i64, align 8
  %3 = load i64, ptr @n, align 8, !tbaa !5
  %4 = icmp sgt i64 %3, 0
  br i1 %4, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %1
  %.014.lcssa = phi i64 [ 0, %1 ], [ %37, %.lr.ph ]
  %5 = load i64, ptr @m, align 8, !tbaa !5
  %6 = icmp sge i64 %.014.lcssa, %5
  ret i1 %6

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.016 = phi i64 [ %38, %.lr.ph ], [ 0, %1 ]
  %.01415 = phi i64 [ %37, %.lr.ph ], [ 0, %1 ]
  %7 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI7tripletSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @arr, i64 noundef %.016) #3
  %8 = load i64, ptr %7, align 8, !tbaa !9
  %9 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI7tripletSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @arr, i64 noundef %.016) #3
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  %11 = load i64, ptr %10, align 8, !tbaa !11
  %12 = mul nsw i64 %11, %8
  %13 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI7tripletSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @arr, i64 noundef %.016) #3
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  %15 = load i64, ptr %14, align 8, !tbaa !12
  %16 = add nsw i64 %15, %12
  %17 = sdiv i64 %0, %16
  %18 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI7tripletSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @arr, i64 noundef %.016) #3
  %19 = getelementptr inbounds i8, ptr %18, i64 8
  %20 = load i64, ptr %19, align 8, !tbaa !11
  %21 = mul nsw i64 %20, %17
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  %22 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI7tripletSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @arr, i64 noundef %.016) #3
  %23 = load i64, ptr %22, align 8, !tbaa !9
  %24 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI7tripletSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @arr, i64 noundef %.016) #3
  %25 = getelementptr inbounds i8, ptr %24, i64 16
  %26 = load i64, ptr %25, align 8, !tbaa !12
  %27 = add nsw i64 %26, %23
  %28 = srem i64 %0, %27
  %29 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI7tripletSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @arr, i64 noundef %.016) #3
  %30 = load i64, ptr %29, align 8, !tbaa !9
  %31 = sdiv i64 %28, %30
  store i64 %31, ptr %2, align 8, !tbaa !5
  %32 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI7tripletSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @arr, i64 noundef %.016) #3
  %33 = getelementptr inbounds i8, ptr %32, i64 8
  %34 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(8) %33)
  %35 = load i64, ptr %34, align 8, !tbaa !5
  %36 = add i64 %21, %.01415
  %37 = add i64 %36, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  %38 = add nuw nsw i64 %.016, 1
  %39 = load i64, ptr @n, align 8, !tbaa !5
  %40 = icmp slt i64 %38, %39
  br i1 %40, label %.lr.ph, label %._crit_edge, !llvm.loop !13
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI7tripletSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

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

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

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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"_ZTS7triplet", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!10, !6, i64 8}
!12 = !{!10, !6, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass