; LLVM IR from wmcnamara/crynn :: lib/thirdparty/assimp/contrib/Open3DGC/o3dgcDynamicVectorDecoder.ll (ZN5o3dgc5MergeEPll)

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

@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [118 x i8], align 1
@__PRETTY_FUNCTION__._ZN5o3dgc5MergeEPll = external hidden unnamed_addr constant [53 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

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

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

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

11:                                               ; preds = %2
  br label %14

12:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 69, ptr noundef @__PRETTY_FUNCTION__._ZN5o3dgc5MergeEPll) #4
  unreachable

13:                                               ; No predecessors!
  br label %14

14:                                               ; preds = %13, %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %15 = load i64, ptr %4, align 8, !tbaa !9
  %16 = ashr i64 %15, 1
  %17 = load i64, ptr %4, align 8, !tbaa !9
  %18 = and i64 %17, 1
  %19 = add nsw i64 %16, %18
  store i64 %19, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %20 = load i64, ptr %5, align 8, !tbaa !9
  %21 = sub nsw i64 %20, 1
  store i64 %21, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %22 = load i64, ptr %5, align 8, !tbaa !9
  store i64 %22, ptr %7, align 8, !tbaa !9
  br label %23

23:                                               ; preds = %44, %14
  %24 = load i64, ptr %6, align 8, !tbaa !9
  %25 = icmp sgt i64 %24, 0
  br i1 %25, label %26, label %49

26:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %27 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %27, ptr %8, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %41, %26
  %29 = load i64, ptr %8, align 8, !tbaa !9
  %30 = load i64, ptr %7, align 8, !tbaa !9
  %31 = icmp slt i64 %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %44

33:                                               ; preds = %28
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = load i64, ptr %8, align 8, !tbaa !9
  %36 = getelementptr inbounds i64, ptr %34, i64 %35
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = load i64, ptr %8, align 8, !tbaa !9
  %39 = add nsw i64 %38, 1
  %40 = getelementptr inbounds i64, ptr %37, i64 %39
  call void @_ZN5o3dgc4swapIlEEvRT_S2_(ptr noundef nonnull align 8 dereferenceable(8) %36, ptr noundef nonnull align 8 dereferenceable(8) %40)
  br label %41

41:                                               ; preds = %33
  %42 = load i64, ptr %8, align 8, !tbaa !9
  %43 = add nsw i64 %42, 2
  store i64 %43, ptr %8, align 8, !tbaa !9
  br label %28, !llvm.loop !11

44:                                               ; preds = %32
  %45 = load i64, ptr %6, align 8, !tbaa !9
  %46 = add nsw i64 %45, -1
  store i64 %46, ptr %6, align 8, !tbaa !9
  %47 = load i64, ptr %7, align 8, !tbaa !9
  %48 = add nsw i64 %47, 1
  store i64 %48, ptr %7, align 8, !tbaa !9
  br label %23, !llvm.loop !13

49:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret i32 0
}

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

attributes #0 = { noreturn nounwind "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 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 = { noreturn nounwind }
attributes #5 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [118 x i8], align 1
@__PRETTY_FUNCTION__._ZN5o3dgc5MergeEPll = external hidden unnamed_addr constant [53 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN5o3dgc5MergeEPll(ptr noundef %0, i64 noundef %1) local_unnamed_addr #1 {
  %3 = icmp sgt i64 %1, 1
  br i1 %3, label %5, label %4

4:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 69, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN5o3dgc5MergeEPll) #3
  unreachable

5:                                                ; preds = %2
  %6 = lshr i64 %1, 1
  %7 = sub nsw i64 %1, %6
  %8 = icmp sgt i64 %7, 1
  br i1 %8, label %.preheader, label %._crit_edge22

.preheader:                                       ; preds = %5, %._crit_edge
  %.01621.in = phi i64 [ %.01621, %._crit_edge ], [ %7, %5 ]
  %.01520 = phi i64 [ %9, %._crit_edge ], [ %7, %5 ]
  %.01621 = add nsw i64 %.01621.in, -1
  %.not = icmp sgt i64 %.01621.in, %.01520
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %9 = add nuw nsw i64 %.01520, 1
  %10 = icmp sgt i64 %.01621.in, 2
  br i1 %10, label %.preheader, label %._crit_edge22, !llvm.loop !5

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.018 = phi i64 [ %13, %.lr.ph ], [ %.01621, %.preheader ]
  %11 = getelementptr inbounds i64, ptr %0, i64 %.018
  %12 = getelementptr i8, ptr %11, i64 8
  tail call void @_ZN5o3dgc4swapIlEEvRT_S2_(ptr noundef nonnull align 8 dereferenceable(8) %11, ptr noundef nonnull align 8 dereferenceable(8) %12)
  %13 = add nsw i64 %.018, 2
  %14 = icmp slt i64 %13, %.01520
  br i1 %14, label %.lr.ph, label %._crit_edge, !llvm.loop !7

._crit_edge22:                                    ; preds = %._crit_edge, %5
  ret i32 0
}

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

attributes #0 = { noreturn nounwind "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 = { 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 = { noreturn 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass