; LLVM IR from aap/librw :: src/anim.ll (ZN2rw9Animation16streamReadLegacyEPNS_6StreamE)

; 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.rw::Quat" = type { float, float, float, float }
%"struct.rw::Animation" = type { ptr, i32, i32, float, ptr, ptr }
%"struct.rw::HAnimKeyFrame" = type { ptr, float, %"struct.rw::Quat", %"struct.rw::V3d" }
%"struct.rw::V3d" = type { float, float, float }

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN2rw20AnimInterpolatorInfo4findEi(i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN2rw9Animation6createEPNS_20AnimInterpolatorInfoEiif(ptr noundef, i32 noundef, i32 noundef, float noundef) #2 align 2

declare noundef i32 @_ZN2rw6Stream7readI32Ev(ptr noundef nonnull align 8 dereferenceable(8)) #3

declare noundef float @_ZN2rw6Stream7readF32Ev(ptr noundef nonnull align 8 dereferenceable(8)) #3

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN2rw9Animation16streamReadLegacyEPNS_6StreamE(ptr noundef %0) #4 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca float, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca %"struct.rw::Quat", align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #7
  %12 = call noundef ptr @_ZN2rw20AnimInterpolatorInfo4findEi(i32 noundef 1)
  store ptr %12, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #7
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = call noundef i32 @_ZN2rw6Stream7readI32Ev(ptr noundef nonnull align 8 dereferenceable(8) %13)
  store i32 %14, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = call noundef i32 @_ZN2rw6Stream7readI32Ev(ptr noundef nonnull align 8 dereferenceable(8) %15)
  store i32 %16, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = call noundef float @_ZN2rw6Stream7readF32Ev(ptr noundef nonnull align 8 dereferenceable(8) %17)
  store float %18, ptr %7, align 4, !tbaa !11
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = load float, ptr %7, align 4, !tbaa !11
  %23 = call noundef ptr @_ZN2rw9Animation6createEPNS_20AnimInterpolatorInfoEiif(ptr noundef %19, i32 noundef %20, i32 noundef %21, float noundef %22)
  store ptr %23, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #7
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %"struct.rw::Animation", ptr %24, i32 0, i32 4
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  store ptr %26, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #7
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %83, %1
  %28 = load i32, ptr %9, align 4, !tbaa !9
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %"struct.rw::Animation", ptr %29, i32 0, i32 1
  %31 = load i32, ptr %30, align 8, !tbaa !15
  %32 = icmp slt i32 %28, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #7
  br label %86

34:                                               ; preds = %27
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = load i32, ptr %9, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds %"struct.rw::HAnimKeyFrame", ptr %36, i64 %38
  %40 = getelementptr inbounds %"struct.rw::HAnimKeyFrame", ptr %39, i32 0, i32 2
  %41 = call noundef i32 @_ZN2rw6Stream6read32EPvj(ptr noundef nonnull align 8 dereferenceable(8) %35, ptr noundef %40, i32 noundef 16)
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #7
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds %"struct.rw::HAnimKeyFrame", ptr %42, i64 %44
  %46 = getelementptr inbounds %"struct.rw::HAnimKeyFrame", ptr %45, i32 0, i32 2
  %47 = call { <2 x float>, <2 x float> } @_ZN2rw4conjERKNS_4QuatE(ptr noundef nonnull align 4 dereferenceable(16) %46)
  %48 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %10, i32 0, i32 0
  %49 = extractvalue { <2 x float>, <2 x float> } %47, 0
  store <2 x float> %49, ptr %48, align 4
  %50 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %10, i32 0, i32 1
  %51 = extractvalue { <2 x float>, <2 x float> } %47, 1
  store <2 x float> %51, ptr %50, align 4
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds %"struct.rw::HAnimKeyFrame", ptr %52, i64 %54
  %56 = getelementptr inbounds %"struct.rw::HAnimKeyFrame", ptr %55, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %56, ptr align 4 %10, i64 16, i1 false), !tbaa.struct !16
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #7
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = load i32, ptr %9, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds %"struct.rw::HAnimKeyFrame", ptr %58, i64 %60
  %62 = getelementptr inbounds %"struct.rw::HAnimKeyFrame", ptr %61, i32 0, i32 3
  %63 = call noundef i32 @_ZN2rw6Stream6read32EPvj(ptr noundef nonnull align 8 dereferenceable(8) %57, ptr noundef %62, i32 noundef 12)
  %64 = load ptr, ptr %2, align 8, !tbaa !5
  %65 = call noundef float @_ZN2rw6Stream7readF32Ev(ptr noundef nonnull align 8 dereferenceable(8) %64)
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = load i32, ptr %9, align 4, !tbaa !9
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds %"struct.rw::HAnimKeyFrame", ptr %66, i64 %68
  %70 = getelementptr inbounds %"struct.rw::HAnimKeyFrame", ptr %69, i32 0, i32 1
  store float %65, ptr %70, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #7
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  %72 = call noundef i32 @_ZN2rw6Stream7readI32Ev(ptr noundef nonnull align 8 dereferenceable(8) %71)
  %73 = sdiv i32 %72, 36
  store i32 %73, ptr %11, align 4, !tbaa !9
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = load i32, ptr %11, align 4, !tbaa !9
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds %"struct.rw::HAnimKeyFrame", ptr %74, i64 %76
  %78 = load ptr, ptr %8, align 8, !tbaa !5
  %79 = load i32, ptr %9, align 4, !tbaa !9
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds %"struct.rw::HAnimKeyFrame", ptr %78, i64 %80
  %82 = getelementptr inbounds %"struct.rw::HAnimKeyFrame", ptr %81, i32 0, i32 0
  store ptr %77, ptr %82, align 8, !tbaa !21
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #7
  br label %83

83:                                               ; preds = %34
  %84 = load i32, ptr %9, align 4, !tbaa !9
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %9, align 4, !tbaa !9
  br label %27, !llvm.loop !22

86:                                               ; preds = %33
  %87 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #7
  ret ptr %87
}

declare noundef i32 @_ZN2rw6Stream6read32EPvj(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef, i32 noundef) #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local { <2 x float>, <2 x float> } @_ZN2rw4conjERKNS_4QuatE(ptr noundef nonnull align 4 dereferenceable(16)) #5

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #6

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { "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 = { mustprogress uwtable "min-legal-vector-width"="64" "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 #5 = { inlinehint mustprogress uwtable "min-legal-vector-width"="64" "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 #6 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #7 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !6, i64 24}
!14 = !{!"_ZTSN2rw9AnimationE", !6, i64 0, !10, i64 8, !10, i64 12, !12, i64 16, !6, i64 24, !6, i64 32}
!15 = !{!14, !10, i64 8}
!16 = !{i64 0, i64 4, !11, i64 4, i64 4, !11, i64 8, i64 4, !11, i64 12, i64 4, !11}
!17 = !{!18, !12, i64 8}
!18 = !{!"_ZTSN2rw13HAnimKeyFrameE", !6, i64 0, !12, i64 8, !19, i64 12, !20, i64 28}
!19 = !{!"_ZTSN2rw4QuatE", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12}
!20 = !{!"_ZTSN2rw3V3dE", !12, i64 0, !12, i64 4, !12, i64 8}
!21 = !{!18, !6, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"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"

%"struct.rw::HAnimKeyFrame" = type { ptr, float, %"struct.rw::Quat", %"struct.rw::V3d" }
%"struct.rw::Quat" = type { float, float, float, float }
%"struct.rw::V3d" = type { float, float, float }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN2rw20AnimInterpolatorInfo4findEi(i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN2rw9Animation6createEPNS_20AnimInterpolatorInfoEiif(ptr noundef, i32 noundef, i32 noundef, float noundef) local_unnamed_addr #1 align 2

declare noundef i32 @_ZN2rw6Stream7readI32Ev(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

declare noundef float @_ZN2rw6Stream7readF32Ev(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN2rw9Animation16streamReadLegacyEPNS_6StreamE(ptr noundef %0) local_unnamed_addr #3 align 2 {
  %2 = tail call noundef ptr @_ZN2rw20AnimInterpolatorInfo4findEi(i32 noundef 1)
  %3 = tail call noundef i32 @_ZN2rw6Stream7readI32Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %4 = tail call noundef i32 @_ZN2rw6Stream7readI32Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %5 = tail call noundef float @_ZN2rw6Stream7readF32Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %6 = tail call noundef ptr @_ZN2rw9Animation6createEPNS_20AnimInterpolatorInfoEiif(ptr noundef %2, i32 noundef %3, i32 noundef %4, float noundef %5)
  %7 = getelementptr inbounds i8, ptr %6, i64 24
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %6, i64 8
  %10 = load i32, ptr %9, align 8, !tbaa !12
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %1
  ret ptr %6

.lr.ph:                                           ; preds = %1, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %1 ]
  %12 = getelementptr inbounds %"struct.rw::HAnimKeyFrame", ptr %8, i64 %indvars.iv
  %13 = getelementptr inbounds i8, ptr %12, i64 12
  %14 = tail call noundef i32 @_ZN2rw6Stream6read32EPvj(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull %13, i32 noundef 16)
  %15 = tail call { <2 x float>, <2 x float> } @_ZN2rw4conjERKNS_4QuatE(ptr noundef nonnull align 4 dereferenceable(16) %13)
  %16 = extractvalue { <2 x float>, <2 x float> } %15, 0
  %17 = extractvalue { <2 x float>, <2 x float> } %15, 1
  store <2 x float> %16, ptr %13, align 4
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 20
  store <2 x float> %17, ptr %.sroa.4.0..sroa_idx, align 4
  %18 = getelementptr inbounds i8, ptr %12, i64 28
  %19 = tail call noundef i32 @_ZN2rw6Stream6read32EPvj(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull %18, i32 noundef 12)
  %20 = tail call noundef float @_ZN2rw6Stream7readF32Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %21 = getelementptr inbounds i8, ptr %12, i64 8
  store float %20, ptr %21, align 8, !tbaa !13
  %22 = tail call noundef i32 @_ZN2rw6Stream7readI32Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %23 = sdiv i32 %22, 36
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds %"struct.rw::HAnimKeyFrame", ptr %8, i64 %24
  store ptr %25, ptr %12, align 8, !tbaa !17
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %26 = load i32, ptr %9, align 8, !tbaa !12
  %27 = sext i32 %26 to i64
  %28 = icmp slt i64 %indvars.iv.next, %27
  br i1 %28, label %.lr.ph, label %._crit_edge, !llvm.loop !18
}

declare noundef i32 @_ZN2rw6Stream6read32EPvj(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local { <2 x float>, <2 x float> } @_ZN2rw4conjERKNS_4QuatE(ptr noundef nonnull align 4 dereferenceable(16)) local_unnamed_addr #4

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 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 = { "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"="64" "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 = { inlinehint mustprogress uwtable "min-legal-vector-width"="64" "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" }

!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, !7, i64 24}
!6 = !{!"_ZTSN2rw9AnimationE", !7, i64 0, !10, i64 8, !10, i64 12, !11, i64 16, !7, i64 24, !7, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"float", !8, i64 0}
!12 = !{!6, !10, i64 8}
!13 = !{!14, !11, i64 8}
!14 = !{!"_ZTSN2rw13HAnimKeyFrameE", !7, i64 0, !11, i64 8, !15, i64 12, !16, i64 28}
!15 = !{!"_ZTSN2rw4QuatE", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12}
!16 = !{!"_ZTSN2rw3V3dE", !11, i64 0, !11, i64 4, !11, i64 8}
!17 = !{!14, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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