; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseImageSaveJpeg.ll (ZN4Simd4Base14ImageJpegSaver8ToStreamEPKhm)

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

%"class.Simd::Base::ImageJpegSaver" = type { %"class.Simd::ImageSaver", %"struct.Simd::Array", ptr, ptr, ptr, ptr, ptr, i8, i32, i32, i32, [64 x float], [64 x float], [64 x i8], [64 x i8] }
%"class.Simd::ImageSaver" = type { ptr, %"struct.Simd::ImageSaverParam", %"class.Simd::OutputMemoryStream" }
%"struct.Simd::ImageSaverParam" = type { i64, i64, i32, i32, i32, i32 }
%"class.Simd::OutputMemoryStream" = type { i64, ptr, i64, i64, i64, i64, i64 }
%"struct.Simd::Array" = type { ptr, i64 }

@_ZZN4Simd4Base14ImageJpegSaver8ToStreamEPKhmE9FILL_BITS = external hidden constant [2 x i16], align 2

; 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
declare dso_local void @_ZN4Simd4Base14ImageJpegSaver11WriteHeaderEv(ptr noundef nonnull align 8 dereferenceable(808)) #1 align 2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZN4Simd18OutputMemoryStream7Write8uEh(ptr noundef nonnull align 8 dereferenceable(56), i8 noundef zeroext) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4Simd4Base14ImageJpegSaver8ToStreamEPKhm(ptr noundef nonnull align 8 dereferenceable(808) %0, ptr noundef %1, i64 noundef %2) unnamed_addr #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca [3 x i32], align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  %13 = load ptr, ptr %4, align 8
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = getelementptr inbounds ptr, ptr %14, i64 5
  %16 = load ptr, ptr %15, align 8
  call void %16(ptr noundef nonnull align 8 dereferenceable(808) %13)
  call void @_ZN4Simd4Base14ImageJpegSaver11WriteHeaderEv(ptr noundef nonnull align 8 dereferenceable(808) %13)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %17 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 1
  %18 = getelementptr inbounds %"struct.Simd::Array", ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  store ptr %19, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 10
  %22 = load i32, ptr %21, align 4, !tbaa !24
  %23 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 9
  %24 = load i32, ptr %23, align 8, !tbaa !25
  %25 = mul nsw i32 %22, %24
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i8, ptr %20, i64 %26
  store ptr %27, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 10
  %30 = load i32, ptr %29, align 4, !tbaa !24
  %31 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 9
  %32 = load i32, ptr %31, align 8, !tbaa !25
  %33 = mul nsw i32 %30, %32
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds i8, ptr %28, i64 %34
  store ptr %35, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 12, ptr %10) #5
  call void @llvm.memset.p0.i64(ptr align 4 %10, i8 0, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !26
  br label %36

36:                                               ; preds = %198, %3
  %37 = load i32, ptr %11, align 4, !tbaa !26
  %38 = getelementptr inbounds %"class.Simd::ImageSaver", ptr %13, i32 0, i32 1
  %39 = getelementptr inbounds %"struct.Simd::ImageSaverParam", ptr %38, i32 0, i32 1
  %40 = load i64, ptr %39, align 8, !tbaa !27
  %41 = trunc i64 %40 to i32
  %42 = icmp slt i32 %37, %41
  br i1 %42, label %44, label %43

43:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %203

44:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %45 = load i32, ptr %11, align 4, !tbaa !26
  %46 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 9
  %47 = load i32, ptr %46, align 8, !tbaa !25
  %48 = add nsw i32 %45, %47
  %49 = getelementptr inbounds %"class.Simd::ImageSaver", ptr %13, i32 0, i32 1
  %50 = getelementptr inbounds %"struct.Simd::ImageSaverParam", ptr %49, i32 0, i32 1
  %51 = load i64, ptr %50, align 8, !tbaa !27
  %52 = trunc i64 %51 to i32
  %53 = call noundef i32 @_ZN4Simd3MinIiEET_S1_S1_(i32 noundef %48, i32 noundef %52)
  %54 = load i32, ptr %11, align 4, !tbaa !26
  %55 = sub nsw i32 %53, %54
  store i32 %55, ptr %12, align 4, !tbaa !26
  %56 = getelementptr inbounds %"class.Simd::ImageSaver", ptr %13, i32 0, i32 1
  %57 = getelementptr inbounds %"struct.Simd::ImageSaverParam", ptr %56, i32 0, i32 2
  %58 = load i32, ptr %57, align 8, !tbaa !28
  switch i32 %58, label %147 [
    i32 3, label %59
    i32 4, label %81
    i32 16, label %103
    i32 17, label %125
  ]

59:                                               ; preds = %44
  %60 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 2
  %61 = load ptr, ptr %60, align 8, !tbaa !29
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = load i64, ptr %6, align 8, !tbaa !9
  %64 = getelementptr inbounds %"class.Simd::ImageSaver", ptr %13, i32 0, i32 1
  %65 = getelementptr inbounds %"struct.Simd::ImageSaverParam", ptr %64, i32 0, i32 0
  %66 = load i64, ptr %65, align 8, !tbaa !30
  %67 = load i32, ptr %12, align 4, !tbaa !26
  %68 = sext i32 %67 to i64
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  %70 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 10
  %71 = load i32, ptr %70, align 4, !tbaa !24
  %72 = sext i32 %71 to i64
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 10
  %75 = load i32, ptr %74, align 4, !tbaa !24
  %76 = sext i32 %75 to i64
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 10
  %79 = load i32, ptr %78, align 4, !tbaa !24
  %80 = sext i32 %79 to i64
  call void %61(ptr noundef %62, i64 noundef %63, i64 noundef %66, i64 noundef %68, ptr noundef %69, i64 noundef %72, ptr noundef %73, i64 noundef %76, ptr noundef %77, i64 noundef %80)
  br label %148

81:                                               ; preds = %44
  %82 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 3
  %83 = load ptr, ptr %82, align 8, !tbaa !31
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = load i64, ptr %6, align 8, !tbaa !9
  %86 = getelementptr inbounds %"class.Simd::ImageSaver", ptr %13, i32 0, i32 1
  %87 = getelementptr inbounds %"struct.Simd::ImageSaverParam", ptr %86, i32 0, i32 0
  %88 = load i64, ptr %87, align 8, !tbaa !30
  %89 = load i32, ptr %12, align 4, !tbaa !26
  %90 = sext i32 %89 to i64
  %91 = load ptr, ptr %9, align 8, !tbaa !5
  %92 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 10
  %93 = load i32, ptr %92, align 4, !tbaa !24
  %94 = sext i32 %93 to i64
  %95 = load ptr, ptr %8, align 8, !tbaa !5
  %96 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 10
  %97 = load i32, ptr %96, align 4, !tbaa !24
  %98 = sext i32 %97 to i64
  %99 = load ptr, ptr %7, align 8, !tbaa !5
  %100 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 10
  %101 = load i32, ptr %100, align 4, !tbaa !24
  %102 = sext i32 %101 to i64
  call void %83(ptr noundef %84, i64 noundef %85, i64 noundef %88, i64 noundef %90, ptr noundef %91, i64 noundef %94, ptr noundef %95, i64 noundef %98, ptr noundef %99, i64 noundef %102, ptr noundef null, i64 noundef 0)
  br label %148

103:                                              ; preds = %44
  %104 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 2
  %105 = load ptr, ptr %104, align 8, !tbaa !29
  %106 = load ptr, ptr %5, align 8, !tbaa !5
  %107 = load i64, ptr %6, align 8, !tbaa !9
  %108 = getelementptr inbounds %"class.Simd::ImageSaver", ptr %13, i32 0, i32 1
  %109 = getelementptr inbounds %"struct.Simd::ImageSaverParam", ptr %108, i32 0, i32 0
  %110 = load i64, ptr %109, align 8, !tbaa !30
  %111 = load i32, ptr %12, align 4, !tbaa !26
  %112 = sext i32 %111 to i64
  %113 = load ptr, ptr %7, align 8, !tbaa !5
  %114 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 10
  %115 = load i32, ptr %114, align 4, !tbaa !24
  %116 = sext i32 %115 to i64
  %117 = load ptr, ptr %8, align 8, !tbaa !5
  %118 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 10
  %119 = load i32, ptr %118, align 4, !tbaa !24
  %120 = sext i32 %119 to i64
  %121 = load ptr, ptr %9, align 8, !tbaa !5
  %122 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 10
  %123 = load i32, ptr %122, align 4, !tbaa !24
  %124 = sext i32 %123 to i64
  call void %105(ptr noundef %106, i64 noundef %107, i64 noundef %110, i64 noundef %112, ptr noundef %113, i64 noundef %116, ptr noundef %117, i64 noundef %120, ptr noundef %121, i64 noundef %124)
  br label %148

125:                                              ; preds = %44
  %126 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 3
  %127 = load ptr, ptr %126, align 8, !tbaa !31
  %128 = load ptr, ptr %5, align 8, !tbaa !5
  %129 = load i64, ptr %6, align 8, !tbaa !9
  %130 = getelementptr inbounds %"class.Simd::ImageSaver", ptr %13, i32 0, i32 1
  %131 = getelementptr inbounds %"struct.Simd::ImageSaverParam", ptr %130, i32 0, i32 0
  %132 = load i64, ptr %131, align 8, !tbaa !30
  %133 = load i32, ptr %12, align 4, !tbaa !26
  %134 = sext i32 %133 to i64
  %135 = load ptr, ptr %7, align 8, !tbaa !5
  %136 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 10
  %137 = load i32, ptr %136, align 4, !tbaa !24
  %138 = sext i32 %137 to i64
  %139 = load ptr, ptr %8, align 8, !tbaa !5
  %140 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 10
  %141 = load i32, ptr %140, align 4, !tbaa !24
  %142 = sext i32 %141 to i64
  %143 = load ptr, ptr %9, align 8, !tbaa !5
  %144 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 10
  %145 = load i32, ptr %144, align 4, !tbaa !24
  %146 = sext i32 %145 to i64
  call void %127(ptr noundef %128, i64 noundef %129, i64 noundef %132, i64 noundef %134, ptr noundef %135, i64 noundef %138, ptr noundef %139, i64 noundef %142, ptr noundef %143, i64 noundef %146, ptr noundef null, i64 noundef 0)
  br label %148

147:                                              ; preds = %44
  br label %148

148:                                              ; preds = %147, %125, %103, %81, %59
  %149 = getelementptr inbounds %"class.Simd::ImageSaver", ptr %13, i32 0, i32 1
  %150 = getelementptr inbounds %"struct.Simd::ImageSaverParam", ptr %149, i32 0, i32 2
  %151 = load i32, ptr %150, align 8, !tbaa !28
  %152 = icmp eq i32 %151, 1
  br i1 %152, label %153, label %172

153:                                              ; preds = %148
  %154 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 4
  %155 = load ptr, ptr %154, align 8, !tbaa !32
  %156 = getelementptr inbounds %"class.Simd::ImageSaver", ptr %13, i32 0, i32 2
  %157 = getelementptr inbounds %"class.Simd::ImageSaver", ptr %13, i32 0, i32 1
  %158 = getelementptr inbounds %"struct.Simd::ImageSaverParam", ptr %157, i32 0, i32 0
  %159 = load i64, ptr %158, align 8, !tbaa !30
  %160 = trunc i64 %159 to i32
  %161 = load i32, ptr %12, align 4, !tbaa !26
  %162 = load ptr, ptr %5, align 8, !tbaa !5
  %163 = load ptr, ptr %5, align 8, !tbaa !5
  %164 = load ptr, ptr %5, align 8, !tbaa !5
  %165 = load i64, ptr %6, align 8, !tbaa !9
  %166 = trunc i64 %165 to i32
  %167 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 11
  %168 = getelementptr inbounds [64 x float], ptr %167, i64 0, i64 0
  %169 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 12
  %170 = getelementptr inbounds [64 x float], ptr %169, i64 0, i64 0
  %171 = getelementptr inbounds [3 x i32], ptr %10, i64 0, i64 0
  call void %155(ptr noundef nonnull align 8 dereferenceable(56) %156, i32 noundef %160, i32 noundef %161, ptr noundef %162, ptr noundef %163, ptr noundef %164, i32 noundef %166, ptr noundef %168, ptr noundef %170, ptr noundef %171)
  br label %191

172:                                              ; preds = %148
  %173 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 4
  %174 = load ptr, ptr %173, align 8, !tbaa !32
  %175 = getelementptr inbounds %"class.Simd::ImageSaver", ptr %13, i32 0, i32 2
  %176 = getelementptr inbounds %"class.Simd::ImageSaver", ptr %13, i32 0, i32 1
  %177 = getelementptr inbounds %"struct.Simd::ImageSaverParam", ptr %176, i32 0, i32 0
  %178 = load i64, ptr %177, align 8, !tbaa !30
  %179 = trunc i64 %178 to i32
  %180 = load i32, ptr %12, align 4, !tbaa !26
  %181 = load ptr, ptr %7, align 8, !tbaa !5
  %182 = load ptr, ptr %8, align 8, !tbaa !5
  %183 = load ptr, ptr %9, align 8, !tbaa !5
  %184 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 10
  %185 = load i32, ptr %184, align 4, !tbaa !24
  %186 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 11
  %187 = getelementptr inbounds [64 x float], ptr %186, i64 0, i64 0
  %188 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 12
  %189 = getelementptr inbounds [64 x float], ptr %188, i64 0, i64 0
  %190 = getelementptr inbounds [3 x i32], ptr %10, i64 0, i64 0
  call void %174(ptr noundef nonnull align 8 dereferenceable(56) %175, i32 noundef %179, i32 noundef %180, ptr noundef %181, ptr noundef %182, ptr noundef %183, i32 noundef %185, ptr noundef %187, ptr noundef %189, ptr noundef %190)
  br label %191

191:                                              ; preds = %172, %153
  %192 = load i32, ptr %12, align 4, !tbaa !26
  %193 = sext i32 %192 to i64
  %194 = load i64, ptr %6, align 8, !tbaa !9
  %195 = mul i64 %193, %194
  %196 = load ptr, ptr %5, align 8, !tbaa !5
  %197 = getelementptr inbounds i8, ptr %196, i64 %195
  store ptr %197, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %198

198:                                              ; preds = %191
  %199 = getelementptr inbounds %"class.Simd::Base::ImageJpegSaver", ptr %13, i32 0, i32 9
  %200 = load i32, ptr %199, align 8, !tbaa !25
  %201 = load i32, ptr %11, align 4, !tbaa !26
  %202 = add nsw i32 %201, %200
  store i32 %202, ptr %11, align 4, !tbaa !26
  br label %36, !llvm.loop !33

203:                                              ; preds = %43
  %204 = getelementptr inbounds %"class.Simd::ImageSaver", ptr %13, i32 0, i32 2
  call void @_ZN4Simd4Base9WriteBitsERNS_18OutputMemoryStreamEPKt(ptr noundef nonnull align 8 dereferenceable(56) %204, ptr noundef @_ZZN4Simd4Base14ImageJpegSaver8ToStreamEPKhmE9FILL_BITS)
  %205 = getelementptr inbounds %"class.Simd::ImageSaver", ptr %13, i32 0, i32 2
  call void @_ZN4Simd18OutputMemoryStream7Write8uEh(ptr noundef nonnull align 8 dereferenceable(56) %205, i8 noundef zeroext -1)
  %206 = getelementptr inbounds %"class.Simd::ImageSaver", ptr %13, i32 0, i32 2
  call void @_ZN4Simd18OutputMemoryStream7Write8uEh(ptr noundef nonnull align 8 dereferenceable(56) %206, i8 noundef zeroext -39)
  call void @llvm.lifetime.end.p0(i64 12, ptr %10) #5
  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 8, ptr %7) #5
  ret i1 true
}

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

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN4Simd3MinIiEET_S1_S1_(i32 noundef, i32 noundef) #4

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZN4Simd4Base9WriteBitsERNS_18OutputMemoryStreamEPKt(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef) #2

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 = { alwaysinline 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { alwaysinline mustprogress 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 #5 = { 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = !{!14, !6, i64 96}
!14 = !{!"_ZTSN4Simd4Base14ImageJpegSaverE", !15, i64 0, !22, i64 96, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !23, i64 152, !19, i64 156, !19, i64 160, !19, i64 164, !7, i64 168, !7, i64 424, !7, i64 680, !7, i64 744}
!15 = !{!"_ZTSN4Simd10ImageSaverE", !16, i64 8, !21, i64 40}
!16 = !{!"_ZTSN4Simd15ImageSaverParamE", !10, i64 0, !10, i64 8, !17, i64 16, !18, i64 20, !19, i64 24, !20, i64 28}
!17 = !{!"_ZTS19SimdPixelFormatType", !7, i64 0}
!18 = !{!"_ZTS17SimdImageFileType", !7, i64 0}
!19 = !{!"int", !7, i64 0}
!20 = !{!"_ZTS11SimdYuvType", !7, i64 0}
!21 = !{!"_ZTSN4Simd18OutputMemoryStreamE", !10, i64 0, !6, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48}
!22 = !{!"_ZTSN4Simd5ArrayIhEE", !6, i64 0, !10, i64 8}
!23 = !{!"bool", !7, i64 0}
!24 = !{!14, !19, i64 164}
!25 = !{!14, !19, i64 160}
!26 = !{!19, !19, i64 0}
!27 = !{!15, !10, i64 16}
!28 = !{!15, !17, i64 24}
!29 = !{!14, !6, i64 112}
!30 = !{!15, !10, i64 8}
!31 = !{!14, !6, i64 120}
!32 = !{!14, !6, i64 128}
!33 = distinct !{!33, !34}
!34 = !{!"llvm.loop.mustprogress"}


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

@_ZZN4Simd4Base14ImageJpegSaver8ToStreamEPKhmE9FILL_BITS = external hidden constant [2 x i16], align 2

; 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: mustprogress uwtable
declare dso_local void @_ZN4Simd4Base14ImageJpegSaver11WriteHeaderEv(ptr noundef nonnull align 8 dereferenceable(808)) local_unnamed_addr #1 align 2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZN4Simd18OutputMemoryStream7Write8uEh(ptr noundef nonnull align 8 dereferenceable(56), i8 noundef zeroext) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4Simd4Base14ImageJpegSaver8ToStreamEPKhm(ptr noundef nonnull align 8 dereferenceable(808) %0, ptr noundef %1, i64 noundef %2) unnamed_addr #1 align 2 {
  %4 = alloca [3 x i32], align 4
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 40
  %7 = load ptr, ptr %6, align 8
  tail call void %7(ptr noundef nonnull align 8 dereferenceable(808) %0)
  tail call void @_ZN4Simd4Base14ImageJpegSaver11WriteHeaderEv(ptr noundef nonnull align 8 dereferenceable(808) %0)
  %8 = getelementptr inbounds i8, ptr %0, i64 96
  %9 = load ptr, ptr %8, align 8, !tbaa !8
  %10 = getelementptr inbounds i8, ptr %0, i64 164
  %11 = load i32, ptr %10, align 4, !tbaa !22
  %12 = getelementptr inbounds i8, ptr %0, i64 160
  %13 = load i32, ptr %12, align 8, !tbaa !23
  %14 = mul nsw i32 %13, %11
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds i8, ptr %9, i64 %15
  %17 = getelementptr inbounds i8, ptr %16, i64 %15
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %4) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(12) %4, i8 0, i64 12, i1 false)
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  %19 = getelementptr inbounds i8, ptr %0, i64 16
  %20 = load i64, ptr %19, align 8, !tbaa !24
  %21 = trunc i64 %20 to i32
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %23 = getelementptr inbounds i8, ptr %0, i64 24
  %24 = getelementptr inbounds i8, ptr %0, i64 120
  %25 = getelementptr inbounds i8, ptr %0, i64 112
  %26 = getelementptr inbounds i8, ptr %0, i64 128
  %27 = getelementptr inbounds i8, ptr %0, i64 40
  %28 = getelementptr inbounds i8, ptr %0, i64 168
  %29 = getelementptr inbounds i8, ptr %0, i64 424
  %30 = trunc i64 %2 to i32
  br label %32

._crit_edge:                                      ; preds = %72, %3
  %31 = getelementptr inbounds i8, ptr %0, i64 40
  call void @_ZN4Simd4Base9WriteBitsERNS_18OutputMemoryStreamEPKt(ptr noundef nonnull align 8 dereferenceable(56) %31, ptr noundef nonnull @_ZZN4Simd4Base14ImageJpegSaver8ToStreamEPKhmE9FILL_BITS)
  call void @_ZN4Simd18OutputMemoryStream7Write8uEh(ptr noundef nonnull align 8 dereferenceable(56) %31, i8 noundef zeroext -1)
  call void @_ZN4Simd18OutputMemoryStream7Write8uEh(ptr noundef nonnull align 8 dereferenceable(56) %31, i8 noundef zeroext -39)
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #5
  ret i1 true

32:                                               ; preds = %.lr.ph, %72
  %33 = phi i32 [ %13, %.lr.ph ], [ %76, %72 ]
  %34 = phi i32 [ %21, %.lr.ph ], [ %79, %72 ]
  %.045 = phi ptr [ %1, %.lr.ph ], [ %75, %72 ]
  %.04244 = phi i32 [ 0, %.lr.ph ], [ %77, %72 ]
  %35 = add nsw i32 %33, %.04244
  %36 = call noundef i32 @_ZN4Simd3MinIiEET_S1_S1_(i32 noundef %35, i32 noundef %34)
  %37 = sub nsw i32 %36, %.04244
  %38 = load i32, ptr %23, align 8, !tbaa !25
  switch i32 %38, label %63 [
    i32 3, label %39
    i32 4, label %45
    i32 16, label %51
    i32 17, label %57
  ]

39:                                               ; preds = %32
  %40 = load ptr, ptr %25, align 8, !tbaa !26
  %41 = load i64, ptr %18, align 8, !tbaa !27
  %42 = sext i32 %37 to i64
  %43 = load i32, ptr %10, align 4, !tbaa !22
  %44 = sext i32 %43 to i64
  call void %40(ptr noundef %.045, i64 noundef %2, i64 noundef %41, i64 noundef %42, ptr noundef %17, i64 noundef %44, ptr noundef %16, i64 noundef %44, ptr noundef %9, i64 noundef %44)
  br label %thread-pre-split

45:                                               ; preds = %32
  %46 = load ptr, ptr %24, align 8, !tbaa !28
  %47 = load i64, ptr %18, align 8, !tbaa !27
  %48 = sext i32 %37 to i64
  %49 = load i32, ptr %10, align 4, !tbaa !22
  %50 = sext i32 %49 to i64
  call void %46(ptr noundef %.045, i64 noundef %2, i64 noundef %47, i64 noundef %48, ptr noundef %17, i64 noundef %50, ptr noundef %16, i64 noundef %50, ptr noundef %9, i64 noundef %50, ptr noundef null, i64 noundef 0)
  br label %thread-pre-split

51:                                               ; preds = %32
  %52 = load ptr, ptr %25, align 8, !tbaa !26
  %53 = load i64, ptr %18, align 8, !tbaa !27
  %54 = sext i32 %37 to i64
  %55 = load i32, ptr %10, align 4, !tbaa !22
  %56 = sext i32 %55 to i64
  call void %52(ptr noundef %.045, i64 noundef %2, i64 noundef %53, i64 noundef %54, ptr noundef %9, i64 noundef %56, ptr noundef %16, i64 noundef %56, ptr noundef %17, i64 noundef %56)
  br label %thread-pre-split

57:                                               ; preds = %32
  %58 = load ptr, ptr %24, align 8, !tbaa !28
  %59 = load i64, ptr %18, align 8, !tbaa !27
  %60 = sext i32 %37 to i64
  %61 = load i32, ptr %10, align 4, !tbaa !22
  %62 = sext i32 %61 to i64
  call void %58(ptr noundef %.045, i64 noundef %2, i64 noundef %59, i64 noundef %60, ptr noundef %9, i64 noundef %62, ptr noundef %16, i64 noundef %62, ptr noundef %17, i64 noundef %62, ptr noundef null, i64 noundef 0)
  br label %thread-pre-split

thread-pre-split:                                 ; preds = %39, %45, %51, %57
  %.pr = load i32, ptr %23, align 8, !tbaa !25
  br label %63

63:                                               ; preds = %thread-pre-split, %32
  %64 = phi i32 [ %.pr, %thread-pre-split ], [ %38, %32 ]
  %65 = icmp eq i32 %64, 1
  %66 = load ptr, ptr %26, align 8, !tbaa !29
  %67 = load i64, ptr %18, align 8, !tbaa !27
  %68 = trunc i64 %67 to i32
  br i1 %65, label %69, label %70

69:                                               ; preds = %63
  call void %66(ptr noundef nonnull align 8 dereferenceable(56) %27, i32 noundef %68, i32 noundef %37, ptr noundef %.045, ptr noundef %.045, ptr noundef %.045, i32 noundef %30, ptr noundef nonnull %28, ptr noundef nonnull %29, ptr noundef nonnull %4)
  br label %72

70:                                               ; preds = %63
  %71 = load i32, ptr %10, align 4, !tbaa !22
  call void %66(ptr noundef nonnull align 8 dereferenceable(56) %27, i32 noundef %68, i32 noundef %37, ptr noundef %9, ptr noundef %16, ptr noundef %17, i32 noundef %71, ptr noundef nonnull %28, ptr noundef nonnull %29, ptr noundef nonnull %4)
  br label %72

72:                                               ; preds = %70, %69
  %73 = sext i32 %37 to i64
  %74 = mul i64 %73, %2
  %75 = getelementptr inbounds i8, ptr %.045, i64 %74
  %76 = load i32, ptr %12, align 8, !tbaa !23
  %77 = add nsw i32 %76, %.04244
  %78 = load i64, ptr %19, align 8, !tbaa !24
  %79 = trunc i64 %78 to i32
  %80 = icmp slt i32 %77, %79
  br i1 %80, label %32, label %._crit_edge, !llvm.loop !30
}

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

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN4Simd3MinIiEET_S1_S1_(i32 noundef, i32 noundef) local_unnamed_addr #4

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZN4Simd4Base9WriteBitsERNS_18OutputMemoryStreamEPKt(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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 = { alwaysinline 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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { alwaysinline mustprogress 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 #5 = { 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !19, i64 96}
!9 = !{!"_ZTSN4Simd4Base14ImageJpegSaverE", !10, i64 0, !20, i64 96, !19, i64 112, !19, i64 120, !19, i64 128, !19, i64 136, !19, i64 144, !21, i64 152, !16, i64 156, !16, i64 160, !16, i64 164, !13, i64 168, !13, i64 424, !13, i64 680, !13, i64 744}
!10 = !{!"_ZTSN4Simd10ImageSaverE", !11, i64 8, !18, i64 40}
!11 = !{!"_ZTSN4Simd15ImageSaverParamE", !12, i64 0, !12, i64 8, !14, i64 16, !15, i64 20, !16, i64 24, !17, i64 28}
!12 = !{!"long", !13, i64 0}
!13 = !{!"omnipotent char", !7, i64 0}
!14 = !{!"_ZTS19SimdPixelFormatType", !13, i64 0}
!15 = !{!"_ZTS17SimdImageFileType", !13, i64 0}
!16 = !{!"int", !13, i64 0}
!17 = !{!"_ZTS11SimdYuvType", !13, i64 0}
!18 = !{!"_ZTSN4Simd18OutputMemoryStreamE", !12, i64 0, !19, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48}
!19 = !{!"any pointer", !13, i64 0}
!20 = !{!"_ZTSN4Simd5ArrayIhEE", !19, i64 0, !12, i64 8}
!21 = !{!"bool", !13, i64 0}
!22 = !{!9, !16, i64 164}
!23 = !{!9, !16, i64 160}
!24 = !{!10, !12, i64 16}
!25 = !{!10, !14, i64 24}
!26 = !{!9, !19, i64 112}
!27 = !{!10, !12, i64 8}
!28 = !{!9, !19, i64 120}
!29 = !{!9, !19, i64 128}
!30 = distinct !{!30, !31}
!31 = !{!"llvm.loop.mustprogress"}


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