; LLVM IR from NVIDIA/DALI :: dali/operators/decoder/jpeg (jpeg_handle)

; 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.jpeg_decompress_struct = type { ptr, ptr, ptr, ptr, i32, i32, ptr, i32, i32, i32, i32, i32, i32, i32, double, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, i32, i32, i32, i32, i32, ptr, [4 x ptr], [4 x ptr], [4 x ptr], i32, ptr, i32, i32, i32, [16 x i8], [16 x i8], [16 x i8], i32, i32, i8, i8, i8, i16, i16, i32, i8, i32, ptr, i32, i32, i32, i32, i32, ptr, i32, [4 x ptr], i32, i32, i32, [10 x i32], i32, i32, i32, i32, i32, ptr, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.jpeg_memory_mgr = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64 }
%"struct.dali::jpeg::MemSourceMgr" = type { %struct.jpeg_source_mgr, ptr, i64, i8 }
%struct.jpeg_source_mgr = type { ptr, i64, ptr, ptr, ptr, ptr, ptr }

; 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 void @_ZN4dali4jpeg13MemInitSourceEP22jpeg_decompress_struct(ptr noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN4dali4jpeg18MemFillInputBufferEP22jpeg_decompress_struct(ptr noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4dali4jpeg13MemTermSourceEP22jpeg_decompress_struct(ptr noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4dali4jpeg16MemSkipInputDataEP22jpeg_decompress_structl(ptr noundef, i64 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4dali4jpeg6SetSrcEP22jpeg_decompress_structPKvmb(ptr noundef %0, ptr noundef %1, i64 noundef %2, i1 noundef zeroext %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i8, align 1
  %9 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  %10 = zext i1 %3 to i8
  store i8 %10, ptr %8, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %11, i32 0, i32 1
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = getelementptr inbounds %struct.jpeg_memory_mgr, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !21
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = call noundef ptr %15(ptr noundef %16, i32 noundef 0, i64 noundef 80)
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %18, i32 0, i32 6
  store ptr %17, ptr %19, align 8, !tbaa !23
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %20, i32 0, i32 6
  %22 = load ptr, ptr %21, align 8, !tbaa !23
  store ptr %22, ptr %9, align 8, !tbaa !5
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = getelementptr inbounds %"struct.dali::jpeg::MemSourceMgr", ptr %23, i32 0, i32 0
  %25 = getelementptr inbounds %struct.jpeg_source_mgr, ptr %24, i32 0, i32 2
  store ptr @_ZN4dali4jpeg13MemInitSourceEP22jpeg_decompress_struct, ptr %25, align 8, !tbaa !24
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = getelementptr inbounds %"struct.dali::jpeg::MemSourceMgr", ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds %struct.jpeg_source_mgr, ptr %27, i32 0, i32 3
  store ptr @_ZN4dali4jpeg18MemFillInputBufferEP22jpeg_decompress_struct, ptr %28, align 8, !tbaa !27
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = getelementptr inbounds %"struct.dali::jpeg::MemSourceMgr", ptr %29, i32 0, i32 0
  %31 = getelementptr inbounds %struct.jpeg_source_mgr, ptr %30, i32 0, i32 4
  store ptr @_ZN4dali4jpeg16MemSkipInputDataEP22jpeg_decompress_structl, ptr %31, align 8, !tbaa !28
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = getelementptr inbounds %"struct.dali::jpeg::MemSourceMgr", ptr %32, i32 0, i32 0
  %34 = getelementptr inbounds %struct.jpeg_source_mgr, ptr %33, i32 0, i32 5
  store ptr @jpeg_resync_to_restart, ptr %34, align 8, !tbaa !29
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = getelementptr inbounds %"struct.dali::jpeg::MemSourceMgr", ptr %35, i32 0, i32 0
  %37 = getelementptr inbounds %struct.jpeg_source_mgr, ptr %36, i32 0, i32 6
  store ptr @_ZN4dali4jpeg13MemTermSourceEP22jpeg_decompress_struct, ptr %37, align 8, !tbaa !30
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = getelementptr inbounds %"struct.dali::jpeg::MemSourceMgr", ptr %39, i32 0, i32 1
  store ptr %38, ptr %40, align 8, !tbaa !31
  %41 = load i64, ptr %7, align 8, !tbaa !9
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = getelementptr inbounds %"struct.dali::jpeg::MemSourceMgr", ptr %42, i32 0, i32 2
  store i64 %41, ptr %43, align 8, !tbaa !32
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = getelementptr inbounds %"struct.dali::jpeg::MemSourceMgr", ptr %44, i32 0, i32 0
  %46 = getelementptr inbounds %struct.jpeg_source_mgr, ptr %45, i32 0, i32 1
  store i64 0, ptr %46, align 8, !tbaa !33
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = getelementptr inbounds %"struct.dali::jpeg::MemSourceMgr", ptr %47, i32 0, i32 0
  %49 = getelementptr inbounds %struct.jpeg_source_mgr, ptr %48, i32 0, i32 0
  store ptr null, ptr %49, align 8, !tbaa !34
  %50 = load i8, ptr %8, align 1, !tbaa !11, !range !35, !noundef !36
  %51 = trunc i8 %50 to i1
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = getelementptr inbounds %"struct.dali::jpeg::MemSourceMgr", ptr %52, i32 0, i32 3
  %54 = zext i1 %51 to i8
  store i8 %54, ptr %53, align 8, !tbaa !37
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret void
}

declare i32 @jpeg_resync_to_restart(ptr noundef, i32 noundef) #3

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 = { 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 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"_ZTS22jpeg_decompress_struct", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !15, i64 32, !15, i64 36, !6, i64 40, !15, i64 48, !15, i64 52, !15, i64 56, !16, i64 60, !16, i64 64, !15, i64 68, !15, i64 72, !17, i64 80, !15, i64 88, !15, i64 92, !18, i64 96, !15, i64 100, !15, i64 104, !15, i64 108, !19, i64 112, !15, i64 116, !15, i64 120, !15, i64 124, !15, i64 128, !15, i64 132, !15, i64 136, !15, i64 140, !15, i64 144, !15, i64 148, !15, i64 152, !15, i64 156, !6, i64 160, !15, i64 168, !15, i64 172, !15, i64 176, !15, i64 180, !15, i64 184, !6, i64 192, !7, i64 200, !7, i64 232, !7, i64 264, !15, i64 296, !6, i64 304, !15, i64 312, !15, i64 316, !15, i64 320, !7, i64 324, !7, i64 340, !7, i64 356, !15, i64 372, !15, i64 376, !7, i64 380, !7, i64 381, !7, i64 382, !20, i64 384, !20, i64 386, !15, i64 388, !7, i64 392, !15, i64 396, !6, i64 400, !15, i64 408, !15, i64 412, !15, i64 416, !15, i64 420, !15, i64 424, !6, i64 432, !15, i64 440, !7, i64 448, !15, i64 480, !15, i64 484, !15, i64 488, !7, i64 492, !15, i64 532, !15, i64 536, !15, i64 540, !15, i64 544, !15, i64 548, !6, i64 552, !15, i64 560, !15, i64 564, !6, i64 568, !6, i64 576, !6, i64 584, !6, i64 592, !6, i64 600, !6, i64 608, !6, i64 616, !6, i64 624, !6, i64 632, !6, i64 640, !6, i64 648}
!15 = !{!"int", !7, i64 0}
!16 = !{!"_ZTS13J_COLOR_SPACE", !7, i64 0}
!17 = !{!"double", !7, i64 0}
!18 = !{!"_ZTS12J_DCT_METHOD", !7, i64 0}
!19 = !{!"_ZTS13J_DITHER_MODE", !7, i64 0}
!20 = !{!"short", !7, i64 0}
!21 = !{!22, !6, i64 0}
!22 = !{!"_ZTS15jpeg_memory_mgr", !6, 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, !6, i64 72, !6, i64 80, !10, i64 88, !10, i64 96}
!23 = !{!14, !6, i64 40}
!24 = !{!25, !6, i64 16}
!25 = !{!"_ZTSN4dali4jpeg12MemSourceMgrE", !26, i64 0, !6, i64 56, !10, i64 64, !12, i64 72}
!26 = !{!"_ZTS15jpeg_source_mgr", !6, i64 0, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!27 = !{!25, !6, i64 24}
!28 = !{!25, !6, i64 32}
!29 = !{!25, !6, i64 40}
!30 = !{!25, !6, i64 48}
!31 = !{!25, !6, i64 56}
!32 = !{!25, !10, i64 64}
!33 = !{!25, !10, i64 8}
!34 = !{!25, !6, i64 0}
!35 = !{i8 0, i8 2}
!36 = !{}
!37 = !{!25, !12, i64 72}


; 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
declare dso_local void @_ZN4dali4jpeg13MemInitSourceEP22jpeg_decompress_struct(ptr noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN4dali4jpeg18MemFillInputBufferEP22jpeg_decompress_struct(ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4dali4jpeg13MemTermSourceEP22jpeg_decompress_struct(ptr noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4dali4jpeg16MemSkipInputDataEP22jpeg_decompress_structl(ptr noundef, i64 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4dali4jpeg6SetSrcEP22jpeg_decompress_structPKvmb(ptr noundef %0, ptr noundef %1, i64 noundef %2, i1 noundef zeroext %3) local_unnamed_addr #1 {
  %5 = zext i1 %3 to i8
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = load ptr, ptr %7, align 8, !tbaa !16
  %9 = tail call noundef ptr %8(ptr noundef %0, i32 noundef 0, i64 noundef 80)
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  store ptr %9, ptr %10, align 8, !tbaa !19
  %11 = getelementptr inbounds i8, ptr %9, i64 16
  store ptr @_ZN4dali4jpeg13MemInitSourceEP22jpeg_decompress_struct, ptr %11, align 8, !tbaa !20
  %12 = getelementptr inbounds i8, ptr %9, i64 24
  store ptr @_ZN4dali4jpeg18MemFillInputBufferEP22jpeg_decompress_struct, ptr %12, align 8, !tbaa !24
  %13 = getelementptr inbounds i8, ptr %9, i64 32
  store ptr @_ZN4dali4jpeg16MemSkipInputDataEP22jpeg_decompress_structl, ptr %13, align 8, !tbaa !25
  %14 = getelementptr inbounds i8, ptr %9, i64 40
  store ptr @jpeg_resync_to_restart, ptr %14, align 8, !tbaa !26
  %15 = getelementptr inbounds i8, ptr %9, i64 48
  store ptr @_ZN4dali4jpeg13MemTermSourceEP22jpeg_decompress_struct, ptr %15, align 8, !tbaa !27
  %16 = getelementptr inbounds i8, ptr %9, i64 56
  store ptr %1, ptr %16, align 8, !tbaa !28
  %17 = getelementptr inbounds i8, ptr %9, i64 64
  store i64 %2, ptr %17, align 8, !tbaa !29
  %18 = getelementptr inbounds i8, ptr %9, i64 72
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %9, i8 0, i64 16, i1 false)
  store i8 %5, ptr %18, align 8, !tbaa !30
  ret void
}

declare i32 @jpeg_resync_to_restart(ptr noundef, i32 noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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 8}
!6 = !{!"_ZTS22jpeg_decompress_struct", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 36, !7, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !11, i64 60, !11, i64 64, !10, i64 68, !10, i64 72, !12, i64 80, !10, i64 88, !10, i64 92, !13, i64 96, !10, i64 100, !10, i64 104, !10, i64 108, !14, i64 112, !10, i64 116, !10, i64 120, !10, i64 124, !10, i64 128, !10, i64 132, !10, i64 136, !10, i64 140, !10, i64 144, !10, i64 148, !10, i64 152, !10, i64 156, !7, i64 160, !10, i64 168, !10, i64 172, !10, i64 176, !10, i64 180, !10, i64 184, !7, i64 192, !8, i64 200, !8, i64 232, !8, i64 264, !10, i64 296, !7, i64 304, !10, i64 312, !10, i64 316, !10, i64 320, !8, i64 324, !8, i64 340, !8, i64 356, !10, i64 372, !10, i64 376, !8, i64 380, !8, i64 381, !8, i64 382, !15, i64 384, !15, i64 386, !10, i64 388, !8, i64 392, !10, i64 396, !7, i64 400, !10, i64 408, !10, i64 412, !10, i64 416, !10, i64 420, !10, i64 424, !7, i64 432, !10, i64 440, !8, i64 448, !10, i64 480, !10, i64 484, !10, i64 488, !8, i64 492, !10, i64 532, !10, i64 536, !10, i64 540, !10, i64 544, !10, i64 548, !7, i64 552, !10, i64 560, !10, i64 564, !7, i64 568, !7, i64 576, !7, i64 584, !7, i64 592, !7, i64 600, !7, i64 608, !7, i64 616, !7, i64 624, !7, i64 632, !7, i64 640, !7, i64 648}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_ZTS13J_COLOR_SPACE", !8, i64 0}
!12 = !{!"double", !8, i64 0}
!13 = !{!"_ZTS12J_DCT_METHOD", !8, i64 0}
!14 = !{!"_ZTS13J_DITHER_MODE", !8, i64 0}
!15 = !{!"short", !8, i64 0}
!16 = !{!17, !7, i64 0}
!17 = !{!"_ZTS15jpeg_memory_mgr", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !18, i64 88, !18, i64 96}
!18 = !{!"long", !8, i64 0}
!19 = !{!6, !7, i64 40}
!20 = !{!21, !7, i64 16}
!21 = !{!"_ZTSN4dali4jpeg12MemSourceMgrE", !22, i64 0, !7, i64 56, !18, i64 64, !23, i64 72}
!22 = !{!"_ZTS15jpeg_source_mgr", !7, i64 0, !18, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48}
!23 = !{!"bool", !8, i64 0}
!24 = !{!21, !7, i64 24}
!25 = !{!21, !7, i64 32}
!26 = !{!21, !7, i64 40}
!27 = !{!21, !7, i64 48}
!28 = !{!21, !7, i64 56}
!29 = !{!21, !18, i64 64}
!30 = !{!21, !23, i64 72}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SROAPass,TailCallElimPass