; 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.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 uwtable
declare dso_local noundef i32 @_ZN4dali4jpeg18MemFillInputBufferEP22jpeg_decompress_struct(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4dali4jpeg16MemSkipInputDataEP22jpeg_decompress_structl(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %7, i32 0, i32 6
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  store ptr %9, ptr %5, align 8, !tbaa !5
  %10 = load i64, ptr %4, align 8, !tbaa !9
  %11 = icmp slt i64 %10, 0
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  store i32 1, ptr %6, align 4
  br label %40

13:                                               ; preds = %2
  %14 = load i64, ptr %4, align 8, !tbaa !9
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %"struct.dali::jpeg::MemSourceMgr", ptr %15, i32 0, i32 0
  %17 = getelementptr inbounds %struct.jpeg_source_mgr, ptr %16, i32 0, i32 1
  %18 = load i64, ptr %17, align 8, !tbaa !19
  %19 = icmp sgt i64 %14, %18
  br i1 %19, label %20, label %26

20:                                               ; preds = %13
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %"struct.dali::jpeg::MemSourceMgr", ptr %21, i32 0, i32 0
  %23 = getelementptr inbounds %struct.jpeg_source_mgr, ptr %22, i32 0, i32 1
  store i64 0, ptr %23, align 8, !tbaa !19
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = call noundef i32 @_ZN4dali4jpeg18MemFillInputBufferEP22jpeg_decompress_struct(ptr noundef %24)
  br label %39

26:                                               ; preds = %13
  %27 = load i64, ptr %4, align 8, !tbaa !9
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %"struct.dali::jpeg::MemSourceMgr", ptr %28, i32 0, i32 0
  %30 = getelementptr inbounds %struct.jpeg_source_mgr, ptr %29, i32 0, i32 1
  %31 = load i64, ptr %30, align 8, !tbaa !19
  %32 = sub i64 %31, %27
  store i64 %32, ptr %30, align 8, !tbaa !19
  %33 = load i64, ptr %4, align 8, !tbaa !9
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %"struct.dali::jpeg::MemSourceMgr", ptr %34, i32 0, i32 0
  %36 = getelementptr inbounds %struct.jpeg_source_mgr, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !23
  %38 = getelementptr inbounds i8, ptr %37, i64 %33
  store ptr %38, ptr %36, align 8, !tbaa !23
  br label %39

39:                                               ; preds = %26, %20
  store i32 0, ptr %6, align 4
  br label %40

40:                                               ; preds = %39, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  %41 = load i32, ptr %6, align 4
  switch i32 %41, label %43 [
    i32 0, label %42
    i32 1, label %42
  ]

42:                                               ; preds = %40, %40
  ret void

43:                                               ; preds = %40
  unreachable
}

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 = { 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, !6, i64 40}
!12 = !{!"_ZTS22jpeg_decompress_struct", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !13, i64 32, !13, i64 36, !6, i64 40, !13, i64 48, !13, i64 52, !13, i64 56, !14, i64 60, !14, i64 64, !13, i64 68, !13, i64 72, !15, i64 80, !13, i64 88, !13, i64 92, !16, i64 96, !13, i64 100, !13, i64 104, !13, i64 108, !17, i64 112, !13, i64 116, !13, i64 120, !13, i64 124, !13, i64 128, !13, i64 132, !13, i64 136, !13, i64 140, !13, i64 144, !13, i64 148, !13, i64 152, !13, i64 156, !6, i64 160, !13, i64 168, !13, i64 172, !13, i64 176, !13, i64 180, !13, i64 184, !6, i64 192, !7, i64 200, !7, i64 232, !7, i64 264, !13, i64 296, !6, i64 304, !13, i64 312, !13, i64 316, !13, i64 320, !7, i64 324, !7, i64 340, !7, i64 356, !13, i64 372, !13, i64 376, !7, i64 380, !7, i64 381, !7, i64 382, !18, i64 384, !18, i64 386, !13, i64 388, !7, i64 392, !13, i64 396, !6, i64 400, !13, i64 408, !13, i64 412, !13, i64 416, !13, i64 420, !13, i64 424, !6, i64 432, !13, i64 440, !7, i64 448, !13, i64 480, !13, i64 484, !13, i64 488, !7, i64 492, !13, i64 532, !13, i64 536, !13, i64 540, !13, i64 544, !13, i64 548, !6, i64 552, !13, i64 560, !13, 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}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTS13J_COLOR_SPACE", !7, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = !{!"_ZTS12J_DCT_METHOD", !7, i64 0}
!17 = !{!"_ZTS13J_DITHER_MODE", !7, i64 0}
!18 = !{!"short", !7, i64 0}
!19 = !{!20, !10, i64 8}
!20 = !{!"_ZTSN4dali4jpeg12MemSourceMgrE", !21, i64 0, !6, i64 56, !10, i64 64, !22, i64 72}
!21 = !{!"_ZTS15jpeg_source_mgr", !6, i64 0, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!22 = !{!"bool", !7, i64 0}
!23 = !{!20, !6, 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
declare dso_local noundef i32 @_ZN4dali4jpeg18MemFillInputBufferEP22jpeg_decompress_struct(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4dali4jpeg16MemSkipInputDataEP22jpeg_decompress_structl(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 40
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = icmp slt i64 %1, 0
  br i1 %5, label %16, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %4, i64 8
  %8 = load i64, ptr %7, align 8, !tbaa !16
  %9 = icmp slt i64 %8, %1
  br i1 %9, label %10, label %12

10:                                               ; preds = %6
  store i64 0, ptr %7, align 8, !tbaa !16
  %11 = tail call noundef i32 @_ZN4dali4jpeg18MemFillInputBufferEP22jpeg_decompress_struct(ptr noundef nonnull %0)
  br label %16

12:                                               ; preds = %6
  %13 = sub nsw i64 %8, %1
  store i64 %13, ptr %7, align 8, !tbaa !16
  %14 = load ptr, ptr %4, align 8, !tbaa !21
  %15 = getelementptr inbounds i8, ptr %14, i64 %1
  store ptr %15, ptr %4, align 8, !tbaa !21
  br label %16

16:                                               ; preds = %10, %12, %2
  ret void
}

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

!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 40}
!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, !19, i64 8}
!17 = !{!"_ZTSN4dali4jpeg12MemSourceMgrE", !18, i64 0, !7, i64 56, !19, i64 64, !20, i64 72}
!18 = !{!"_ZTS15jpeg_source_mgr", !7, i64 0, !19, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48}
!19 = !{!"long", !8, i64 0}
!20 = !{!"bool", !8, i64 0}
!21 = !{!17, !7, i64 0}


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