; LLVM IR from tessarin/dither :: src (DTImage)

; 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.DTImage = type { i32, i32, i32, i64, ptr }
%struct.DTPixel = type { i8, i8, i8 }
%struct.__jmp_buf_tag = type { [8 x i64], i32, %struct.__sigset_t }
%struct.__sigset_t = type { [16 x i64] }

@.str.8 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [12 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

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @ReadDataFromFile(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i8, align 1
  %11 = alloca i8, align 1
  %12 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.DTImage, ptr %13, i32 0, i32 2
  %15 = load i32, ptr %14, align 8, !tbaa !9
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %70

17:                                               ; preds = %2
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = call i32 @fseek(ptr noundef %18, i64 noundef 2, i32 noundef 0)
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.DTImage, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.DTImage, ptr %23, i32 0, i32 1
  %25 = call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef %20, ptr noundef @.str.10, ptr noundef %22, ptr noundef %24)
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.DTImage, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 8, !tbaa !13
  %29 = sext i32 %28 to i64
  %30 = mul i64 3, %29
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.DTImage, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 4, !tbaa !14
  %34 = sext i32 %33 to i64
  %35 = mul i64 %30, %34
  %36 = call noalias ptr @malloc(i64 noundef %35) #7
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.DTImage, ptr %37, i32 0, i32 4
  store ptr %36, ptr %38, align 8, !tbaa !15
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.DTImage, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !13
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.DTImage, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %43, align 4, !tbaa !14
  %45 = mul nsw i32 %41, %44
  %46 = sext i32 %45 to i64
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.DTImage, ptr %47, i32 0, i32 3
  store i64 %46, ptr %48, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #8
  store i32 0, ptr %6, align 4, !tbaa !17
  br label %49

49:                                               ; preds = %66, %17
  %50 = load i32, ptr %6, align 4, !tbaa !17
  %51 = sext i32 %50 to i64
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.DTImage, ptr %52, i32 0, i32 3
  %54 = load i64, ptr %53, align 8, !tbaa !16
  %55 = icmp ult i64 %51, %54
  br i1 %55, label %57, label %56

56:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #8
  br label %69

57:                                               ; preds = %49
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.DTImage, ptr %58, i32 0, i32 4
  %60 = load ptr, ptr %59, align 8, !tbaa !15
  %61 = load i32, ptr %6, align 4, !tbaa !17
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds %struct.DTPixel, ptr %60, i64 %62
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = call i64 @fread(ptr noundef %63, i64 noundef 3, i64 noundef 1, ptr noundef %64)
  br label %66

66:                                               ; preds = %57
  %67 = load i32, ptr %6, align 4, !tbaa !17
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %6, align 4, !tbaa !17
  br label %49, !llvm.loop !18

69:                                               ; preds = %56
  br label %70

70:                                               ; preds = %69, %2
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.DTImage, ptr %71, i32 0, i32 2
  %73 = load i32, ptr %72, align 8, !tbaa !9
  %74 = icmp eq i32 %73, 1
  br i1 %74, label %75, label %209

75:                                               ; preds = %70
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #8
  %76 = call noalias ptr @png_create_read_struct(ptr noundef @.str.8, ptr noundef null, ptr noundef null, ptr noundef null)
  store ptr %76, ptr %7, align 8, !tbaa !5
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = icmp ne ptr %77, null
  br i1 %78, label %80, label %79

79:                                               ; preds = %75
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %206

80:                                               ; preds = %75
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #8
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  %82 = call noalias ptr @png_create_info_struct(ptr noundef %81)
  store ptr %82, ptr %9, align 8, !tbaa !5
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  %84 = icmp ne ptr %83, null
  br i1 %84, label %86, label %85

85:                                               ; preds = %80
  store i32 2, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %205

86:                                               ; preds = %80
  %87 = load ptr, ptr %7, align 8, !tbaa !5
  %88 = call ptr @png_set_longjmp_fn(ptr noundef %87, ptr noundef @longjmp, i64 noundef 200)
  %89 = getelementptr inbounds [1 x %struct.__jmp_buf_tag], ptr %88, i64 0, i64 0
  %90 = call i32 @_setjmp(ptr noundef %89) #9
  %91 = icmp ne i32 %90, 0
  br i1 %91, label %92, label %93

92:                                               ; preds = %86
  store i32 3, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %205

93:                                               ; preds = %86
  %94 = load ptr, ptr %7, align 8, !tbaa !5
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  call void @png_init_io(ptr noundef %94, ptr noundef %95)
  %96 = load ptr, ptr %7, align 8, !tbaa !5
  call void @png_set_sig_bytes(ptr noundef %96, i32 noundef 8)
  %97 = load ptr, ptr %7, align 8, !tbaa !5
  %98 = load ptr, ptr %9, align 8, !tbaa !5
  call void @png_read_info(ptr noundef %97, ptr noundef %98)
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #8
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #8
  %99 = load ptr, ptr %7, align 8, !tbaa !5
  %100 = load ptr, ptr %9, align 8, !tbaa !5
  %101 = call i32 @png_get_image_width(ptr noundef %99, ptr noundef %100)
  %102 = load ptr, ptr %4, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.DTImage, ptr %102, i32 0, i32 0
  store i32 %101, ptr %103, align 8, !tbaa !13
  %104 = load ptr, ptr %7, align 8, !tbaa !5
  %105 = load ptr, ptr %9, align 8, !tbaa !5
  %106 = call i32 @png_get_image_height(ptr noundef %104, ptr noundef %105)
  %107 = load ptr, ptr %4, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.DTImage, ptr %107, i32 0, i32 1
  store i32 %106, ptr %108, align 4, !tbaa !14
  %109 = load ptr, ptr %7, align 8, !tbaa !5
  %110 = load ptr, ptr %9, align 8, !tbaa !5
  %111 = call zeroext i8 @png_get_color_type(ptr noundef %109, ptr noundef %110)
  store i8 %111, ptr %10, align 1, !tbaa !20
  %112 = load ptr, ptr %7, align 8, !tbaa !5
  %113 = load ptr, ptr %9, align 8, !tbaa !5
  %114 = call zeroext i8 @png_get_bit_depth(ptr noundef %112, ptr noundef %113)
  store i8 %114, ptr %11, align 1, !tbaa !20
  %115 = load ptr, ptr %4, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.DTImage, ptr %115, i32 0, i32 0
  %117 = load i32, ptr %116, align 8, !tbaa !13
  %118 = load ptr, ptr %4, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.DTImage, ptr %118, i32 0, i32 1
  %120 = load i32, ptr %119, align 4, !tbaa !14
  %121 = mul nsw i32 %117, %120
  %122 = sext i32 %121 to i64
  %123 = load ptr, ptr %4, align 8, !tbaa !5
  %124 = getelementptr inbounds %struct.DTImage, ptr %123, i32 0, i32 3
  store i64 %122, ptr %124, align 8, !tbaa !16
  %125 = load i8, ptr %11, align 1, !tbaa !20
  %126 = zext i8 %125 to i32
  %127 = icmp eq i32 %126, 16
  br i1 %127, label %128, label %130

128:                                              ; preds = %93
  %129 = load ptr, ptr %7, align 8, !tbaa !5
  call void @png_set_strip_16(ptr noundef %129)
  br label %130

130:                                              ; preds = %128, %93
  %131 = load i8, ptr %10, align 1, !tbaa !20
  %132 = zext i8 %131 to i32
  %133 = icmp eq i32 %132, 3
  br i1 %133, label %134, label %136

134:                                              ; preds = %130
  %135 = load ptr, ptr %7, align 8, !tbaa !5
  call void @png_set_palette_to_rgb(ptr noundef %135)
  br label %136

136:                                              ; preds = %134, %130
  %137 = load i8, ptr %10, align 1, !tbaa !20
  %138 = zext i8 %137 to i32
  %139 = icmp eq i32 %138, 0
  br i1 %139, label %140, label %146

140:                                              ; preds = %136
  %141 = load i8, ptr %11, align 1, !tbaa !20
  %142 = zext i8 %141 to i32
  %143 = icmp slt i32 %142, 8
  br i1 %143, label %144, label %146

144:                                              ; preds = %140
  %145 = load ptr, ptr %7, align 8, !tbaa !5
  call void @png_set_expand_gray_1_2_4_to_8(ptr noundef %145)
  br label %146

146:                                              ; preds = %144, %140, %136
  %147 = load ptr, ptr %7, align 8, !tbaa !5
  %148 = load ptr, ptr %9, align 8, !tbaa !5
  %149 = call i32 @png_get_valid(ptr noundef %147, ptr noundef %148, i32 noundef 16)
  %150 = icmp ne i32 %149, 0
  br i1 %150, label %151, label %153

151:                                              ; preds = %146
  %152 = load ptr, ptr %7, align 8, !tbaa !5
  call void @png_set_tRNS_to_alpha(ptr noundef %152)
  br label %153

153:                                              ; preds = %151, %146
  %154 = load i8, ptr %10, align 1, !tbaa !20
  %155 = zext i8 %154 to i32
  %156 = and i32 %155, 4
  %157 = icmp ne i32 %156, 0
  br i1 %157, label %158, label %160

158:                                              ; preds = %153
  %159 = load ptr, ptr %7, align 8, !tbaa !5
  call void @png_set_strip_alpha(ptr noundef %159)
  br label %160

160:                                              ; preds = %158, %153
  %161 = load i8, ptr %10, align 1, !tbaa !20
  %162 = zext i8 %161 to i32
  %163 = icmp eq i32 %162, 0
  br i1 %163, label %168, label %164

164:                                              ; preds = %160
  %165 = load i8, ptr %10, align 1, !tbaa !20
  %166 = zext i8 %165 to i32
  %167 = icmp eq i32 %166, 4
  br i1 %167, label %168, label %170

168:                                              ; preds = %164, %160
  %169 = load ptr, ptr %7, align 8, !tbaa !5
  call void @png_set_gray_to_rgb(ptr noundef %169)
  br label %170

170:                                              ; preds = %168, %164
  %171 = load ptr, ptr %7, align 8, !tbaa !5
  %172 = load ptr, ptr %9, align 8, !tbaa !5
  call void @png_read_update_info(ptr noundef %171, ptr noundef %172)
  %173 = load ptr, ptr %4, align 8, !tbaa !5
  %174 = getelementptr inbounds %struct.DTImage, ptr %173, i32 0, i32 0
  %175 = load i32, ptr %174, align 8, !tbaa !13
  %176 = sext i32 %175 to i64
  %177 = mul i64 3, %176
  %178 = load ptr, ptr %4, align 8, !tbaa !5
  %179 = getelementptr inbounds %struct.DTImage, ptr %178, i32 0, i32 1
  %180 = load i32, ptr %179, align 4, !tbaa !14
  %181 = sext i32 %180 to i64
  %182 = mul i64 %177, %181
  %183 = call noalias ptr @malloc(i64 noundef %182) #7
  %184 = load ptr, ptr %4, align 8, !tbaa !5
  %185 = getelementptr inbounds %struct.DTImage, ptr %184, i32 0, i32 4
  store ptr %183, ptr %185, align 8, !tbaa !15
  %186 = load ptr, ptr %7, align 8, !tbaa !5
  %187 = load ptr, ptr %9, align 8, !tbaa !5
  %188 = call i64 @png_get_rowbytes(ptr noundef %186, ptr noundef %187)
  %189 = load ptr, ptr %4, align 8, !tbaa !5
  %190 = getelementptr inbounds %struct.DTImage, ptr %189, i32 0, i32 0
  %191 = load i32, ptr %190, align 8, !tbaa !13
  %192 = sext i32 %191 to i64
  %193 = mul i64 %192, 3
  %194 = icmp ne i64 %188, %193
  br i1 %194, label %195, label %196

195:                                              ; preds = %170
  store i32 4, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %204

196:                                              ; preds = %170
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #8
  %197 = load ptr, ptr %4, align 8, !tbaa !5
  %198 = call ptr @PNGRowPointersForImage(ptr noundef %197)
  store ptr %198, ptr %12, align 8, !tbaa !5
  %199 = load ptr, ptr %7, align 8, !tbaa !5
  %200 = load ptr, ptr %12, align 8, !tbaa !5
  call void @png_read_image(ptr noundef %199, ptr noundef %200)
  %201 = load ptr, ptr %7, align 8, !tbaa !5
  %202 = load ptr, ptr %9, align 8, !tbaa !5
  call void @png_read_end(ptr noundef %201, ptr noundef %202)
  call void @png_destroy_read_struct(ptr noundef %7, ptr noundef %9, ptr noundef null)
  %203 = load ptr, ptr %12, align 8, !tbaa !5
  call void @free(ptr noundef %203) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #8
  store i32 0, ptr %8, align 4
  br label %204

204:                                              ; preds = %196, %195
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #8
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #8
  br label %205

205:                                              ; preds = %204, %92, %85
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #8
  br label %206

206:                                              ; preds = %205, %79
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #8
  %207 = load i32, ptr %8, align 4
  switch i32 %207, label %212 [
    i32 0, label %208
    i32 1, label %210
  ]

208:                                              ; preds = %206
  br label %209

209:                                              ; preds = %208, %70
  store i32 0, ptr %3, align 4
  br label %210

210:                                              ; preds = %209, %206
  %211 = load i32, ptr %3, align 4
  ret i32 %211

212:                                              ; preds = %206
  unreachable
}

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

declare noalias ptr @png_create_info_struct(ptr noundef) #1

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

declare ptr @png_set_longjmp_fn(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: noreturn nounwind
declare void @longjmp(ptr noundef, i32 noundef) #5

declare void @png_init_io(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @PNGRowPointersForImage(ptr noundef) #3

; Function Attrs: nounwind
declare void @free(ptr noundef) #6

declare i32 @fseek(ptr noundef, i64 noundef, i32 noundef) #1

declare i32 @__isoc99_fscanf(ptr noundef, ptr noundef, ...) #1

declare noalias ptr @png_create_read_struct(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

declare void @png_set_sig_bytes(ptr noundef, i32 noundef) #1

declare void @png_read_info(ptr noundef, ptr noundef) #1

declare i32 @png_get_image_width(ptr noundef, ptr noundef) #1

declare i32 @png_get_image_height(ptr noundef, ptr noundef) #1

declare zeroext i8 @png_get_color_type(ptr noundef, ptr noundef) #1

declare zeroext i8 @png_get_bit_depth(ptr noundef, ptr noundef) #1

declare void @png_set_strip_16(ptr noundef) #1

declare void @png_set_palette_to_rgb(ptr noundef) #1

declare void @png_set_expand_gray_1_2_4_to_8(ptr noundef) #1

declare i32 @png_get_valid(ptr noundef, ptr noundef, i32 noundef) #1

declare void @png_set_tRNS_to_alpha(ptr noundef) #1

declare void @png_set_strip_alpha(ptr noundef) #1

declare void @png_set_gray_to_rgb(ptr noundef) #1

declare void @png_read_update_info(ptr noundef, ptr noundef) #1

declare i64 @png_get_rowbytes(ptr noundef, ptr noundef) #1

declare void @png_read_image(ptr noundef, ptr noundef) #1

declare void @png_read_end(ptr noundef, ptr noundef) #1

declare void @png_destroy_read_struct(ptr noundef, ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 allocsize(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 = { 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 = { 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 #5 = { 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 #6 = { 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 #7 = { nounwind allocsize(0) }
attributes #8 = { nounwind }
attributes #9 = { 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, !11, i64 8}
!10 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !12, i64 16, !6, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !11, i64 0}
!14 = !{!10, !11, i64 4}
!15 = !{!10, !6, i64 24}
!16 = !{!10, !12, i64 16}
!17 = !{!11, !11, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!7, !7, i64 0}


; 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.DTPixel = type { i8, i8, i8 }

@.str.8 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [12 x i8], align 1

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

; Function Attrs: nofree nounwind
declare noundef i64 @fread(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 5) i32 @ReadDataFromFile(ptr noundef %0, ptr noundef %1) local_unnamed_addr #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %8, label %28

8:                                                ; preds = %2
  %9 = call i32 @fseek(ptr noundef %1, i64 noundef 2, i32 noundef 0)
  %10 = getelementptr inbounds i8, ptr %0, i64 4
  %11 = call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef %1, ptr noundef nonnull @.str.10, ptr noundef nonnull %0, ptr noundef nonnull %10) #8
  %12 = load i32, ptr %0, align 8, !tbaa !12
  %13 = sext i32 %12 to i64
  %14 = mul nsw i64 %13, 3
  %15 = load i32, ptr %10, align 4, !tbaa !13
  %16 = sext i32 %15 to i64
  %17 = mul i64 %14, %16
  %18 = call noalias ptr @malloc(i64 noundef %17) #9
  %19 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %18, ptr %19, align 8, !tbaa !14
  %20 = mul nsw i32 %15, %12
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %21, ptr %22, align 8, !tbaa !15
  %.not63 = icmp eq i32 %20, 0
  br i1 %.not63, label %thread-pre-split, label %.lr.ph

.lr.ph:                                           ; preds = %8, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %8 ]
  %23 = load ptr, ptr %19, align 8, !tbaa !14
  %24 = getelementptr inbounds %struct.DTPixel, ptr %23, i64 %indvars.iv
  %25 = call i64 @fread(ptr noundef %24, i64 noundef 3, i64 noundef 1, ptr noundef %1)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %26 = load i64, ptr %22, align 8, !tbaa !15
  %27 = icmp ugt i64 %26, %indvars.iv.next
  br i1 %27, label %.lr.ph, label %thread-pre-split, !llvm.loop !16

thread-pre-split:                                 ; preds = %.lr.ph, %8
  %.pr = load i32, ptr %5, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %thread-pre-split, %2
  %29 = phi i32 [ %.pr, %thread-pre-split ], [ %6, %2 ]
  %30 = icmp eq i32 %29, 1
  br i1 %30, label %31, label %80

31:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #8
  %32 = call noalias ptr @png_create_read_struct(ptr noundef nonnull @.str.8, ptr noundef null, ptr noundef null, ptr noundef null) #8
  store ptr %32, ptr %3, align 8, !tbaa !18
  %.not = icmp eq ptr %32, null
  br i1 %.not, label %.thread54, label %33

.thread54:                                        ; preds = %31
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #8
  br label %80

33:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #8
  %34 = call noalias ptr @png_create_info_struct(ptr noundef nonnull %32) #8
  store ptr %34, ptr %4, align 8, !tbaa !18
  %.not48 = icmp eq ptr %34, null
  br i1 %.not48, label %.thread58, label %35

35:                                               ; preds = %33
  %36 = call ptr @png_set_longjmp_fn(ptr noundef nonnull %32, ptr noundef nonnull @longjmp, i64 noundef 200) #8
  %37 = call i32 @_setjmp(ptr noundef %36) #10
  %.not49 = icmp eq i32 %37, 0
  br i1 %.not49, label %38, label %.thread58

38:                                               ; preds = %35
  call void @png_init_io(ptr noundef nonnull %32, ptr noundef %1) #8
  call void @png_set_sig_bytes(ptr noundef nonnull %32, i32 noundef 8) #8
  call void @png_read_info(ptr noundef nonnull %32, ptr noundef nonnull %34) #8
  %39 = call i32 @png_get_image_width(ptr noundef nonnull %32, ptr noundef nonnull %34) #8
  store i32 %39, ptr %0, align 8, !tbaa !12
  %40 = call i32 @png_get_image_height(ptr noundef nonnull %32, ptr noundef nonnull %34) #8
  %41 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %40, ptr %41, align 4, !tbaa !13
  %42 = call zeroext i8 @png_get_color_type(ptr noundef nonnull %32, ptr noundef nonnull %34) #8
  %43 = call zeroext i8 @png_get_bit_depth(ptr noundef nonnull %32, ptr noundef nonnull %34) #8
  %44 = load i32, ptr %0, align 8, !tbaa !12
  %45 = load i32, ptr %41, align 4, !tbaa !13
  %46 = mul nsw i32 %45, %44
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %47, ptr %48, align 8, !tbaa !15
  %49 = icmp eq i8 %43, 16
  br i1 %49, label %50, label %51

50:                                               ; preds = %38
  call void @png_set_strip_16(ptr noundef nonnull %32) #8
  br label %51

51:                                               ; preds = %50, %38
  %52 = icmp eq i8 %42, 3
  br i1 %52, label %.thread, label %53

.thread:                                          ; preds = %51
  call void @png_set_palette_to_rgb(ptr noundef nonnull %32) #8
  br label %57

53:                                               ; preds = %51
  %54 = icmp eq i8 %42, 0
  %55 = icmp ult i8 %43, 8
  %or.cond = and i1 %54, %55
  br i1 %or.cond, label %56, label %57

56:                                               ; preds = %53
  call void @png_set_expand_gray_1_2_4_to_8(ptr noundef nonnull %32) #8
  br label %57

57:                                               ; preds = %.thread, %56, %53
  %58 = call i32 @png_get_valid(ptr noundef nonnull %32, ptr noundef nonnull %34, i32 noundef 16) #8
  %.not50 = icmp eq i32 %58, 0
  br i1 %.not50, label %60, label %59

59:                                               ; preds = %57
  call void @png_set_tRNS_to_alpha(ptr noundef nonnull %32) #8
  br label %60

60:                                               ; preds = %59, %57
  %61 = and i8 %42, 4
  %.not51 = icmp eq i8 %61, 0
  br i1 %.not51, label %63, label %62

62:                                               ; preds = %60
  call void @png_set_strip_alpha(ptr noundef nonnull %32) #8
  br label %63

63:                                               ; preds = %62, %60
  switch i8 %42, label %65 [
    i8 4, label %64
    i8 0, label %64
  ]

64:                                               ; preds = %63, %63
  call void @png_set_gray_to_rgb(ptr noundef nonnull %32) #8
  br label %65

65:                                               ; preds = %63, %64
  call void @png_read_update_info(ptr noundef nonnull %32, ptr noundef nonnull %34) #8
  %66 = load i32, ptr %0, align 8, !tbaa !12
  %67 = sext i32 %66 to i64
  %68 = mul nsw i64 %67, 3
  %69 = load i32, ptr %41, align 4, !tbaa !13
  %70 = sext i32 %69 to i64
  %71 = mul i64 %68, %70
  %72 = call noalias ptr @malloc(i64 noundef %71) #9
  %73 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %72, ptr %73, align 8, !tbaa !14
  %74 = call i64 @png_get_rowbytes(ptr noundef nonnull %32, ptr noundef nonnull %34) #8
  %75 = load i32, ptr %0, align 8, !tbaa !12
  %76 = sext i32 %75 to i64
  %77 = mul nsw i64 %76, 3
  %.not52 = icmp eq i64 %74, %77
  br i1 %.not52, label %78, label %.thread58

.thread58:                                        ; preds = %33, %35, %65
  %.1.ph = phi i32 [ 4, %65 ], [ 3, %35 ], [ 2, %33 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #8
  br label %80

78:                                               ; preds = %65
  %79 = call ptr @PNGRowPointersForImage(ptr noundef nonnull %0)
  call void @png_read_image(ptr noundef nonnull %32, ptr noundef %79) #8
  call void @png_read_end(ptr noundef nonnull %32, ptr noundef nonnull %34) #8
  call void @png_destroy_read_struct(ptr noundef nonnull %3, ptr noundef nonnull %4, ptr noundef null) #8
  call void @free(ptr noundef %79) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #8
  br label %80

80:                                               ; preds = %28, %78, %.thread58, %.thread54
  %.3 = phi i32 [ 1, %.thread54 ], [ %.1.ph, %.thread58 ], [ 0, %78 ], [ 0, %28 ]
  ret i32 %.3
}

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

declare noalias ptr @png_create_info_struct(ptr noundef) local_unnamed_addr #4

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

declare ptr @png_set_longjmp_fn(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #4

; Function Attrs: noreturn nounwind
declare void @longjmp(ptr noundef, i32 noundef) #6

declare void @png_init_io(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare dso_local ptr @PNGRowPointersForImage(ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #7

; Function Attrs: nofree nounwind
declare noundef i32 @fseek(ptr nocapture noundef, i64 noundef, i32 noundef) local_unnamed_addr #1

declare i32 @__isoc99_fscanf(ptr noundef, ptr noundef, ...) local_unnamed_addr #4

declare noalias ptr @png_create_read_struct(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

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

declare void @png_read_info(ptr noundef, ptr noundef) local_unnamed_addr #4

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

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

declare zeroext i8 @png_get_color_type(ptr noundef, ptr noundef) local_unnamed_addr #4

declare zeroext i8 @png_get_bit_depth(ptr noundef, ptr noundef) local_unnamed_addr #4

declare void @png_set_strip_16(ptr noundef) local_unnamed_addr #4

declare void @png_set_palette_to_rgb(ptr noundef) local_unnamed_addr #4

declare void @png_set_expand_gray_1_2_4_to_8(ptr noundef) local_unnamed_addr #4

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

declare void @png_set_tRNS_to_alpha(ptr noundef) local_unnamed_addr #4

declare void @png_set_strip_alpha(ptr noundef) local_unnamed_addr #4

declare void @png_set_gray_to_rgb(ptr noundef) local_unnamed_addr #4

declare void @png_read_update_info(ptr noundef, ptr noundef) local_unnamed_addr #4

declare i64 @png_get_rowbytes(ptr noundef, ptr noundef) local_unnamed_addr #4

declare void @png_read_image(ptr noundef, ptr noundef) local_unnamed_addr #4

declare void @png_read_end(ptr noundef, ptr noundef) local_unnamed_addr #4

declare void @png_destroy_read_struct(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree 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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 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 #6 = { 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 #7 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #8 = { nounwind }
attributes #9 = { nounwind allocsize(0) }
attributes #10 = { 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, !7, i64 8}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !11, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !7, i64 4}
!14 = !{!6, !11, i64 24}
!15 = !{!6, !10, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!11, !11, i64 0}


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