; 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 }
%struct.jpeg_error_mgr = type { ptr, ptr, ptr, ptr, ptr, i32, %union.anon, i32, i64, ptr, i32, ptr, i32, i32 }
%union.anon = type { [8 x i32], [48 x i8] }

@_ZZN4dali4jpeg18MemFillInputBufferEP22jpeg_decompress_structE10kEOIBuffer = external hidden constant [2 x i8], align 1

; 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 i32 @_ZN4dali4jpeg18MemFillInputBufferEP22jpeg_decompress_struct(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %6, i32 0, i32 6
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %8, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %"struct.dali::jpeg::MemSourceMgr", ptr %9, i32 0, i32 0
  %11 = getelementptr inbounds %struct.jpeg_source_mgr, ptr %10, i32 0, i32 1
  %12 = load i64, ptr %11, align 8, !tbaa !17
  %13 = icmp eq i64 %12, 0
  br i1 %13, label %14, label %34

14:                                               ; preds = %1
  %15 = load ptr, ptr %4, 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 0
  %18 = load ptr, ptr %17, align 8, !tbaa !22
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %"struct.dali::jpeg::MemSourceMgr", ptr %19, i32 0, i32 1
  %21 = load ptr, ptr %20, align 8, !tbaa !23
  %22 = icmp eq ptr %18, %21
  br i1 %22, label %23, label %34

23:                                               ; preds = %14
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !24
  %27 = getelementptr inbounds %struct.jpeg_error_mgr, ptr %26, i32 0, i32 5
  store i32 42, ptr %27, align 8, !tbaa !25
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !24
  %31 = getelementptr inbounds %struct.jpeg_error_mgr, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !27
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  call void %32(ptr noundef %33)
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %86

34:                                               ; preds = %14, %1
  %35 = load ptr, ptr %4, 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 1
  %38 = load i64, ptr %37, align 8, !tbaa !17
  %39 = icmp ne i64 %38, 0
  br i1 %39, label %40, label %47

40:                                               ; preds = %34
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %"struct.dali::jpeg::MemSourceMgr", ptr %41, i32 0, i32 3
  %43 = load i8, ptr %42, align 8, !tbaa !28, !range !29, !noundef !30
  %44 = trunc i8 %43 to i1
  %45 = zext i1 %44 to i64
  %46 = select i1 %44, i32 1, i32 0
  store i32 %46, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %86

47:                                               ; preds = %34
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %"struct.dali::jpeg::MemSourceMgr", ptr %48, i32 0, i32 0
  %50 = getelementptr inbounds %struct.jpeg_source_mgr, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !22
  %52 = icmp ne ptr %51, @_ZZN4dali4jpeg18MemFillInputBufferEP22jpeg_decompress_structE10kEOIBuffer
  br i1 %52, label %53, label %75

53:                                               ; preds = %47
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %"struct.dali::jpeg::MemSourceMgr", ptr %54, i32 0, i32 3
  %56 = load i8, ptr %55, align 8, !tbaa !28, !range !29, !noundef !30
  %57 = trunc i8 %56 to i1
  br i1 %57, label %58, label %75

58:                                               ; preds = %53
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !24
  %62 = getelementptr inbounds %struct.jpeg_error_mgr, ptr %61, i32 0, i32 5
  store i32 120, ptr %62, align 8, !tbaa !25
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %63, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !24
  %66 = getelementptr inbounds %struct.jpeg_error_mgr, ptr %65, i32 0, i32 1
  %67 = load ptr, ptr %66, align 8, !tbaa !31
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  call void %67(ptr noundef %68, i32 noundef -1)
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %"struct.dali::jpeg::MemSourceMgr", ptr %69, i32 0, i32 0
  %71 = getelementptr inbounds %struct.jpeg_source_mgr, ptr %70, i32 0, i32 0
  store ptr @_ZZN4dali4jpeg18MemFillInputBufferEP22jpeg_decompress_structE10kEOIBuffer, ptr %71, align 8, !tbaa !22
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %"struct.dali::jpeg::MemSourceMgr", ptr %72, i32 0, i32 0
  %74 = getelementptr inbounds %struct.jpeg_source_mgr, ptr %73, i32 0, i32 1
  store i64 2, ptr %74, align 8, !tbaa !17
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %86

75:                                               ; preds = %53, %47
  %76 = load ptr, ptr %3, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %76, i32 0, i32 0
  %78 = load ptr, ptr %77, align 8, !tbaa !24
  %79 = getelementptr inbounds %struct.jpeg_error_mgr, ptr %78, i32 0, i32 5
  store i32 36, ptr %79, align 8, !tbaa !25
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %80, i32 0, i32 0
  %82 = load ptr, ptr %81, align 8, !tbaa !24
  %83 = getelementptr inbounds %struct.jpeg_error_mgr, ptr %82, i32 0, i32 0
  %84 = load ptr, ptr %83, align 8, !tbaa !27
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  call void %84(ptr noundef %85)
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %86

86:                                               ; preds = %75, %58, %40, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %87 = load i32, ptr %2, align 4
  ret i32 %87
}

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


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

@_ZZN4dali4jpeg18MemFillInputBufferEP22jpeg_decompress_structE10kEOIBuffer = external hidden constant [2 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZN4dali4jpeg18MemFillInputBufferEP22jpeg_decompress_struct(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 40
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 8
  %5 = load i64, ptr %4, align 8, !tbaa !16
  %6 = icmp eq i64 %5, 0
  br i1 %6, label %7, label %16

7:                                                ; preds = %1
  %8 = load ptr, ptr %3, align 8, !tbaa !21
  %9 = getelementptr inbounds i8, ptr %3, i64 56
  %10 = load ptr, ptr %9, align 8, !tbaa !22
  %11 = icmp eq ptr %8, %10
  br i1 %11, label %12, label %20

12:                                               ; preds = %7
  %13 = load ptr, ptr %0, align 8, !tbaa !23
  %14 = getelementptr inbounds i8, ptr %13, i64 40
  store i32 42, ptr %14, align 8, !tbaa !24
  %15 = load ptr, ptr %13, align 8, !tbaa !26
  tail call void %15(ptr noundef nonnull %0)
  br label %34

16:                                               ; preds = %1
  %17 = getelementptr inbounds i8, ptr %3, i64 72
  %18 = load i8, ptr %17, align 8, !tbaa !27, !range !28, !noundef !29
  %19 = zext nneg i8 %18 to i32
  br label %34

20:                                               ; preds = %7
  %.not19 = icmp eq ptr %8, @_ZZN4dali4jpeg18MemFillInputBufferEP22jpeg_decompress_structE10kEOIBuffer
  br i1 %.not19, label %30, label %21

21:                                               ; preds = %20
  %22 = getelementptr inbounds i8, ptr %3, i64 72
  %23 = load i8, ptr %22, align 8, !tbaa !27, !range !28, !noundef !29
  %24 = trunc nuw i8 %23 to i1
  br i1 %24, label %25, label %30

25:                                               ; preds = %21
  %26 = load ptr, ptr %0, align 8, !tbaa !23
  %27 = getelementptr inbounds i8, ptr %26, i64 40
  store i32 120, ptr %27, align 8, !tbaa !24
  %28 = getelementptr inbounds i8, ptr %26, i64 8
  %29 = load ptr, ptr %28, align 8, !tbaa !30
  tail call void %29(ptr noundef nonnull %0, i32 noundef -1)
  store ptr @_ZZN4dali4jpeg18MemFillInputBufferEP22jpeg_decompress_structE10kEOIBuffer, ptr %3, align 8, !tbaa !21
  store i64 2, ptr %4, align 8, !tbaa !16
  br label %34

30:                                               ; preds = %21, %20
  %31 = load ptr, ptr %0, align 8, !tbaa !23
  %32 = getelementptr inbounds i8, ptr %31, i64 40
  store i32 36, ptr %32, align 8, !tbaa !24
  %33 = load ptr, ptr %31, align 8, !tbaa !26
  tail call void %33(ptr noundef nonnull %0)
  br label %34

34:                                               ; preds = %30, %25, %16, %12
  %.0 = phi i32 [ 0, %12 ], [ %19, %16 ], [ 1, %25 ], [ 0, %30 ]
  ret i32 %.0
}

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}
!22 = !{!17, !7, i64 56}
!23 = !{!6, !7, i64 0}
!24 = !{!25, !10, i64 40}
!25 = !{!"_ZTS14jpeg_error_mgr", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !8, i64 44, !10, i64 124, !19, i64 128, !7, i64 136, !10, i64 144, !7, i64 152, !10, i64 160, !10, i64 164}
!26 = !{!25, !7, i64 0}
!27 = !{!17, !20, i64 72}
!28 = !{i8 0, i8 2}
!29 = !{}
!30 = !{!25, !7, i64 8}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,TailCallElimPass