; LLVM IR from codemistic/Data-Structures-and-Algorithms :: CPP/collatz.ll (Z7collatzxRSt6vectorIxSaIxEEx)

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z7collatzxRSt6vectorIxSaIxEEx(i64 noundef %0, ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  store i64 %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !5
  %10 = load i64, ptr %5, align 8, !tbaa !5
  %11 = load i64, ptr %7, align 8, !tbaa !5
  %12 = icmp sle i64 %10, %11
  br i1 %12, label %13, label %24

13:                                               ; preds = %3
  %14 = load ptr, ptr %6, align 8, !tbaa !9
  %15 = load i64, ptr %5, align 8, !tbaa !5
  %16 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %14, i64 noundef %15) #3
  %17 = load i64, ptr %16, align 8, !tbaa !5
  %18 = icmp ne i64 %17, -1
  br i1 %18, label %19, label %24

19:                                               ; preds = %13
  %20 = load ptr, ptr %6, align 8, !tbaa !9
  %21 = load i64, ptr %5, align 8, !tbaa !5
  %22 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %20, i64 noundef %21) #3
  %23 = load i64, ptr %22, align 8, !tbaa !5
  store i64 %23, ptr %4, align 8
  br label %53

24:                                               ; preds = %13, %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %25 = load i64, ptr %5, align 8, !tbaa !5
  %26 = mul nsw i64 3, %25
  %27 = add nsw i64 %26, 1
  store i64 %27, ptr %8, align 8, !tbaa !5
  %28 = load i64, ptr %5, align 8, !tbaa !5
  %29 = srem i64 %28, 2
  %30 = icmp eq i64 %29, 0
  br i1 %30, label %31, label %34

31:                                               ; preds = %24
  %32 = load i64, ptr %5, align 8, !tbaa !5
  %33 = sdiv i64 %32, 2
  store i64 %33, ptr %8, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %31, %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %35 = load i64, ptr %8, align 8, !tbaa !5
  %36 = load ptr, ptr %6, align 8, !tbaa !9
  %37 = load i64, ptr %7, align 8, !tbaa !5
  %38 = call noundef i64 @_Z7collatzxRSt6vectorIxSaIxEEx(i64 noundef %35, ptr noundef nonnull align 8 dereferenceable(24) %36, i64 noundef %37)
  %39 = add nsw i64 1, %38
  %40 = trunc i64 %39 to i32
  store i32 %40, ptr %9, align 4, !tbaa !11
  %41 = load i64, ptr %5, align 8, !tbaa !5
  %42 = load i64, ptr %7, align 8, !tbaa !5
  %43 = icmp sle i64 %41, %42
  br i1 %43, label %44, label %50

44:                                               ; preds = %34
  %45 = load i32, ptr %9, align 4, !tbaa !11
  %46 = sext i32 %45 to i64
  %47 = load ptr, ptr %6, align 8, !tbaa !9
  %48 = load i64, ptr %5, align 8, !tbaa !5
  %49 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %47, i64 noundef %48) #3
  store i64 %46, ptr %49, align 8, !tbaa !5
  br label %50

50:                                               ; preds = %44, %34
  %51 = load i32, ptr %9, align 4, !tbaa !11
  %52 = sext i32 %51 to i64
  store i64 %52, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %53

53:                                               ; preds = %50, %19
  %54 = load i64, ptr %4, align 8
  ret i64 %54
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #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

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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}


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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z7collatzxRSt6vectorIxSaIxEEx(i64 noundef %0, ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %2) local_unnamed_addr #0 {
  %.not = icmp sgt i64 %0, %2
  br i1 %.not, label %10, label %4

4:                                                ; preds = %3
  %5 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %0) #1
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %.not20 = icmp eq i64 %6, -1
  br i1 %.not20, label %10, label %7

7:                                                ; preds = %4
  %8 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %0) #1
  %9 = load i64, ptr %8, align 8, !tbaa !5
  br label %._crit_edge

10:                                               ; preds = %4, %3
  %11 = mul nsw i64 %0, 3
  %12 = add nsw i64 %11, 1
  %13 = and i64 %0, 1
  %14 = icmp eq i64 %13, 0
  %15 = ashr exact i64 %0, 1
  %spec.select = select i1 %14, i64 %15, i64 %12
  %16 = tail call noundef i64 @_Z7collatzxRSt6vectorIxSaIxEEx(i64 noundef %spec.select, ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %2)
  %17 = shl i64 %16, 32
  %sext = add i64 %17, 4294967296
  %.pre = ashr exact i64 %sext, 32
  br i1 %.not, label %._crit_edge, label %18

18:                                               ; preds = %10
  %19 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %0) #1
  store i64 %.pre, ptr %19, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %10, %18, %7
  %.0 = phi i64 [ %9, %7 ], [ %.pre, %18 ], [ %.pre, %10 ]
  ret i64 %.0
}

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

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 = { 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"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass