; LLVM IR from zeux/meshoptimizer :: src (vertexcodec)

; 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 [38 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [72 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [21 x i8], align 1
@__PRETTY_FUNCTION__.meshopt_encodeVertexBufferBound = external hidden unnamed_addr constant [55 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [39 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: mustprogress nounwind uwtable
declare hidden noundef i64 @_ZN7meshoptL18getVertexBlockSizeEm(i64 noundef) #2

; 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 i64 @meshopt_encodeVertexBufferBound(i64 noundef %0, i64 noundef %1) #3 {
  %3 = alloca i64, 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
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !5
  %13 = load i64, ptr %4, align 8, !tbaa !5
  %14 = icmp ugt i64 %13, 0
  br i1 %14, label %15, label %18

15:                                               ; preds = %2
  %16 = load i64, ptr %4, align 8, !tbaa !5
  %17 = icmp ule i64 %16, 256
  br label %18

18:                                               ; preds = %15, %2
  %19 = phi i1 [ false, %2 ], [ %17, %15 ]
  br i1 %19, label %20, label %21

20:                                               ; preds = %18
  br label %23

21:                                               ; preds = %18
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.2, i32 noundef 1788, ptr noundef @__PRETTY_FUNCTION__.meshopt_encodeVertexBufferBound) #4
  unreachable

22:                                               ; No predecessors!
  br label %23

23:                                               ; preds = %22, %20
  %24 = load i64, ptr %4, align 8, !tbaa !5
  %25 = urem i64 %24, 4
  %26 = icmp eq i64 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %23
  br label %30

28:                                               ; preds = %23
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.2, i32 noundef 1789, ptr noundef @__PRETTY_FUNCTION__.meshopt_encodeVertexBufferBound) #4
  unreachable

29:                                               ; No predecessors!
  br label %30

30:                                               ; preds = %29, %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %31 = load i64, ptr %4, align 8, !tbaa !5
  %32 = call noundef i64 @_ZN7meshoptL18getVertexBlockSizeEm(i64 noundef %31)
  store i64 %32, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %33 = load i64, ptr %3, align 8, !tbaa !5
  %34 = load i64, ptr %5, align 8, !tbaa !5
  %35 = add i64 %33, %34
  %36 = sub i64 %35, 1
  %37 = load i64, ptr %5, align 8, !tbaa !5
  %38 = udiv i64 %36, %37
  store i64 %38, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %39 = load i64, ptr %4, align 8, !tbaa !5
  %40 = udiv i64 %39, 4
  store i64 %40, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %41 = load i64, ptr %5, align 8, !tbaa !5
  %42 = udiv i64 %41, 16
  %43 = add i64 %42, 3
  %44 = udiv i64 %43, 4
  store i64 %44, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %45 = load i64, ptr %5, align 8, !tbaa !5
  store i64 %45, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %46 = load i64, ptr %4, align 8, !tbaa !5
  %47 = load i64, ptr %4, align 8, !tbaa !5
  %48 = udiv i64 %47, 4
  %49 = add i64 %46, %48
  store i64 %49, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  store i64 32, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %50 = load i64, ptr %10, align 8, !tbaa !5
  %51 = load i64, ptr %11, align 8, !tbaa !5
  %52 = icmp ult i64 %50, %51
  br i1 %52, label %53, label %55

53:                                               ; preds = %30
  %54 = load i64, ptr %11, align 8, !tbaa !5
  br label %57

55:                                               ; preds = %30
  %56 = load i64, ptr %10, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %55, %53
  %58 = phi i64 [ %54, %53 ], [ %56, %55 ]
  store i64 %58, ptr %12, align 8, !tbaa !5
  %59 = load i64, ptr %12, align 8, !tbaa !5
  %60 = icmp uge i64 %59, 24
  br i1 %60, label %61, label %62

61:                                               ; preds = %57
  br label %64

62:                                               ; preds = %57
  call void @__assert_fail(ptr noundef @.str.9, ptr noundef @.str.2, i32 noundef 1801, ptr noundef @__PRETTY_FUNCTION__.meshopt_encodeVertexBufferBound) #4
  unreachable

63:                                               ; No predecessors!
  br label %64

64:                                               ; preds = %63, %61
  %65 = load i64, ptr %6, align 8, !tbaa !5
  %66 = load i64, ptr %4, align 8, !tbaa !5
  %67 = mul i64 %65, %66
  %68 = load i64, ptr %7, align 8, !tbaa !5
  %69 = load i64, ptr %8, align 8, !tbaa !5
  %70 = add i64 %68, %69
  %71 = load i64, ptr %9, align 8, !tbaa !5
  %72 = add i64 %70, %71
  %73 = mul i64 %67, %72
  %74 = add i64 1, %73
  %75 = load i64, ptr %12, align 8, !tbaa !5
  %76 = add i64 %74, %75
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  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 i64 %76
}

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

@.str = external hidden unnamed_addr constant [38 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [72 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [21 x i8], align 1
@__PRETTY_FUNCTION__.meshopt_encodeVertexBufferBound = external hidden unnamed_addr constant [55 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
declare hidden noundef i64 @_ZN7meshoptL18getVertexBlockSizeEm(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local i64 @meshopt_encodeVertexBufferBound(i64 noundef %0, i64 noundef %1) local_unnamed_addr #1 {
  %3 = add i64 %1, -1
  %4 = icmp ult i64 %3, 256
  br i1 %4, label %6, label %5

5:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.2, i32 noundef 1788, ptr noundef nonnull @__PRETTY_FUNCTION__.meshopt_encodeVertexBufferBound) #3
  unreachable

6:                                                ; preds = %2
  %7 = and i64 %1, 3
  %8 = icmp eq i64 %7, 0
  br i1 %8, label %10, label %9

9:                                                ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.2, i32 noundef 1789, ptr noundef nonnull @__PRETTY_FUNCTION__.meshopt_encodeVertexBufferBound) #3
  unreachable

10:                                               ; preds = %6
  %11 = tail call noundef i64 @_ZN7meshoptL18getVertexBlockSizeEm(i64 noundef %1)
  %12 = lshr exact i64 %1, 2
  %13 = add nuw nsw i64 %12, %1
  %14 = tail call i64 @llvm.umax.i64(i64 %13, i64 32)
  %15 = lshr i64 %11, 4
  %16 = add nuw nsw i64 %15, 3
  %17 = lshr i64 %16, 2
  %18 = add i64 %0, -1
  %19 = add i64 %18, %11
  %20 = udiv i64 %19, %11
  %21 = mul i64 %20, %1
  %22 = add i64 %11, %12
  %23 = add i64 %22, %17
  %24 = mul i64 %21, %23
  %25 = add nuw nsw i64 %14, 1
  %26 = add i64 %25, %24
  ret i64 %26
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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)"}


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