; LLVM IR from modlfo/AudioEngine :: AudioEngine/JuceLibraryCode/modules/juce_graphics/image_formats/jpglib (jdphuff)

; 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, i8, i32, ptr, i32, i32, i32, i32, i32, i32, i32, double, i8, i8, i32, i8, i8, i8, i32, i8, i32, i8, i8, i8, i32, i32, i32, i32, i32, i32, ptr, i32, i32, i32, i32, i32, ptr, [4 x ptr], [4 x ptr], [4 x ptr], i32, ptr, i8, i8, [16 x i8], [16 x i8], [16 x i8], i32, i8, i8, i8, i8, i16, i16, i8, i8, i8, ptr, i32, i32, i32, i32, ptr, i32, [4 x ptr], i32, i32, i32, [10 x i32], i32, i32, i32, 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.phuff_entropy_decoder = type { %struct.jpeg_entropy_decoder, %struct.bitread_perm_state, %struct.savable_state3, i32, [4 x ptr], ptr }
%struct.jpeg_entropy_decoder = type { ptr, ptr, i8 }
%struct.bitread_perm_state = type { i64, i32 }
%struct.savable_state3 = type { i32, [4 x i32] }

; Function Attrs: nounwind uwtable
define dso_local void @jinit_phuff_decoder(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %7, i32 0, i32 1
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = getelementptr inbounds %struct.jpeg_memory_mgr, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !14
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = call ptr %11(ptr noundef %12, i32 noundef 1, i64 noundef 104)
  store ptr %13, ptr %3, align 8, !tbaa !5
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %15, i32 0, i32 83
  store ptr %14, ptr %16, align 8, !tbaa !17
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.phuff_entropy_decoder, ptr %17, i32 0, i32 0
  %19 = getelementptr inbounds %struct.jpeg_entropy_decoder, ptr %18, i32 0, i32 0
  store ptr @start_pass_phuff_decoder, ptr %19, align 8, !tbaa !18
  store i32 0, ptr %6, align 4, !tbaa !23
  br label %20

20:                                               ; preds = %29, %1
  %21 = load i32, ptr %6, align 4, !tbaa !23
  %22 = icmp slt i32 %21, 4
  br i1 %22, label %23, label %32

23:                                               ; preds = %20
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.phuff_entropy_decoder, ptr %24, i32 0, i32 4
  %26 = load i32, ptr %6, align 4, !tbaa !23
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [4 x ptr], ptr %25, i64 0, i64 %27
  store ptr null, ptr %28, align 8, !tbaa !5
  br label %29

29:                                               ; preds = %23
  %30 = load i32, ptr %6, align 4, !tbaa !23
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %6, align 4, !tbaa !23
  br label %20, !llvm.loop !24

32:                                               ; preds = %20
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.jpeg_memory_mgr, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !14
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %39, i32 0, i32 9
  %41 = load i32, ptr %40, align 8, !tbaa !26
  %42 = mul nsw i32 %41, 64
  %43 = sext i32 %42 to i64
  %44 = mul i64 %43, 4
  %45 = call ptr %37(ptr noundef %38, i32 noundef 1, i64 noundef %44)
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %46, i32 0, i32 39
  store ptr %45, ptr %47, align 8, !tbaa !27
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %48, i32 0, i32 39
  %50 = load ptr, ptr %49, align 8, !tbaa !27
  %51 = getelementptr inbounds [64 x i32], ptr %50, i64 0
  %52 = getelementptr inbounds [64 x i32], ptr %51, i64 0, i64 0
  store ptr %52, ptr %4, align 8, !tbaa !5
  store i32 0, ptr %5, align 4, !tbaa !23
  br label %53

53:                                               ; preds = %70, %32
  %54 = load i32, ptr %5, align 4, !tbaa !23
  %55 = load ptr, ptr %2, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %55, i32 0, i32 9
  %57 = load i32, ptr %56, align 8, !tbaa !26
  %58 = icmp slt i32 %54, %57
  br i1 %58, label %59, label %73

59:                                               ; preds = %53
  store i32 0, ptr %6, align 4, !tbaa !23
  br label %60

60:                                               ; preds = %66, %59
  %61 = load i32, ptr %6, align 4, !tbaa !23
  %62 = icmp slt i32 %61, 64
  br i1 %62, label %63, label %69

63:                                               ; preds = %60
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds i32, ptr %64, i32 1
  store ptr %65, ptr %4, align 8, !tbaa !5
  store i32 -1, ptr %64, align 4, !tbaa !23
  br label %66

66:                                               ; preds = %63
  %67 = load i32, ptr %6, align 4, !tbaa !23
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %6, align 4, !tbaa !23
  br label %60, !llvm.loop !28

69:                                               ; preds = %60
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %5, align 4, !tbaa !23
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %5, align 4, !tbaa !23
  br label %53, !llvm.loop !29

73:                                               ; preds = %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare hidden void @start_pass_phuff_decoder(ptr noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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/C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"jpeg_decompress_struct", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !7, i64 32, !11, i64 36, !6, i64 40, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !11, i64 72, !12, i64 80, !7, i64 88, !7, i64 89, !11, i64 92, !7, i64 96, !7, i64 97, !7, i64 98, !11, i64 100, !7, i64 104, !11, i64 108, !7, i64 112, !7, i64 113, !7, i64 114, !11, i64 116, !11, i64 120, !11, i64 124, !11, i64 128, !11, i64 132, !11, i64 136, !6, i64 144, !11, i64 152, !11, i64 156, !11, i64 160, !11, i64 164, !11, i64 168, !6, i64 176, !7, i64 184, !7, i64 216, !7, i64 248, !11, i64 280, !6, i64 288, !7, i64 296, !7, i64 297, !7, i64 298, !7, i64 314, !7, i64 330, !11, i64 348, !7, i64 352, !7, i64 353, !7, i64 354, !7, i64 355, !13, i64 356, !13, i64 358, !7, i64 360, !7, i64 361, !7, i64 362, !6, i64 368, !11, i64 376, !11, i64 380, !11, i64 384, !11, i64 388, !6, i64 392, !11, i64 400, !7, i64 408, !11, i64 440, !11, i64 444, !11, i64 448, !7, i64 452, !11, i64 492, !11, i64 496, !11, i64 500, !11, i64 504, !11, i64 508, !6, i64 512, !6, i64 520, !6, i64 528, !6, i64 536, !6, i64 544, !6, i64 552, !6, i64 560, !6, i64 568, !6, i64 576, !6, i64 584, !6, i64 592}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"jpeg_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, !16, i64 88, !16, i64 96}
!16 = !{!"long", !7, i64 0}
!17 = !{!10, !6, i64 560}
!18 = !{!19, !6, i64 0}
!19 = !{!"", !20, i64 0, !21, i64 24, !22, i64 40, !11, i64 60, !7, i64 64, !6, i64 96}
!20 = !{!"jpeg_entropy_decoder", !6, i64 0, !6, i64 8, !7, i64 16}
!21 = !{!"", !16, i64 0, !11, i64 8}
!22 = !{!"", !11, i64 0, !7, i64 4}
!23 = !{!11, !11, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = !{!10, !11, i64 56}
!27 = !{!10, !6, i64 176}
!28 = distinct !{!28, !25}
!29 = distinct !{!29, !25}


; 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: nounwind uwtable
define dso_local void @jinit_phuff_decoder(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !13
  %5 = tail call ptr %4(ptr noundef %0, i32 noundef 1, i64 noundef 104) #2
  %6 = getelementptr inbounds i8, ptr %0, i64 560
  store ptr %5, ptr %6, align 8, !tbaa !16
  store ptr @start_pass_phuff_decoder, ptr %5, align 8, !tbaa !17
  %7 = getelementptr inbounds i8, ptr %5, i64 64
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %7, i8 0, i64 32, i1 false), !tbaa !22
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = load ptr, ptr %8, align 8, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %0, i64 56
  %11 = load i32, ptr %10, align 8, !tbaa !23
  %12 = shl nsw i32 %11, 6
  %13 = sext i32 %12 to i64
  %14 = shl nsw i64 %13, 2
  %15 = tail call ptr %9(ptr noundef %0, i32 noundef 1, i64 noundef %14) #2
  %16 = getelementptr inbounds i8, ptr %0, i64 176
  store ptr %15, ptr %16, align 8, !tbaa !24
  %17 = load i32, ptr %10, align 8, !tbaa !23
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %.preheader, label %._crit_edge

.preheader:                                       ; preds = %1, %.preheader
  %.01926 = phi i32 [ %19, %.preheader ], [ 0, %1 ]
  %.02025 = phi ptr [ %scevgep, %.preheader ], [ %15, %1 ]
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(256) %.02025, i8 -1, i64 256, i1 false), !tbaa !25
  %scevgep = getelementptr i8, ptr %.02025, i64 256
  %19 = add nuw nsw i32 %.01926, 1
  %20 = load i32, ptr %10, align 8, !tbaa !23
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %.preheader, label %._crit_edge, !llvm.loop !26

._crit_edge:                                      ; preds = %.preheader, %1
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @start_pass_phuff_decoder(ptr noundef) #0

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

attributes #0 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !7, i64 8}
!6 = !{!"jpeg_decompress_struct", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !8, i64 32, !10, i64 36, !7, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !10, i64 72, !11, i64 80, !8, i64 88, !8, i64 89, !10, i64 92, !8, i64 96, !8, i64 97, !8, i64 98, !10, i64 100, !8, i64 104, !10, i64 108, !8, i64 112, !8, i64 113, !8, i64 114, !10, i64 116, !10, i64 120, !10, i64 124, !10, i64 128, !10, i64 132, !10, i64 136, !7, i64 144, !10, i64 152, !10, i64 156, !10, i64 160, !10, i64 164, !10, i64 168, !7, i64 176, !8, i64 184, !8, i64 216, !8, i64 248, !10, i64 280, !7, i64 288, !8, i64 296, !8, i64 297, !8, i64 298, !8, i64 314, !8, i64 330, !10, i64 348, !8, i64 352, !8, i64 353, !8, i64 354, !8, i64 355, !12, i64 356, !12, i64 358, !8, i64 360, !8, i64 361, !8, i64 362, !7, i64 368, !10, i64 376, !10, i64 380, !10, i64 384, !10, i64 388, !7, i64 392, !10, i64 400, !8, i64 408, !10, i64 440, !10, i64 444, !10, i64 448, !8, i64 452, !10, i64 492, !10, i64 496, !10, i64 500, !10, i64 504, !10, i64 508, !7, i64 512, !7, i64 520, !7, i64 528, !7, i64 536, !7, i64 544, !7, i64 552, !7, i64 560, !7, i64 568, !7, i64 576, !7, i64 584, !7, i64 592}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"double", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!14, !7, i64 0}
!14 = !{!"jpeg_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, !15, i64 88, !15, i64 96}
!15 = !{!"long", !8, i64 0}
!16 = !{!6, !7, i64 560}
!17 = !{!18, !7, i64 0}
!18 = !{!"", !19, i64 0, !20, i64 24, !21, i64 40, !10, i64 60, !8, i64 64, !7, i64 96}
!19 = !{!"jpeg_entropy_decoder", !7, i64 0, !7, i64 8, !8, i64 16}
!20 = !{!"", !15, i64 0, !10, i64 8}
!21 = !{!"", !10, i64 0, !8, i64 4}
!22 = !{!7, !7, i64 0}
!23 = !{!6, !10, i64 56}
!24 = !{!6, !7, i64 176}
!25 = !{!10, !10, i64 0}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass