; LLVM IR from clangen/musikcube :: src/plugins/ffmpegdecoder/FfmpegDecoder.ll (ZN13FfmpegDecoder11SetPositionEd)

; 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.AVRational = type { i32, i32 }
%class.FfmpegDecoder = type <{ %"class.musik::core::sdk::IDecoder", ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i8, [3 x i8], i32, i32, i32, i32, double, i8, i8, [6 x i8] }>
%"class.musik::core::sdk::IDecoder" = type { ptr }
%struct.AVFormatContext = type { ptr, ptr, ptr, ptr, ptr, i32, i32, ptr, i32, ptr, i32, ptr, ptr, i64, i64, i64, i32, i32, i32, i64, i64, ptr, i32, i32, ptr, i32, i32, i32, i32, ptr, i64, i32, i32, %struct.AVIOInterruptCB, i32, i32, i32, i32, i64, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i64, i32, i32, i32, i32, i32, ptr, ptr, ptr, ptr, i32, ptr, ptr, ptr, ptr, i32, ptr, ptr, i64, ptr, ptr, ptr }
%struct.AVIOInterruptCB = type { ptr, ptr }
%struct.AVStream = type { ptr, i32, i32, ptr, ptr, %struct.AVRational, i64, i64, i64, i32, i32, %struct.AVRational, ptr, %struct.AVRational, %struct.AVPacket, ptr, i32, i32, %struct.AVRational, i32 }
%struct.AVPacket = type { ptr, i64, i64, ptr, i32, i32, i32, ptr, i32, i64, i64, ptr, ptr, %struct.AVRational }

; 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 uwtable
define dso_local noundef double @_ZN13FfmpegDecoder11SetPositionEd(ptr noundef nonnull align 8 dereferenceable(106) %0, double noundef %1) unnamed_addr #1 align 2 {
  %3 = alloca double, align 8
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.AVRational, align 4
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  %10 = load ptr, ptr %4, align 8
  %11 = getelementptr inbounds %class.FfmpegDecoder, ptr %10, i32 0, i32 2
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %69

14:                                               ; preds = %2
  %15 = getelementptr inbounds %class.FfmpegDecoder, ptr %10, i32 0, i32 4
  %16 = load ptr, ptr %15, align 8, !tbaa !16
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %69

18:                                               ; preds = %14
  %19 = getelementptr inbounds %class.FfmpegDecoder, ptr %10, i32 0, i32 5
  %20 = load ptr, ptr %19, align 8, !tbaa !17
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %69

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %23 = getelementptr inbounds %class.FfmpegDecoder, ptr %10, i32 0, i32 4
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  %25 = getelementptr inbounds %struct.AVFormatContext, ptr %24, i32 0, i32 7
  %26 = load ptr, ptr %25, align 8, !tbaa !18
  %27 = getelementptr inbounds %class.FfmpegDecoder, ptr %10, i32 0, i32 14
  %28 = load i32, ptr %27, align 8, !tbaa !24
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds ptr, ptr %26, i64 %29
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  store ptr %31, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.AVStream, ptr %32, i32 0, i32 5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 8 %33, i64 8, i1 false), !tbaa.struct !25
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.AVStream, ptr %34, i32 0, i32 6
  %36 = load i64, ptr %35, align 8, !tbaa !27
  %37 = icmp ne i64 %36, -9223372036854775808
  br i1 %37, label %38, label %42

38:                                               ; preds = %22
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.AVStream, ptr %39, i32 0, i32 6
  %41 = load i64, ptr %40, align 8, !tbaa !27
  br label %43

42:                                               ; preds = %22
  br label %43

43:                                               ; preds = %42, %38
  %44 = phi i64 [ %41, %38 ], [ 0, %42 ]
  store i64 %44, ptr %8, align 8, !tbaa !32
  %45 = load double, ptr %5, align 8, !tbaa !9
  %46 = fptosi double %45 to i64
  %47 = getelementptr inbounds %struct.AVRational, ptr %7, i32 0, i32 1
  %48 = load i32, ptr %47, align 4, !tbaa !33
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds %struct.AVRational, ptr %7, i32 0, i32 0
  %51 = load i32, ptr %50, align 4, !tbaa !34
  %52 = sext i32 %51 to i64
  %53 = call i64 @av_rescale(i64 noundef %46, i64 noundef %49, i64 noundef %52) #6
  %54 = load i64, ptr %8, align 8, !tbaa !32
  %55 = add nsw i64 %54, %53
  store i64 %55, ptr %8, align 8, !tbaa !32
  %56 = getelementptr inbounds %class.FfmpegDecoder, ptr %10, i32 0, i32 4
  %57 = load ptr, ptr %56, align 8, !tbaa !16
  %58 = getelementptr inbounds %class.FfmpegDecoder, ptr %10, i32 0, i32 14
  %59 = load i32, ptr %58, align 8, !tbaa !24
  %60 = load i64, ptr %8, align 8, !tbaa !32
  %61 = call i32 @av_seek_frame(ptr noundef %57, i32 noundef %59, i64 noundef %60, i32 noundef 4)
  %62 = icmp sge i32 %61, 0
  br i1 %62, label %63, label %65

63:                                               ; preds = %43
  %64 = load double, ptr %5, align 8, !tbaa !9
  store double %64, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %66

65:                                               ; preds = %43
  store i32 0, ptr %9, align 4
  br label %66

66:                                               ; preds = %65, %63
  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
  %67 = load i32, ptr %9, align 4
  switch i32 %67, label %72 [
    i32 0, label %68
    i32 1, label %70
  ]

68:                                               ; preds = %66
  br label %69

69:                                               ; preds = %68, %18, %14, %2
  store double -1.000000e+00, ptr %3, align 8
  br label %70

70:                                               ; preds = %69, %66
  %71 = load double, ptr %3, align 8
  ret double %71

72:                                               ; preds = %66
  unreachable
}

; 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) #2

; Function Attrs: nounwind willreturn memory(none)
declare i64 @av_rescale(i64 noundef, i64 noundef, i64 noundef) #3

declare i32 @av_seek_frame(ptr noundef, i32 noundef, i64 noundef, i32 noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind willreturn memory(none) "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 = { "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 = { nounwind }
attributes #6 = { nounwind willreturn memory(none) }

!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 = !{!"double", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"_ZTS13FfmpegDecoder", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !14, i64 72, !15, i64 76, !14, i64 80, !14, i64 84, !14, i64 88, !14, i64 92, !10, i64 96, !15, i64 104, !15, i64 105}
!13 = !{!"_ZTSN5musik4core3sdk8IDecoderE"}
!14 = !{!"int", !7, i64 0}
!15 = !{!"bool", !7, i64 0}
!16 = !{!12, !6, i64 32}
!17 = !{!12, !6, i64 40}
!18 = !{!19, !6, i64 48}
!19 = !{!"_ZTS15AVFormatContext", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !14, i64 40, !14, i64 44, !6, i64 48, !14, i64 56, !6, i64 64, !14, i64 72, !6, i64 80, !6, i64 88, !20, i64 96, !20, i64 104, !20, i64 112, !14, i64 120, !14, i64 124, !14, i64 128, !20, i64 136, !20, i64 144, !6, i64 152, !14, i64 160, !14, i64 164, !6, i64 168, !21, i64 176, !21, i64 180, !21, i64 184, !21, i64 188, !6, i64 192, !20, i64 200, !14, i64 208, !14, i64 212, !22, i64 216, !14, i64 232, !14, i64 236, !14, i64 240, !14, i64 244, !20, i64 248, !14, i64 256, !14, i64 260, !14, i64 264, !14, i64 268, !14, i64 272, !14, i64 276, !14, i64 280, !14, i64 284, !14, i64 288, !14, i64 292, !14, i64 296, !23, i64 300, !20, i64 304, !14, i64 312, !14, i64 316, !14, i64 320, !14, i64 324, !14, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !14, i64 368, !6, i64 376, !6, i64 384, !6, i64 392, !6, i64 400, !14, i64 408, !6, i64 416, !6, i64 424, !20, i64 432, !6, i64 440, !6, i64 448, !6, i64 456}
!20 = !{!"long", !7, i64 0}
!21 = !{!"_ZTS9AVCodecID", !7, i64 0}
!22 = !{!"_ZTS15AVIOInterruptCB", !6, i64 0, !6, i64 8}
!23 = !{!"_ZTS26AVDurationEstimationMethod", !7, i64 0}
!24 = !{!12, !14, i64 88}
!25 = !{i64 0, i64 4, !26, i64 4, i64 4, !26}
!26 = !{!14, !14, i64 0}
!27 = !{!28, !20, i64 40}
!28 = !{!"_ZTS8AVStream", !6, i64 0, !14, i64 8, !14, i64 12, !6, i64 16, !6, i64 24, !29, i64 32, !20, i64 40, !20, i64 48, !20, i64 56, !14, i64 64, !30, i64 68, !29, i64 72, !6, i64 80, !29, i64 88, !31, i64 96, !6, i64 200, !14, i64 208, !14, i64 212, !29, i64 216, !14, i64 224}
!29 = !{!"_ZTS10AVRational", !14, i64 0, !14, i64 4}
!30 = !{!"_ZTS9AVDiscard", !7, i64 0}
!31 = !{!"_ZTS8AVPacket", !6, i64 0, !20, i64 8, !20, i64 16, !6, i64 24, !14, i64 32, !14, i64 36, !14, i64 40, !6, i64 48, !14, i64 56, !20, i64 64, !20, i64 72, !6, i64 80, !6, i64 88, !29, i64 96}
!32 = !{!20, !20, i64 0}
!33 = !{!29, !14, i64 4}
!34 = !{!29, !14, 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 uwtable
define dso_local noundef double @_ZN13FfmpegDecoder11SetPositionEd(ptr nocapture noundef nonnull readonly align 8 dereferenceable(106) %0, double noundef %1) unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %28, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  %7 = load ptr, ptr %6, align 8, !tbaa !14
  %.not12 = icmp eq ptr %7, null
  %8 = getelementptr inbounds i8, ptr %0, i64 40
  %9 = load ptr, ptr %8, align 8
  %.not13 = icmp eq ptr %9, null
  %or.cond = select i1 %.not12, i1 true, i1 %.not13
  br i1 %or.cond, label %28, label %10

10:                                               ; preds = %5
  %11 = getelementptr inbounds i8, ptr %7, i64 48
  %12 = load ptr, ptr %11, align 8, !tbaa !15
  %13 = getelementptr inbounds i8, ptr %0, i64 88
  %14 = load i32, ptr %13, align 8, !tbaa !21
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds ptr, ptr %12, i64 %15
  %17 = load ptr, ptr %16, align 8, !tbaa !22
  %18 = getelementptr inbounds i8, ptr %17, i64 32
  %.sroa.0.0.copyload = load i32, ptr %18, align 8, !tbaa !23
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %17, i64 36
  %.sroa.4.0.copyload = load i32, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !23
  %19 = getelementptr inbounds i8, ptr %17, i64 40
  %20 = load i64, ptr %19, align 8, !tbaa !24
  %.not14 = icmp eq i64 %20, -9223372036854775808
  %spec.select = select i1 %.not14, i64 0, i64 %20
  %21 = fptosi double %1 to i64
  %22 = sext i32 %.sroa.4.0.copyload to i64
  %23 = sext i32 %.sroa.0.0.copyload to i64
  %24 = tail call i64 @av_rescale(i64 noundef %21, i64 noundef %22, i64 noundef %23) #3
  %25 = add nsw i64 %spec.select, %24
  %26 = tail call i32 @av_seek_frame(ptr noundef nonnull %7, i32 noundef %14, i64 noundef %25, i32 noundef 4)
  %27 = icmp slt i32 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %10, %5, %2
  br label %29

29:                                               ; preds = %10, %28
  %.1 = phi double [ %1, %10 ], [ -1.000000e+00, %28 ]
  ret double %.1
}

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare i64 @av_rescale(i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

declare i32 @av_seek_frame(ptr noundef, i32 noundef, i64 noundef, i32 noundef) local_unnamed_addr #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 nofree nosync nounwind willreturn memory(none) "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 = { nounwind willreturn memory(none) }

!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, !8, i64 16}
!6 = !{!"_ZTS13FfmpegDecoder", !7, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !8, i64 32, !8, i64 40, !8, i64 48, !8, i64 56, !8, i64 64, !11, i64 72, !12, i64 76, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !13, i64 96, !12, i64 104, !12, i64 105}
!7 = !{!"_ZTSN5musik4core3sdk8IDecoderE"}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"bool", !9, i64 0}
!13 = !{!"double", !9, i64 0}
!14 = !{!6, !8, i64 32}
!15 = !{!16, !8, i64 48}
!16 = !{!"_ZTS15AVFormatContext", !8, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !8, i64 32, !11, i64 40, !11, i64 44, !8, i64 48, !11, i64 56, !8, i64 64, !11, i64 72, !8, i64 80, !8, i64 88, !17, i64 96, !17, i64 104, !17, i64 112, !11, i64 120, !11, i64 124, !11, i64 128, !17, i64 136, !17, i64 144, !8, i64 152, !11, i64 160, !11, i64 164, !8, i64 168, !18, i64 176, !18, i64 180, !18, i64 184, !18, i64 188, !8, i64 192, !17, i64 200, !11, i64 208, !11, i64 212, !19, i64 216, !11, i64 232, !11, i64 236, !11, i64 240, !11, i64 244, !17, i64 248, !11, i64 256, !11, i64 260, !11, i64 264, !11, i64 268, !11, i64 272, !11, i64 276, !11, i64 280, !11, i64 284, !11, i64 288, !11, i64 292, !11, i64 296, !20, i64 300, !17, i64 304, !11, i64 312, !11, i64 316, !11, i64 320, !11, i64 324, !11, i64 328, !8, i64 336, !8, i64 344, !8, i64 352, !8, i64 360, !11, i64 368, !8, i64 376, !8, i64 384, !8, i64 392, !8, i64 400, !11, i64 408, !8, i64 416, !8, i64 424, !17, i64 432, !8, i64 440, !8, i64 448, !8, i64 456}
!17 = !{!"long", !9, i64 0}
!18 = !{!"_ZTS9AVCodecID", !9, i64 0}
!19 = !{!"_ZTS15AVIOInterruptCB", !8, i64 0, !8, i64 8}
!20 = !{!"_ZTS26AVDurationEstimationMethod", !9, i64 0}
!21 = !{!6, !11, i64 88}
!22 = !{!8, !8, i64 0}
!23 = !{!11, !11, i64 0}
!24 = !{!25, !17, i64 40}
!25 = !{!"_ZTS8AVStream", !8, i64 0, !11, i64 8, !11, i64 12, !8, i64 16, !8, i64 24, !26, i64 32, !17, i64 40, !17, i64 48, !17, i64 56, !11, i64 64, !27, i64 68, !26, i64 72, !8, i64 80, !26, i64 88, !28, i64 96, !8, i64 200, !11, i64 208, !11, i64 212, !26, i64 216, !11, i64 224}
!26 = !{!"_ZTS10AVRational", !11, i64 0, !11, i64 4}
!27 = !{!"_ZTS9AVDiscard", !9, i64 0}
!28 = !{!"_ZTS8AVPacket", !8, i64 0, !17, i64 8, !17, i64 16, !8, i64 24, !11, i64 32, !11, i64 36, !11, i64 40, !8, i64 48, !11, i64 56, !17, i64 64, !17, i64 72, !8, i64 80, !8, i64 88, !26, i64 96}


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