; LLVM IR from JayXon/Leanify :: lib/mozjpeg (jdarith)

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

; Function Attrs: nounwind uwtable
define dso_local void @jinit_arith_decoder(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %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 4, ptr %4) #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 344)
  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.arith_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, ptr %19, align 8, !tbaa !18
  store i32 0, ptr %4, align 4, !tbaa !21
  br label %20

20:                                               ; preds = %34, %1
  %21 = load i32, ptr %4, align 4, !tbaa !21
  %22 = icmp slt i32 %21, 16
  br i1 %22, label %23, label %37

23:                                               ; preds = %20
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.arith_entropy_decoder, ptr %24, i32 0, i32 7
  %26 = load i32, ptr %4, align 4, !tbaa !21
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [16 x ptr], ptr %25, i64 0, i64 %27
  store ptr null, ptr %28, align 8, !tbaa !5
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.arith_entropy_decoder, ptr %29, i32 0, i32 8
  %31 = load i32, ptr %4, align 4, !tbaa !21
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [16 x ptr], ptr %30, i64 0, i64 %32
  store ptr null, ptr %33, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %23
  %35 = load i32, ptr %4, align 4, !tbaa !21
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %4, align 4, !tbaa !21
  br label %20, !llvm.loop !22

37:                                               ; preds = %20
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.arith_entropy_decoder, ptr %38, i32 0, i32 9
  %40 = getelementptr inbounds [4 x i8], ptr %39, i64 0, i64 0
  store i8 113, ptr %40, align 8, !tbaa !24
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %41, i32 0, i32 45
  %43 = load i32, ptr %42, align 8, !tbaa !25
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %87

45:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %46, i32 0, i32 1
  %48 = load ptr, ptr %47, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.jpeg_memory_mgr, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !14
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %52, i32 0, i32 9
  %54 = load i32, ptr %53, align 8, !tbaa !26
  %55 = mul nsw i32 %54, 64
  %56 = sext i32 %55 to i64
  %57 = mul i64 %56, 4
  %58 = call ptr %50(ptr noundef %51, i32 noundef 1, i64 noundef %57)
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %59, i32 0, i32 39
  store ptr %58, ptr %60, align 8, !tbaa !27
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %61, i32 0, i32 39
  %63 = load ptr, ptr %62, align 8, !tbaa !27
  %64 = getelementptr inbounds [64 x i32], ptr %63, i64 0
  %65 = getelementptr inbounds [64 x i32], ptr %64, i64 0, i64 0
  store ptr %65, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %6, align 4, !tbaa !21
  br label %66

66:                                               ; preds = %83, %45
  %67 = load i32, ptr %6, align 4, !tbaa !21
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.jpeg_decompress_struct, ptr %68, i32 0, i32 9
  %70 = load i32, ptr %69, align 8, !tbaa !26
  %71 = icmp slt i32 %67, %70
  br i1 %71, label %72, label %86

72:                                               ; preds = %66
  store i32 0, ptr %4, align 4, !tbaa !21
  br label %73

73:                                               ; preds = %79, %72
  %74 = load i32, ptr %4, align 4, !tbaa !21
  %75 = icmp slt i32 %74, 64
  br i1 %75, label %76, label %82

76:                                               ; preds = %73
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds i32, ptr %77, i32 1
  store ptr %78, ptr %5, align 8, !tbaa !5
  store i32 -1, ptr %77, align 4, !tbaa !21
  br label %79

79:                                               ; preds = %76
  %80 = load i32, ptr %4, align 4, !tbaa !21
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %4, align 4, !tbaa !21
  br label %73, !llvm.loop !28

82:                                               ; preds = %73
  br label %83

83:                                               ; preds = %82
  %84 = load i32, ptr %6, align 4, !tbaa !21
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %6, align 4, !tbaa !21
  br label %66, !llvm.loop !29

86:                                               ; preds = %66
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %87

87:                                               ; preds = %86, %37
  call void @llvm.lifetime.end.p0(i64 4, 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(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, !11, 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, !11, i64 88, !11, i64 92, !11, i64 96, !11, i64 100, !11, i64 104, !11, i64 108, !11, 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, !7, i64 320, !7, i64 336, !7, i64 352, !11, i64 368, !11, i64 372, !7, i64 376, !7, i64 377, !7, i64 378, !13, i64 380, !13, i64 382, !11, i64 384, !7, i64 388, !11, i64 392, !6, i64 400, !11, i64 408, !11, i64 412, !11, i64 416, !11, i64 420, !6, i64 424, !11, i64 432, !7, i64 440, !11, i64 472, !11, i64 476, !11, i64 480, !7, i64 484, !11, i64 524, !11, i64 528, !11, i64 532, !11, i64 536, !11, i64 540, !6, i64 544, !6, i64 552, !6, i64 560, !6, i64 568, !6, i64 576, !6, i64 584, !6, i64 592, !6, i64 600, !6, i64 608, !6, i64 616, !6, i64 624}
!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 592}
!18 = !{!19, !6, i64 0}
!19 = !{!"", !20, i64 0, !16, i64 24, !16, i64 32, !11, i64 40, !7, i64 44, !7, i64 60, !11, i64 76, !7, i64 80, !7, i64 208, !7, i64 336}
!20 = !{!"jpeg_entropy_decoder", !6, i64 0, !6, i64 8, !11, i64 16}
!21 = !{!11, !11, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!7, !7, i64 0}
!25 = !{!10, !11, i64 312}
!26 = !{!10, !11, i64 56}
!27 = !{!10, !6, i64 192}
!28 = distinct !{!28, !23}
!29 = distinct !{!29, !23}


; 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_arith_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 344) #2
  %6 = getelementptr inbounds i8, ptr %0, i64 592
  store ptr %5, ptr %6, align 8, !tbaa !16
  store ptr @start_pass, ptr %5, align 8, !tbaa !17
  %7 = getelementptr inbounds i8, ptr %5, i64 80
  %8 = getelementptr inbounds i8, ptr %5, i64 336
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(256) %7, i8 0, i64 256, i1 false)
  store i8 113, ptr %8, align 8, !tbaa !20
  %9 = getelementptr inbounds i8, ptr %0, i64 312
  %10 = load i32, ptr %9, align 8, !tbaa !21
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %.loopexit, label %11

11:                                               ; preds = %1
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %0, i64 56
  %15 = load i32, ptr %14, align 8, !tbaa !22
  %16 = shl nsw i32 %15, 6
  %17 = sext i32 %16 to i64
  %18 = shl nsw i64 %17, 2
  %19 = tail call ptr %13(ptr noundef nonnull %0, i32 noundef 1, i64 noundef %18) #2
  %20 = getelementptr inbounds i8, ptr %0, i64 192
  store ptr %19, ptr %20, align 8, !tbaa !23
  %21 = load i32, ptr %14, align 8, !tbaa !22
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %11, %.preheader
  %.030 = phi i32 [ %23, %.preheader ], [ 0, %11 ]
  %.02329 = phi ptr [ %scevgep, %.preheader ], [ %19, %11 ]
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(256) %.02329, i8 -1, i64 256, i1 false), !tbaa !24
  %scevgep = getelementptr i8, ptr %.02329, i64 256
  %23 = add nuw nsw i32 %.030, 1
  %24 = load i32, ptr %14, align 8, !tbaa !22
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %.preheader, label %.loopexit, !llvm.loop !25

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

; Function Attrs: nounwind uwtable
declare hidden void @start_pass(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, !10, 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, !10, i64 88, !10, i64 92, !10, i64 96, !10, i64 100, !10, i64 104, !10, i64 108, !10, 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, !8, i64 320, !8, i64 336, !8, i64 352, !10, i64 368, !10, i64 372, !8, i64 376, !8, i64 377, !8, i64 378, !12, i64 380, !12, i64 382, !10, i64 384, !8, i64 388, !10, i64 392, !7, i64 400, !10, i64 408, !10, i64 412, !10, i64 416, !10, i64 420, !7, i64 424, !10, i64 432, !8, i64 440, !10, i64 472, !10, i64 476, !10, i64 480, !8, i64 484, !10, i64 524, !10, i64 528, !10, i64 532, !10, i64 536, !10, i64 540, !7, i64 544, !7, i64 552, !7, i64 560, !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 = !{!"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 592}
!17 = !{!18, !7, i64 0}
!18 = !{!"", !19, i64 0, !15, i64 24, !15, i64 32, !10, i64 40, !8, i64 44, !8, i64 60, !10, i64 76, !8, i64 80, !8, i64 208, !8, i64 336}
!19 = !{!"jpeg_entropy_decoder", !7, i64 0, !7, i64 8, !10, i64 16}
!20 = !{!8, !8, i64 0}
!21 = !{!6, !10, i64 312}
!22 = !{!6, !10, i64 56}
!23 = !{!6, !7, i64 192}
!24 = !{!10, !10, i64 0}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}


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