; LLVM IR from aagdev/mlimgsynth :: src/ccommon (image_io_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.CodecJpegSave = type { %struct.jpeg_compress_struct, %struct.img_codec_jpeg_error_mgr, ptr, i32 }
%struct.jpeg_compress_struct = type { ptr, ptr, ptr, ptr, i32, i32, ptr, i32, i32, i32, i32, double, i32, i32, i32, i32, i32, i32, i32, ptr, [4 x ptr], [4 x i32], [4 x ptr], [4 x ptr], [16 x i8], [16 x i8], [16 x i8], i32, ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i8, i16, i16, i32, i32, i32, i32, i32, i32, i32, i32, i32, [4 x ptr], i32, i32, i32, [10 x i32], i32, i32, i32, i32, i32, ptr, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32 }
%struct.img_codec_jpeg_error_mgr = 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] }
%struct.ImageIO = type { ptr, ptr, ptr, ptr, i32, i32 }
%struct.Image = type { ptr, i32, i32, i32, i32, i32, i32 }
%struct.CodecJpegText = type { ptr, ptr }

@g_allocator_dopt = external global ptr, align 8

; 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: inlinehint nounwind uwtable
declare hidden i32 @dynbuf_count(ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @dynbuf_free(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind returns_twice
declare i32 @_setjmp(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @imgio_jpeg_save_op(ptr noundef %0, ptr noundef %1, ptr noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca [1 x ptr], align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store ptr null, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.CodecJpegSave, ptr %13, i32 0, i32 0
  store ptr %14, ptr %9, align 8, !tbaa !5
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.CodecJpegSave, ptr %15, i32 0, i32 1
  %17 = getelementptr inbounds %struct.img_codec_jpeg_error_mgr, ptr %16, i32 0, i32 1
  %18 = getelementptr inbounds [1 x %struct.__jmp_buf_tag], ptr %17, i64 0, i64 0
  %19 = call i32 @_setjmp(ptr noundef %18) #6
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %3
  store i32 -780, ptr %7, align 4, !tbaa !9
  br label %160

22:                                               ; preds = %3
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.ImageIO, ptr %24, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = call i32 @jpeg_stream_dest(ptr noundef %23, ptr noundef %26)
  %28 = icmp slt i32 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %22
  store i32 -780, ptr %7, align 4, !tbaa !9
  br label %160

30:                                               ; preds = %22
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.Image, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 8, !tbaa !13
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.jpeg_compress_struct, ptr %34, i32 0, i32 7
  store i32 %33, ptr %35, align 8, !tbaa !15
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.Image, ptr %36, i32 0, i32 2
  %38 = load i32, ptr %37, align 4, !tbaa !19
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.jpeg_compress_struct, ptr %39, i32 0, i32 8
  store i32 %38, ptr %40, align 4, !tbaa !20
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.Image, ptr %41, i32 0, i32 5
  %43 = load i32, ptr %42, align 8, !tbaa !21
  switch i32 %43, label %54 [
    i32 258, label %44
    i32 1, label %49
  ]

44:                                               ; preds = %30
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.jpeg_compress_struct, ptr %45, i32 0, i32 10
  store i32 2, ptr %46, align 4, !tbaa !22
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.jpeg_compress_struct, ptr %47, i32 0, i32 9
  store i32 3, ptr %48, align 8, !tbaa !23
  br label %55

49:                                               ; preds = %30
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.jpeg_compress_struct, ptr %50, i32 0, i32 10
  store i32 1, ptr %51, align 4, !tbaa !22
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.jpeg_compress_struct, ptr %52, i32 0, i32 9
  store i32 1, ptr %53, align 8, !tbaa !23
  br label %55

54:                                               ; preds = %30
  store i32 -776, ptr %7, align 4, !tbaa !9
  br label %160

55:                                               ; preds = %49, %44
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  call void @jpeg_set_defaults(ptr noundef %56)
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.CodecJpegSave, ptr %58, i32 0, i32 3
  %60 = load i32, ptr %59, align 8, !tbaa !24
  call void @jpeg_set_quality(ptr noundef %57, i32 noundef %60, i32 noundef 1)
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  call void @jpeg_start_compress(ptr noundef %61, i32 noundef 1)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.CodecJpegSave, ptr %62, i32 0, i32 2
  %64 = load ptr, ptr %63, align 8, !tbaa !29
  %65 = getelementptr inbounds %struct.CodecJpegText, ptr %64, i64 0
  store ptr %65, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.CodecJpegSave, ptr %67, i32 0, i32 2
  %69 = load ptr, ptr %68, align 8, !tbaa !29
  %70 = call i32 @dynbuf_count(ptr noundef %69)
  %71 = zext i32 %70 to i64
  %72 = getelementptr inbounds %struct.CodecJpegText, ptr %66, i64 %71
  store ptr %72, ptr %11, align 8, !tbaa !5
  br label %73

73:                                               ; preds = %129, %55
  %74 = load ptr, ptr %10, align 8, !tbaa !5
  %75 = load ptr, ptr %11, align 8, !tbaa !5
  %76 = icmp ult ptr %74, %75
  br i1 %76, label %78, label %77

77:                                               ; preds = %73
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %132

78:                                               ; preds = %73
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.CodecJpegText, ptr %79, i32 0, i32 0
  %81 = load ptr, ptr %80, align 8, !tbaa !30
  %82 = call i32 @dynbuf_count(ptr noundef %81)
  %83 = load ptr, ptr %10, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.CodecJpegText, ptr %83, i32 0, i32 0
  %85 = load ptr, ptr %84, align 8, !tbaa !30
  %86 = load ptr, ptr @g_allocator_dopt, align 8, !tbaa !5
  %87 = call ptr @dynbuf_copy(ptr noundef %8, i32 noundef %82, ptr noundef %85, i64 noundef 1, i32 noundef 1, ptr noundef %86)
  %88 = load ptr, ptr %10, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.CodecJpegText, ptr %88, i32 0, i32 0
  %90 = load ptr, ptr %89, align 8, !tbaa !30
  %91 = icmp ne ptr %90, null
  br i1 %91, label %92, label %115

92:                                               ; preds = %78
  %93 = load ptr, ptr %10, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.CodecJpegText, ptr %93, i32 0, i32 0
  %95 = load ptr, ptr %94, align 8, !tbaa !30
  %96 = getelementptr inbounds i8, ptr %95, i64 0
  %97 = load i8, ptr %96, align 1, !tbaa !32
  %98 = sext i8 %97 to i32
  %99 = icmp ne i32 %98, 0
  br i1 %99, label %100, label %115

100:                                              ; preds = %92
  %101 = load ptr, ptr @g_allocator_dopt, align 8, !tbaa !5
  %102 = call ptr @dynbuf_append(ptr noundef %8, i32 noundef 1, ptr noundef null, i64 noundef 1, i32 noundef 1, ptr noundef %101)
  %103 = icmp ne ptr %102, null
  br i1 %103, label %104, label %112

104:                                              ; preds = %100
  %105 = load ptr, ptr %8, align 8, !tbaa !5
  %106 = load ptr, ptr %8, align 8, !tbaa !5
  %107 = call i32 @dynbuf_count(ptr noundef %106)
  %108 = sub i32 %107, 1
  %109 = zext i32 %108 to i64
  %110 = getelementptr inbounds i8, ptr %105, i64 %109
  store i8 10, ptr %110, align 1, !tbaa !32
  %111 = load ptr, ptr %8, align 8, !tbaa !5
  br label %113

112:                                              ; preds = %100
  br label %113

113:                                              ; preds = %112, %104
  %114 = phi ptr [ %111, %104 ], [ null, %112 ]
  br label %115

115:                                              ; preds = %113, %92, %78
  %116 = load ptr, ptr %10, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.CodecJpegText, ptr %116, i32 0, i32 1
  %118 = load ptr, ptr %117, align 8, !tbaa !33
  %119 = call i32 @dynbuf_count(ptr noundef %118)
  %120 = load ptr, ptr %10, align 8, !tbaa !5
  %121 = getelementptr inbounds %struct.CodecJpegText, ptr %120, i32 0, i32 1
  %122 = load ptr, ptr %121, align 8, !tbaa !33
  %123 = load ptr, ptr @g_allocator_dopt, align 8, !tbaa !5
  %124 = call ptr @dynbuf_append(ptr noundef %8, i32 noundef %119, ptr noundef %122, i64 noundef 1, i32 noundef 1, ptr noundef %123)
  %125 = load ptr, ptr %9, align 8, !tbaa !5
  %126 = load ptr, ptr %8, align 8, !tbaa !5
  %127 = load ptr, ptr %8, align 8, !tbaa !5
  %128 = call i32 @dynbuf_count(ptr noundef %127)
  call void @jpeg_write_marker(ptr noundef %125, i32 noundef 254, ptr noundef %126, i32 noundef %128)
  br label %129

129:                                              ; preds = %115
  %130 = load ptr, ptr %10, align 8, !tbaa !5
  %131 = getelementptr inbounds %struct.CodecJpegText, ptr %130, i32 1
  store ptr %131, ptr %10, align 8, !tbaa !5
  br label %73, !llvm.loop !34

132:                                              ; preds = %77
  br label %133

133:                                              ; preds = %141, %132
  %134 = load ptr, ptr %9, align 8, !tbaa !5
  %135 = getelementptr inbounds %struct.jpeg_compress_struct, ptr %134, i32 0, i32 45
  %136 = load i32, ptr %135, align 4, !tbaa !36
  %137 = load ptr, ptr %9, align 8, !tbaa !5
  %138 = getelementptr inbounds %struct.jpeg_compress_struct, ptr %137, i32 0, i32 8
  %139 = load i32, ptr %138, align 4, !tbaa !20
  %140 = icmp ult i32 %136, %139
  br i1 %140, label %141, label %158

141:                                              ; preds = %133
  %142 = load ptr, ptr %6, align 8, !tbaa !5
  %143 = getelementptr inbounds %struct.Image, ptr %142, i32 0, i32 0
  %144 = load ptr, ptr %143, align 8, !tbaa !37
  %145 = load ptr, ptr %9, align 8, !tbaa !5
  %146 = getelementptr inbounds %struct.jpeg_compress_struct, ptr %145, i32 0, i32 45
  %147 = load i32, ptr %146, align 4, !tbaa !36
  %148 = load ptr, ptr %6, align 8, !tbaa !5
  %149 = getelementptr inbounds %struct.Image, ptr %148, i32 0, i32 3
  %150 = load i32, ptr %149, align 8, !tbaa !38
  %151 = mul i32 %147, %150
  %152 = zext i32 %151 to i64
  %153 = getelementptr inbounds i8, ptr %144, i64 %152
  %154 = getelementptr inbounds [1 x ptr], ptr %12, i64 0, i64 0
  store ptr %153, ptr %154, align 8, !tbaa !5
  %155 = load ptr, ptr %9, align 8, !tbaa !5
  %156 = getelementptr inbounds [1 x ptr], ptr %12, i64 0, i64 0
  %157 = call i32 @jpeg_write_scanlines(ptr noundef %155, ptr noundef %156, i32 noundef 1)
  br label %133, !llvm.loop !39

158:                                              ; preds = %133
  %159 = load ptr, ptr %9, align 8, !tbaa !5
  call void @jpeg_finish_compress(ptr noundef %159)
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %160

160:                                              ; preds = %158, %54, %29, %21
  %161 = load ptr, ptr @g_allocator_dopt, align 8, !tbaa !5
  call void @dynbuf_free(ptr noundef %8, ptr noundef %161)
  %162 = load i32, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  ret i32 %162
}

; Function Attrs: nounwind uwtable
declare hidden i32 @jpeg_stream_dest(ptr noundef, ptr noundef) #3

declare void @jpeg_set_defaults(ptr noundef) #4

declare void @jpeg_set_quality(ptr noundef, i32 noundef, i32 noundef) #4

declare void @jpeg_start_compress(ptr noundef, i32 noundef) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @dynbuf_copy(ptr noundef, i32 noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @dynbuf_append(ptr noundef, i32 noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef) #1

declare void @jpeg_write_marker(ptr noundef, i32 noundef, ptr noundef, i32 noundef) #4

declare i32 @jpeg_write_scanlines(ptr noundef, ptr noundef, i32 noundef) #4

declare void @jpeg_finish_compress(ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = { nounwind returns_twice "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 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 #4 = { "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 #5 = { nounwind }
attributes #6 = { nounwind returns_twice }

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"ImageIO", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36}
!13 = !{!14, !10, i64 8}
!14 = !{!"Image", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!15 = !{!16, !10, i64 48}
!16 = !{!"jpeg_compress_struct", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36, !6, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !17, i64 64, !10, i64 72, !10, i64 76, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !10, i64 96, !6, i64 104, !7, i64 112, !7, i64 144, !7, i64 160, !7, i64 192, !7, i64 224, !7, i64 240, !7, i64 256, !10, i64 272, !6, i64 280, !10, i64 288, !10, i64 292, !10, i64 296, !10, i64 300, !10, i64 304, !10, i64 308, !10, i64 312, !10, i64 316, !10, i64 320, !10, i64 324, !7, i64 328, !7, i64 329, !7, i64 330, !18, i64 332, !18, i64 334, !10, i64 336, !10, i64 340, !10, i64 344, !10, i64 348, !10, i64 352, !10, i64 356, !10, i64 360, !10, i64 364, !10, i64 368, !7, i64 376, !10, i64 408, !10, i64 412, !10, i64 416, !7, i64 420, !10, i64 460, !10, i64 464, !10, i64 468, !10, i64 472, !10, i64 476, !6, i64 480, !10, i64 488, !6, i64 496, !6, i64 504, !6, i64 512, !6, i64 520, !6, i64 528, !6, i64 536, !6, i64 544, !6, i64 552, !6, i64 560, !6, i64 568, !10, i64 576}
!17 = !{!"double", !7, i64 0}
!18 = !{!"short", !7, i64 0}
!19 = !{!14, !10, i64 12}
!20 = !{!16, !10, i64 52}
!21 = !{!14, !10, i64 24}
!22 = !{!16, !10, i64 60}
!23 = !{!16, !10, i64 56}
!24 = !{!25, !10, i64 960}
!25 = !{!"CodecJpegSave", !16, i64 0, !26, i64 584, !6, i64 952, !10, i64 960}
!26 = !{!"img_codec_jpeg_error_mgr", !27, i64 0, !7, i64 168}
!27 = !{!"jpeg_error_mgr", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !7, i64 44, !10, i64 124, !28, i64 128, !6, i64 136, !10, i64 144, !6, i64 152, !10, i64 160, !10, i64 164}
!28 = !{!"long", !7, i64 0}
!29 = !{!25, !6, i64 952}
!30 = !{!31, !6, i64 0}
!31 = !{!"CodecJpegText", !6, i64 0, !6, i64 8}
!32 = !{!7, !7, i64 0}
!33 = !{!31, !6, i64 8}
!34 = distinct !{!34, !35}
!35 = !{!"llvm.loop.mustprogress"}
!36 = !{!16, !10, i64 340}
!37 = !{!14, !6, i64 0}
!38 = !{!14, !10, i64 16}
!39 = distinct !{!39, !35}


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

@g_allocator_dopt = external local_unnamed_addr global ptr, align 8

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @dynbuf_count(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @dynbuf_free(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind returns_twice
declare i32 @_setjmp(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 -780, 1) i32 @imgio_jpeg_save_op(ptr noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #3 {
  %4 = alloca ptr, align 8
  %5 = alloca [1 x ptr], align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  store ptr null, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 752
  %7 = call i32 @_setjmp(ptr noundef nonnull %6) #6
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %8, label %75

8:                                                ; preds = %3
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = call i32 @jpeg_stream_dest(ptr noundef %0, ptr noundef %10)
  %12 = icmp slt i32 %11, 0
  br i1 %12, label %75, label %13

13:                                               ; preds = %8
  %14 = getelementptr inbounds i8, ptr %2, i64 8
  %15 = getelementptr inbounds i8, ptr %0, i64 48
  %16 = getelementptr inbounds i8, ptr %0, i64 52
  %17 = load <2 x i32>, ptr %14, align 8, !tbaa !12
  store <2 x i32> %17, ptr %15, align 8, !tbaa !12
  %18 = getelementptr inbounds i8, ptr %2, i64 24
  %19 = load i32, ptr %18, align 8, !tbaa !13
  switch i32 %19, label %75 [
    i32 258, label %21
    i32 1, label %20
  ]

20:                                               ; preds = %13
  br label %21

21:                                               ; preds = %13, %20
  %22 = phi <2 x i32> [ <i32 1, i32 1>, %20 ], [ <i32 3, i32 2>, %13 ]
  %23 = getelementptr inbounds i8, ptr %0, i64 56
  store <2 x i32> %22, ptr %23, align 8, !tbaa !12
  call void @jpeg_set_defaults(ptr noundef nonnull %0) #5
  %24 = getelementptr inbounds i8, ptr %0, i64 960
  %25 = load i32, ptr %24, align 8, !tbaa !15
  call void @jpeg_set_quality(ptr noundef nonnull %0, i32 noundef %25, i32 noundef 1) #5
  call void @jpeg_start_compress(ptr noundef nonnull %0, i32 noundef 1) #5
  %26 = getelementptr inbounds i8, ptr %0, i64 952
  %27 = load ptr, ptr %26, align 8, !tbaa !23
  %28 = call i32 @dynbuf_count(ptr noundef %27)
  %29 = zext i32 %28 to i64
  %30 = getelementptr inbounds %struct.CodecJpegText, ptr %27, i64 %29
  %.not45 = icmp eq i32 %28, 0
  br i1 %.not45, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %53, %21
  %31 = getelementptr inbounds i8, ptr %0, i64 340
  %32 = load i32, ptr %31, align 4, !tbaa !24
  %33 = load i32, ptr %16, align 4, !tbaa !25
  %34 = icmp ult i32 %32, %33
  br i1 %34, label %.lr.ph44, label %._crit_edge

.lr.ph44:                                         ; preds = %.preheader
  %35 = getelementptr inbounds i8, ptr %2, i64 16
  br label %64

.lr.ph:                                           ; preds = %21, %53
  %.03743 = phi ptr [ %62, %53 ], [ %27, %21 ]
  %36 = load ptr, ptr %.03743, align 8, !tbaa !26
  %37 = call i32 @dynbuf_count(ptr noundef %36)
  %38 = load ptr, ptr %.03743, align 8, !tbaa !26
  %39 = load ptr, ptr @g_allocator_dopt, align 8, !tbaa !5
  %40 = call ptr @dynbuf_copy(ptr noundef nonnull %4, i32 noundef %37, ptr noundef %38, i64 noundef 1, i32 noundef 1, ptr noundef %39)
  %41 = load ptr, ptr %.03743, align 8, !tbaa !26
  %.not40 = icmp eq ptr %41, null
  br i1 %.not40, label %53, label %42

42:                                               ; preds = %.lr.ph
  %43 = load i8, ptr %41, align 1, !tbaa !28
  %.not41 = icmp eq i8 %43, 0
  br i1 %.not41, label %53, label %44

44:                                               ; preds = %42
  %45 = load ptr, ptr @g_allocator_dopt, align 8, !tbaa !5
  %46 = call ptr @dynbuf_append(ptr noundef nonnull %4, i32 noundef 1, ptr noundef null, i64 noundef 1, i32 noundef 1, ptr noundef %45)
  %.not42 = icmp eq ptr %46, null
  br i1 %.not42, label %53, label %47

47:                                               ; preds = %44
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = call i32 @dynbuf_count(ptr noundef %48)
  %50 = add i32 %49, -1
  %51 = zext i32 %50 to i64
  %52 = getelementptr inbounds i8, ptr %48, i64 %51
  store i8 10, ptr %52, align 1, !tbaa !28
  br label %53

53:                                               ; preds = %47, %44, %42, %.lr.ph
  %54 = getelementptr inbounds i8, ptr %.03743, i64 8
  %55 = load ptr, ptr %54, align 8, !tbaa !29
  %56 = call i32 @dynbuf_count(ptr noundef %55)
  %57 = load ptr, ptr %54, align 8, !tbaa !29
  %58 = load ptr, ptr @g_allocator_dopt, align 8, !tbaa !5
  %59 = call ptr @dynbuf_append(ptr noundef nonnull %4, i32 noundef %56, ptr noundef %57, i64 noundef 1, i32 noundef 1, ptr noundef %58)
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = call i32 @dynbuf_count(ptr noundef %60)
  call void @jpeg_write_marker(ptr noundef %0, i32 noundef 254, ptr noundef %60, i32 noundef %61) #5
  %62 = getelementptr inbounds i8, ptr %.03743, i64 16
  %63 = icmp ult ptr %62, %30
  br i1 %63, label %.lr.ph, label %.preheader, !llvm.loop !30

64:                                               ; preds = %.lr.ph44, %64
  %65 = phi i32 [ %32, %.lr.ph44 ], [ %72, %64 ]
  %66 = load ptr, ptr %2, align 8, !tbaa !32
  %67 = load i32, ptr %35, align 8, !tbaa !33
  %68 = mul i32 %67, %65
  %69 = zext i32 %68 to i64
  %70 = getelementptr inbounds i8, ptr %66, i64 %69
  store ptr %70, ptr %5, align 8, !tbaa !5
  %71 = call i32 @jpeg_write_scanlines(ptr noundef nonnull %0, ptr noundef nonnull %5, i32 noundef 1) #5
  %72 = load i32, ptr %31, align 4, !tbaa !24
  %73 = load i32, ptr %16, align 4, !tbaa !25
  %74 = icmp ult i32 %72, %73
  br i1 %74, label %64, label %._crit_edge, !llvm.loop !34

._crit_edge:                                      ; preds = %64, %.preheader
  call void @jpeg_finish_compress(ptr noundef nonnull %0) #5
  br label %75

75:                                               ; preds = %13, %8, %3, %._crit_edge
  %.0 = phi i32 [ 0, %._crit_edge ], [ -780, %3 ], [ -780, %8 ], [ -776, %13 ]
  %76 = load ptr, ptr @g_allocator_dopt, align 8, !tbaa !5
  call void @dynbuf_free(ptr noundef nonnull %4, ptr noundef %76)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @jpeg_stream_dest(ptr noundef, ptr noundef) local_unnamed_addr #3

declare void @jpeg_set_defaults(ptr noundef) local_unnamed_addr #4

declare void @jpeg_set_quality(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #4

declare void @jpeg_start_compress(ptr noundef, i32 noundef) local_unnamed_addr #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @dynbuf_copy(ptr noundef, i32 noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @dynbuf_append(ptr noundef, i32 noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

declare void @jpeg_write_marker(ptr noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #4

declare i32 @jpeg_write_scanlines(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #4

declare void @jpeg_finish_compress(ptr noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = { nounwind returns_twice "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 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 #4 = { "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 #5 = { nounwind }
attributes #6 = { nounwind returns_twice }

!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 = !{!"ImageIO", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !11, i64 36}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !11, i64 24}
!14 = !{!"Image", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28}
!15 = !{!16, !11, i64 960}
!16 = !{!"CodecJpegSave", !17, i64 0, !20, i64 584, !6, i64 952, !11, i64 960}
!17 = !{!"jpeg_compress_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, !18, i64 64, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !11, i64 96, !6, i64 104, !7, i64 112, !7, i64 144, !7, i64 160, !7, i64 192, !7, i64 224, !7, i64 240, !7, i64 256, !11, i64 272, !6, i64 280, !11, i64 288, !11, i64 292, !11, i64 296, !11, i64 300, !11, i64 304, !11, i64 308, !11, i64 312, !11, i64 316, !11, i64 320, !11, i64 324, !7, i64 328, !7, i64 329, !7, i64 330, !19, i64 332, !19, i64 334, !11, i64 336, !11, i64 340, !11, i64 344, !11, i64 348, !11, i64 352, !11, i64 356, !11, i64 360, !11, i64 364, !11, i64 368, !7, i64 376, !11, i64 408, !11, i64 412, !11, i64 416, !7, i64 420, !11, i64 460, !11, i64 464, !11, i64 468, !11, i64 472, !11, i64 476, !6, i64 480, !11, i64 488, !6, i64 496, !6, i64 504, !6, i64 512, !6, i64 520, !6, i64 528, !6, i64 536, !6, i64 544, !6, i64 552, !6, i64 560, !6, i64 568, !11, i64 576}
!18 = !{!"double", !7, i64 0}
!19 = !{!"short", !7, i64 0}
!20 = !{!"img_codec_jpeg_error_mgr", !21, i64 0, !7, i64 168}
!21 = !{!"jpeg_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, !22, i64 128, !6, i64 136, !11, i64 144, !6, i64 152, !11, i64 160, !11, i64 164}
!22 = !{!"long", !7, i64 0}
!23 = !{!16, !6, i64 952}
!24 = !{!17, !11, i64 340}
!25 = !{!17, !11, i64 52}
!26 = !{!27, !6, i64 0}
!27 = !{!"CodecJpegText", !6, i64 0, !6, i64 8}
!28 = !{!7, !7, i64 0}
!29 = !{!27, !6, i64 8}
!30 = distinct !{!30, !31}
!31 = !{!"llvm.loop.mustprogress"}
!32 = !{!14, !6, i64 0}
!33 = !{!14, !11, i64 16}
!34 = distinct !{!34, !31}


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