; LLVM IR from ewconnell/Netlib :: Sources/ImageCodecs (jpeg)

; 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.CDecoderInfo = type { ptr, ptr, i64, i64, i32, i64, i64, i32 }
%struct.JpegContext = type { %struct.jpeg_decompress_struct, %struct.ErrorMgr }
%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.ErrorMgr = type { %struct.jpeg_error_mgr, [1 x %struct.__jmp_buf_tag] }
%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] }
%struct.__jmp_buf_tag = type { [8 x i64], i32, %struct.__sigset_t }
%struct.__sigset_t = type { [16 x i64] }

@.str.1 = external hidden unnamed_addr constant [77 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [59 x i8], align 1
@__PRETTY_FUNCTION__.jpegDecodeData = external hidden unnamed_addr constant [62 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @jpegDecodeData(ptr noundef byval(%struct.CDecoderInfo) align 8 %0, ptr noundef %1, i64 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %1, ptr %4, align 8, !tbaa !5
  store i64 %2, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %8 = getelementptr inbounds %struct.CDecoderInfo, ptr %0, i32 0, i32 0
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  store ptr %9, ptr %6, align 8, !tbaa !5
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.JpegContext, ptr %10, i32 0, i32 0
  %12 = call i32 @jpeg_start_decompress(ptr noundef %11)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.JpegContext, ptr %13, i32 0, i32 0
  %15 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %14, i32 0, i32 27
  %16 = load i32, ptr %15, align 8, !tbaa !14
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.JpegContext, ptr %17, i32 0, i32 0
  %19 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %18, i32 0, i32 30
  %20 = load i32, ptr %19, align 4, !tbaa !21
  %21 = mul i32 %16, %20
  store i32 %21, ptr %7, align 4, !tbaa !22
  %22 = load i32, ptr %7, align 4, !tbaa !22
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.JpegContext, ptr %23, i32 0, i32 0
  %25 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %24, i32 0, i32 28
  %26 = load i32, ptr %25, align 4, !tbaa !23
  %27 = mul i32 %22, %26
  %28 = zext i32 %27 to i64
  %29 = load i64, ptr %5, align 8, !tbaa !9
  %30 = icmp eq i64 %28, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %3
  br label %33

32:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 199, ptr noundef @__PRETTY_FUNCTION__.jpegDecodeData) #5
  unreachable

33:                                               ; preds = %31
  br label %34

34:                                               ; preds = %44, %33
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.JpegContext, ptr %35, i32 0, i32 0
  %37 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %36, i32 0, i32 34
  %38 = load i32, ptr %37, align 8, !tbaa !24
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.JpegContext, ptr %39, i32 0, i32 0
  %41 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %40, i32 0, i32 28
  %42 = load i32, ptr %41, align 4, !tbaa !23
  %43 = icmp ult i32 %38, %42
  br i1 %43, label %44, label %52

44:                                               ; preds = %34
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.JpegContext, ptr %45, i32 0, i32 0
  %47 = call i32 @jpeg_read_scanlines(ptr noundef %46, ptr noundef %4, i32 noundef 1)
  %48 = load i32, ptr %7, align 4, !tbaa !22
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = sext i32 %48 to i64
  %51 = getelementptr inbounds i8, ptr %49, i64 %50
  store ptr %51, ptr %4, align 8, !tbaa !5
  br label %34, !llvm.loop !25

52:                                               ; preds = %34
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.JpegContext, ptr %53, i32 0, i32 0
  %55 = call i32 @jpeg_finish_decompress(ptr noundef %54)
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.JpegContext, ptr %56, i32 0, i32 1
  %58 = getelementptr inbounds %struct.ErrorMgr, ptr %57, i32 0, i32 0
  %59 = getelementptr inbounds %struct.jpeg_error_mgr, ptr %58, i32 0, i32 8
  %60 = load i64, ptr %59, align 8, !tbaa !27
  %61 = icmp sgt i64 %60, 0
  %62 = zext i1 %61 to i64
  %63 = select i1 %61, i32 1, i32 0
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  ret i32 %63
}

declare i32 @jpeg_start_decompress(ptr noundef) #3

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

declare i32 @jpeg_finish_decompress(ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn nounwind "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 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 }
attributes #5 = { noreturn 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 24, !13, i64 32, !10, i64 40, !10, i64 48, !13, i64 56}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 136}
!15 = !{!"", !16, i64 0, !19, i64 656}
!16 = !{!"jpeg_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, !13, i64 60, !13, i64 64, !13, i64 68, !13, i64 72, !17, i64 80, !13, i64 88, !13, i64 92, !13, i64 96, !13, i64 100, !13, i64 104, !13, i64 108, !13, 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}
!17 = !{!"double", !7, i64 0}
!18 = !{!"short", !7, i64 0}
!19 = !{!"ErrorMgr", !20, i64 0, !7, i64 168}
!20 = !{!"jpeg_error_mgr", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !13, i64 40, !7, i64 44, !13, i64 124, !10, i64 128, !6, i64 136, !13, i64 144, !6, i64 152, !13, i64 160, !13, i64 164}
!21 = !{!15, !13, i64 148}
!22 = !{!13, !13, i64 0}
!23 = !{!15, !13, i64 140}
!24 = !{!15, !13, i64 168}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = !{!15, !10, i64 784}


; 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.CDecoderInfo = type { ptr, ptr, i64, i64, i32, i64, i64, i32 }

@.str.1 = external hidden unnamed_addr constant [77 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [59 x i8], align 1
@__PRETTY_FUNCTION__.jpegDecodeData = external hidden unnamed_addr constant [62 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @jpegDecodeData(ptr nocapture noundef readonly byval(%struct.CDecoderInfo) align 8 %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = alloca ptr, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %0, align 8, !tbaa !9
  %6 = tail call i32 @jpeg_start_decompress(ptr noundef %5) #3
  %7 = getelementptr inbounds i8, ptr %5, i64 136
  %8 = load i32, ptr %7, align 8, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %5, i64 148
  %10 = load i32, ptr %9, align 4, !tbaa !20
  %11 = mul i32 %10, %8
  %12 = getelementptr inbounds i8, ptr %5, i64 140
  %13 = load i32, ptr %12, align 4, !tbaa !21
  %14 = mul i32 %11, %13
  %15 = zext i32 %14 to i64
  %16 = icmp eq i64 %15, %2
  br i1 %16, label %.preheader, label %21

.preheader:                                       ; preds = %3
  %17 = getelementptr inbounds i8, ptr %5, i64 168
  %18 = load i32, ptr %17, align 8, !tbaa !22
  %19 = icmp ult i32 %18, %13
  br i1 %19, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %20 = sext i32 %11 to i64
  br label %22

21:                                               ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 199, ptr noundef nonnull @__PRETTY_FUNCTION__.jpegDecodeData) #4
  unreachable

22:                                               ; preds = %.lr.ph, %22
  %23 = call i32 @jpeg_read_scanlines(ptr noundef nonnull %5, ptr noundef nonnull %4, i32 noundef 1) #3
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 %20
  store ptr %25, ptr %4, align 8, !tbaa !5
  %26 = load i32, ptr %17, align 8, !tbaa !22
  %27 = load i32, ptr %12, align 4, !tbaa !21
  %28 = icmp ult i32 %26, %27
  br i1 %28, label %22, label %._crit_edge, !llvm.loop !23

._crit_edge:                                      ; preds = %22, %.preheader
  %29 = call i32 @jpeg_finish_decompress(ptr noundef nonnull %5) #3
  %30 = getelementptr inbounds i8, ptr %5, i64 784
  %31 = load i64, ptr %30, align 8, !tbaa !25
  %32 = icmp sgt i64 %31, 0
  %33 = zext i1 %32 to i32
  ret i32 %33
}

declare i32 @jpeg_start_decompress(ptr noundef) local_unnamed_addr #2

declare i32 @jpeg_read_scanlines(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare i32 @jpeg_finish_decompress(ptr noundef) local_unnamed_addr #2

attributes #0 = { noreturn nounwind "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 = { 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 = { "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 }
attributes #4 = { noreturn 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/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 24, !12, i64 32, !11, i64 40, !11, i64 48, !12, i64 56}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 136}
!14 = !{!"", !15, i64 0, !18, i64 656}
!15 = !{!"jpeg_decompress_struct", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !12, i64 32, !12, i64 36, !6, i64 40, !12, i64 48, !12, i64 52, !12, i64 56, !12, i64 60, !12, i64 64, !12, i64 68, !12, i64 72, !16, i64 80, !12, i64 88, !12, i64 92, !12, i64 96, !12, i64 100, !12, i64 104, !12, i64 108, !12, i64 112, !12, i64 116, !12, i64 120, !12, i64 124, !12, i64 128, !12, i64 132, !12, i64 136, !12, i64 140, !12, i64 144, !12, i64 148, !12, i64 152, !12, i64 156, !6, i64 160, !12, i64 168, !12, i64 172, !12, i64 176, !12, i64 180, !12, i64 184, !6, i64 192, !7, i64 200, !7, i64 232, !7, i64 264, !12, i64 296, !6, i64 304, !12, i64 312, !12, i64 316, !12, i64 320, !7, i64 324, !7, i64 340, !7, i64 356, !12, i64 372, !12, i64 376, !7, i64 380, !7, i64 381, !7, i64 382, !17, i64 384, !17, i64 386, !12, i64 388, !7, i64 392, !12, i64 396, !6, i64 400, !12, i64 408, !12, i64 412, !12, i64 416, !12, i64 420, !12, i64 424, !6, i64 432, !12, i64 440, !7, i64 448, !12, i64 480, !12, i64 484, !12, i64 488, !7, i64 492, !12, i64 532, !12, i64 536, !12, i64 540, !12, i64 544, !12, i64 548, !6, i64 552, !12, i64 560, !12, 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}
!16 = !{!"double", !7, i64 0}
!17 = !{!"short", !7, i64 0}
!18 = !{!"ErrorMgr", !19, i64 0, !7, i64 168}
!19 = !{!"jpeg_error_mgr", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !12, i64 40, !7, i64 44, !12, i64 124, !11, i64 128, !6, i64 136, !12, i64 144, !6, i64 152, !12, i64 160, !12, i64 164}
!20 = !{!14, !12, i64 148}
!21 = !{!14, !12, i64 140}
!22 = !{!14, !12, i64 168}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = !{!14, !11, i64 784}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass