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

; 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.DTPixel = type { i8, i8, i8 }
%struct.DTPalette = type { i32, ptr }
%struct.DTImage = type { i32, i32, i32, i64, ptr }

@opterr = external global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@optarg = external global ptr, align 8
@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [30 x i8], align 1
@optopt = external global i32, align 4
@optind = external global i32, align 4
@.str.2 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [10 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca %struct.DTPixel, align 1
  %20 = alloca i24, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store ptr null, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 1, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr @opterr, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %36, %2
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = load ptr, ptr %5, align 8, !tbaa !9
  %24 = call i32 @getopt(i32 noundef %22, ptr noundef %23, ptr noundef @.str) #5
  store i32 %24, ptr %11, align 4, !tbaa !5
  %25 = icmp ne i32 %24, -1
  br i1 %25, label %26, label %37

26:                                               ; preds = %21
  %27 = load i32, ptr %11, align 4, !tbaa !5
  switch i32 %27, label %36 [
    i32 112, label %28
    i32 118, label %30
    i32 100, label %31
    i32 63, label %32
  ]

28:                                               ; preds = %26
  %29 = load ptr, ptr @optarg, align 8, !tbaa !9
  store ptr %29, ptr %6, align 8, !tbaa !9
  br label %36

30:                                               ; preds = %26
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %36

31:                                               ; preds = %26
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %36

32:                                               ; preds = %26
  %33 = load ptr, ptr @stderr, align 8, !tbaa !9
  %34 = load i32, ptr @optopt, align 4, !tbaa !5
  %35 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef @.str.1, i32 noundef %34) #5
  br label %36

36:                                               ; preds = %32, %31, %30, %28, %26
  br label %21, !llvm.loop !11

37:                                               ; preds = %21
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = load i32, ptr @optind, align 4, !tbaa !5
  %40 = sub nsw i32 %38, %39
  %41 = icmp ne i32 %40, 2
  br i1 %41, label %42, label %48

42:                                               ; preds = %37
  %43 = load ptr, ptr @stderr, align 8, !tbaa !9
  %44 = load ptr, ptr %5, align 8, !tbaa !9
  %45 = getelementptr inbounds ptr, ptr %44, i64 0
  %46 = load ptr, ptr %45, align 8, !tbaa !9
  %47 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %43, ptr noundef @.str.2, ptr noundef %46) #5
  store i32 1, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %169

48:                                               ; preds = %37
  %49 = load ptr, ptr %5, align 8, !tbaa !9
  %50 = load i32, ptr @optind, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds ptr, ptr %49, i64 %51
  %53 = load ptr, ptr %52, align 8, !tbaa !9
  store ptr %53, ptr %7, align 8, !tbaa !9
  %54 = load ptr, ptr %5, align 8, !tbaa !9
  %55 = load i32, ptr @optind, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds ptr, ptr %54, i64 %57
  %59 = load ptr, ptr %58, align 8, !tbaa !9
  store ptr %59, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %60 = load ptr, ptr %7, align 8, !tbaa !9
  %61 = call ptr @CreateImageFromFile(ptr noundef %60)
  store ptr %61, ptr %13, align 8, !tbaa !9
  %62 = load ptr, ptr %13, align 8, !tbaa !9
  %63 = icmp eq ptr %62, null
  br i1 %63, label %64, label %65

64:                                               ; preds = %48
  store i32 2, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %168

65:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %66 = load ptr, ptr %6, align 8, !tbaa !9
  %67 = load ptr, ptr %13, align 8, !tbaa !9
  %68 = call ptr @PaletteForIdentifier(ptr noundef %66, ptr noundef %67)
  store ptr %68, ptr %14, align 8, !tbaa !9
  %69 = load ptr, ptr %14, align 8, !tbaa !9
  %70 = icmp eq ptr %69, null
  br i1 %70, label %71, label %72

71:                                               ; preds = %65
  store i32 3, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %167

72:                                               ; preds = %65
  %73 = load i32, ptr %9, align 4, !tbaa !5
  %74 = icmp ne i32 %73, 0
  br i1 %74, label %75, label %116

75:                                               ; preds = %72
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  store i32 0, ptr %15, align 4, !tbaa !5
  br label %76

76:                                               ; preds = %112, %75
  %77 = load i32, ptr %15, align 4, !tbaa !5
  %78 = load ptr, ptr %14, align 8, !tbaa !9
  %79 = getelementptr inbounds %struct.DTPalette, ptr %78, i32 0, i32 0
  %80 = load i32, ptr %79, align 8, !tbaa !13
  %81 = icmp slt i32 %77, %80
  br i1 %81, label %83, label %82

82:                                               ; preds = %76
  store i32 5, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  br label %115

83:                                               ; preds = %76
  %84 = load ptr, ptr %14, align 8, !tbaa !9
  %85 = getelementptr inbounds %struct.DTPalette, ptr %84, i32 0, i32 1
  %86 = load ptr, ptr %85, align 8, !tbaa !15
  %87 = load i32, ptr %15, align 4, !tbaa !5
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds %struct.DTPixel, ptr %86, i64 %88
  %90 = getelementptr inbounds %struct.DTPixel, ptr %89, i32 0, i32 0
  %91 = load i8, ptr %90, align 1, !tbaa !16
  %92 = zext i8 %91 to i32
  %93 = load ptr, ptr %14, align 8, !tbaa !9
  %94 = getelementptr inbounds %struct.DTPalette, ptr %93, i32 0, i32 1
  %95 = load ptr, ptr %94, align 8, !tbaa !15
  %96 = load i32, ptr %15, align 4, !tbaa !5
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds %struct.DTPixel, ptr %95, i64 %97
  %99 = getelementptr inbounds %struct.DTPixel, ptr %98, i32 0, i32 1
  %100 = load i8, ptr %99, align 1, !tbaa !18
  %101 = zext i8 %100 to i32
  %102 = load ptr, ptr %14, align 8, !tbaa !9
  %103 = getelementptr inbounds %struct.DTPalette, ptr %102, i32 0, i32 1
  %104 = load ptr, ptr %103, align 8, !tbaa !15
  %105 = load i32, ptr %15, align 4, !tbaa !5
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds %struct.DTPixel, ptr %104, i64 %106
  %108 = getelementptr inbounds %struct.DTPixel, ptr %107, i32 0, i32 2
  %109 = load i8, ptr %108, align 1, !tbaa !19
  %110 = zext i8 %109 to i32
  %111 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %92, i32 noundef %101, i32 noundef %110)
  br label %112

112:                                              ; preds = %83
  %113 = load i32, ptr %15, align 4, !tbaa !5
  %114 = add nsw i32 %113, 1
  store i32 %114, ptr %15, align 4, !tbaa !5
  br label %76, !llvm.loop !20

115:                                              ; preds = %82
  br label %116

116:                                              ; preds = %115, %72
  %117 = load i32, ptr %10, align 4, !tbaa !5
  %118 = icmp ne i32 %117, 0
  br i1 %118, label %119, label %122

119:                                              ; preds = %116
  %120 = load ptr, ptr %13, align 8, !tbaa !9
  %121 = load ptr, ptr %14, align 8, !tbaa !9
  call void @ApplyFloydSteinbergDither(ptr noundef %120, ptr noundef %121)
  br label %164

122:                                              ; preds = %116
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #5
  store i32 0, ptr %17, align 4, !tbaa !5
  br label %123

123:                                              ; preds = %160, %122
  %124 = load i32, ptr %17, align 4, !tbaa !5
  %125 = load ptr, ptr %13, align 8, !tbaa !9
  %126 = getelementptr inbounds %struct.DTImage, ptr %125, i32 0, i32 1
  %127 = load i32, ptr %126, align 4, !tbaa !21
  %128 = icmp slt i32 %124, %127
  br i1 %128, label %130, label %129

129:                                              ; preds = %123
  store i32 8, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #5
  br label %163

130:                                              ; preds = %123
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #5
  store i32 0, ptr %18, align 4, !tbaa !5
  br label %131

131:                                              ; preds = %156, %130
  %132 = load i32, ptr %18, align 4, !tbaa !5
  %133 = load ptr, ptr %13, align 8, !tbaa !9
  %134 = getelementptr inbounds %struct.DTImage, ptr %133, i32 0, i32 0
  %135 = load i32, ptr %134, align 8, !tbaa !24
  %136 = icmp slt i32 %132, %135
  br i1 %136, label %138, label %137

137:                                              ; preds = %131
  store i32 11, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #5
  br label %159

138:                                              ; preds = %131
  %139 = load ptr, ptr %13, align 8, !tbaa !9
  %140 = getelementptr inbounds %struct.DTImage, ptr %139, i32 0, i32 4
  %141 = load ptr, ptr %140, align 8, !tbaa !25
  %142 = load i32, ptr %17, align 4, !tbaa !5
  %143 = load ptr, ptr %13, align 8, !tbaa !9
  %144 = getelementptr inbounds %struct.DTImage, ptr %143, i32 0, i32 0
  %145 = load i32, ptr %144, align 8, !tbaa !24
  %146 = mul nsw i32 %142, %145
  %147 = load i32, ptr %18, align 4, !tbaa !5
  %148 = add nsw i32 %146, %147
  %149 = sext i32 %148 to i64
  %150 = getelementptr inbounds %struct.DTPixel, ptr %141, i64 %149
  store ptr %150, ptr %16, align 8, !tbaa !9
  %151 = load ptr, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 3, ptr %19) #5
  %152 = load ptr, ptr %16, align 8, !tbaa !9
  %153 = load ptr, ptr %14, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %20, ptr align 1 %152, i64 3, i1 false)
  %154 = load i24, ptr %20, align 4
  %155 = call i24 @FindClosestColorFromPalette(i24 %154, ptr noundef %153)
  store i24 %155, ptr %19, align 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %151, ptr align 1 %19, i64 3, i1 false), !tbaa.struct !26
  call void @llvm.lifetime.end.p0(i64 3, ptr %19) #5
  br label %156

156:                                              ; preds = %138
  %157 = load i32, ptr %18, align 4, !tbaa !5
  %158 = add nsw i32 %157, 1
  store i32 %158, ptr %18, align 4, !tbaa !5
  br label %131, !llvm.loop !28

159:                                              ; preds = %137
  br label %160

160:                                              ; preds = %159
  %161 = load i32, ptr %17, align 4, !tbaa !5
  %162 = add nsw i32 %161, 1
  store i32 %162, ptr %17, align 4, !tbaa !5
  br label %123, !llvm.loop !29

163:                                              ; preds = %129
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  br label %164

164:                                              ; preds = %163, %119
  %165 = load ptr, ptr %13, align 8, !tbaa !9
  %166 = load ptr, ptr %8, align 8, !tbaa !9
  call void @WriteImageToFile(ptr noundef %165, ptr noundef %166)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %167

167:                                              ; preds = %164, %71
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  br label %168

168:                                              ; preds = %167, %64
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  br label %169

169:                                              ; preds = %168, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, 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
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %170 = load i32, ptr %3, align 4
  ret i32 %170
}

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

; Function Attrs: nounwind
declare i32 @getopt(i32 noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

declare ptr @CreateImageFromFile(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local ptr @PaletteForIdentifier(ptr noundef, ptr noundef) #0

declare i32 @printf(ptr noundef, ...) #3

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

declare void @ApplyFloydSteinbergDither(ptr noundef, ptr noundef) #3

declare i24 @FindClosestColorFromPalette(i24, ptr noundef) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

declare void @WriteImageToFile(ptr noundef, ptr noundef) #3

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind "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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !6, i64 0}
!14 = !{!"", !6, i64 0, !10, i64 8}
!15 = !{!14, !10, i64 8}
!16 = !{!17, !7, i64 0}
!17 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!18 = !{!17, !7, i64 1}
!19 = !{!17, !7, i64 2}
!20 = distinct !{!20, !12}
!21 = !{!22, !6, i64 4}
!22 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !23, i64 16, !10, i64 24}
!23 = !{!"long", !7, i64 0}
!24 = !{!22, !6, i64 0}
!25 = !{!22, !10, i64 24}
!26 = !{i64 0, i64 1, !27, i64 1, i64 1, !27, i64 2, i64 1, !27}
!27 = !{!7, !7, i64 0}
!28 = distinct !{!28, !12}
!29 = distinct !{!29, !12}


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

@opterr = external local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@optarg = external local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [30 x i8], align 1
@optopt = external local_unnamed_addr global i32, align 4
@optind = external local_unnamed_addr global i32, align 4
@.str.2 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [10 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 4) i32 @main(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  store i32 0, ptr @opterr, align 4, !tbaa !5
  br label %.outer

.outer:                                           ; preds = %7, %2
  %.not56 = phi i1 [ true, %7 ], [ false, %2 ]
  %.045.ph = phi i32 [ %.045.ph67, %7 ], [ 0, %2 ]
  %.041.ph = phi ptr [ %.041.ph70, %7 ], [ null, %2 ]
  br label %.outer66

.outer66:                                         ; preds = %3, %.outer
  %.045.ph67 = phi i32 [ %.045.ph, %.outer ], [ 1, %3 ]
  %.041.ph68 = phi ptr [ %.041.ph, %.outer ], [ %.041.ph70, %3 ]
  br label %.outer69

.outer69:                                         ; preds = %.outer66, %5
  %.041.ph70 = phi ptr [ %.041.ph68, %.outer66 ], [ %6, %5 ]
  br label %3

3:                                                ; preds = %.backedge, %.outer69
  %4 = tail call i32 @getopt(i32 noundef %0, ptr noundef %1, ptr noundef nonnull @.str) #4
  switch i32 %4, label %.backedge [
    i32 -1, label %12
    i32 112, label %5
    i32 118, label %.outer66
    i32 100, label %7
    i32 63, label %8
  ], !llvm.loop !9

.backedge:                                        ; preds = %3, %8
  br label %3, !llvm.loop !9

5:                                                ; preds = %3
  %6 = load ptr, ptr @optarg, align 8, !tbaa !11
  br label %.outer69, !llvm.loop !9

7:                                                ; preds = %3
  br label %.outer, !llvm.loop !9

8:                                                ; preds = %3
  %9 = load ptr, ptr @stderr, align 8, !tbaa !11
  %10 = load i32, ptr @optopt, align 4, !tbaa !5
  %11 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %9, ptr noundef nonnull @.str.1, i32 noundef %10) #5
  br label %.backedge

12:                                               ; preds = %3
  %13 = load i32, ptr @optind, align 4, !tbaa !5
  %14 = sub nsw i32 %0, %13
  %.not54 = icmp eq i32 %14, 2
  br i1 %.not54, label %19, label %15

15:                                               ; preds = %12
  %16 = load ptr, ptr @stderr, align 8, !tbaa !11
  %17 = load ptr, ptr %1, align 8, !tbaa !11
  %18 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str.2, ptr noundef %17) #5
  br label %73

19:                                               ; preds = %12
  %20 = sext i32 %13 to i64
  %21 = getelementptr inbounds ptr, ptr %1, i64 %20
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = getelementptr i8, ptr %21, i64 8
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %25 = tail call ptr @CreateImageFromFile(ptr noundef %22) #4
  %26 = icmp eq ptr %25, null
  br i1 %26, label %73, label %27

27:                                               ; preds = %19
  %28 = tail call ptr @PaletteForIdentifier(ptr noundef %.041.ph70, ptr noundef nonnull %25)
  %29 = icmp eq ptr %28, null
  br i1 %29, label %73, label %30

30:                                               ; preds = %27
  %.not55 = icmp eq i32 %.045.ph67, 0
  br i1 %.not55, label %.loopexit59, label %.preheader58

.preheader58:                                     ; preds = %30
  %31 = load i32, ptr %28, align 8, !tbaa !13
  %32 = icmp sgt i32 %31, 0
  br i1 %32, label %.lr.ph, label %.loopexit59

.lr.ph:                                           ; preds = %.preheader58
  %33 = getelementptr inbounds i8, ptr %28, i64 8
  br label %34

34:                                               ; preds = %.lr.ph, %34
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %34 ]
  %35 = load ptr, ptr %33, align 8, !tbaa !15
  %36 = getelementptr inbounds %struct.DTPixel, ptr %35, i64 %indvars.iv
  %37 = load i8, ptr %36, align 1, !tbaa !16
  %38 = zext i8 %37 to i32
  %39 = getelementptr inbounds i8, ptr %36, i64 1
  %40 = load i8, ptr %39, align 1, !tbaa !18
  %41 = zext i8 %40 to i32
  %42 = getelementptr inbounds i8, ptr %36, i64 2
  %43 = load i8, ptr %42, align 1, !tbaa !19
  %44 = zext i8 %43 to i32
  %45 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %38, i32 noundef %41, i32 noundef %44)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %46 = load i32, ptr %28, align 8, !tbaa !13
  %47 = sext i32 %46 to i64
  %48 = icmp slt i64 %indvars.iv.next, %47
  br i1 %48, label %34, label %.loopexit59, !llvm.loop !20

.loopexit59:                                      ; preds = %34, %.preheader58, %30
  br i1 %.not56, label %.preheader57, label %55

.preheader57:                                     ; preds = %.loopexit59
  %49 = getelementptr inbounds i8, ptr %25, i64 4
  %50 = load i32, ptr %49, align 4, !tbaa !21
  %51 = icmp sgt i32 %50, 0
  br i1 %51, label %.preheader.lr.ph, label %.loopexit

.preheader.lr.ph:                                 ; preds = %.preheader57
  %52 = getelementptr inbounds i8, ptr %25, i64 24
  %53 = load i32, ptr %25, align 8, !tbaa !24
  %54 = icmp sgt i32 %53, 0
  br i1 %54, label %.preheader, label %.loopexit

55:                                               ; preds = %.loopexit59
  tail call void @ApplyFloydSteinbergDither(ptr noundef nonnull %25, ptr noundef nonnull %28) #4
  br label %.loopexit

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %56 = phi i32 [ %59, %._crit_edge ], [ %50, %.preheader.lr.ph ]
  %57 = phi i32 [ %60, %._crit_edge ], [ %53, %.preheader.lr.ph ]
  %.04463 = phi i32 [ %61, %._crit_edge ], [ 0, %.preheader.lr.ph ]
  %58 = icmp sgt i32 %57, 0
  br i1 %58, label %.lr.ph62, label %._crit_edge

._crit_edge.loopexit:                             ; preds = %.lr.ph62
  %.pre = load i32, ptr %49, align 4, !tbaa !21
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %59 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %56, %.preheader ]
  %60 = phi i32 [ %71, %._crit_edge.loopexit ], [ %57, %.preheader ]
  %61 = add nuw nsw i32 %.04463, 1
  %62 = icmp slt i32 %61, %59
  br i1 %62, label %.preheader, label %.loopexit, !llvm.loop !25

.lr.ph62:                                         ; preds = %.preheader, %.lr.ph62
  %63 = phi i32 [ %71, %.lr.ph62 ], [ %57, %.preheader ]
  %.04361 = phi i32 [ %70, %.lr.ph62 ], [ 0, %.preheader ]
  %64 = load ptr, ptr %52, align 8, !tbaa !27
  %65 = mul nsw i32 %63, %.04463
  %66 = add nsw i32 %65, %.04361
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds %struct.DTPixel, ptr %64, i64 %67
  %.0.copyload = load i24, ptr %68, align 1
  %69 = tail call i24 @FindClosestColorFromPalette(i24 %.0.copyload, ptr noundef nonnull %28) #4
  store i24 %69, ptr %68, align 1
  %70 = add nuw nsw i32 %.04361, 1
  %71 = load i32, ptr %25, align 8, !tbaa !24
  %72 = icmp slt i32 %70, %71
  br i1 %72, label %.lr.ph62, label %._crit_edge.loopexit, !llvm.loop !28

.loopexit:                                        ; preds = %._crit_edge, %.preheader.lr.ph, %.preheader57, %55
  tail call void @WriteImageToFile(ptr noundef nonnull %25, ptr noundef %24) #4
  br label %73

73:                                               ; preds = %19, %27, %.loopexit, %15
  %.2 = phi i32 [ 1, %15 ], [ 2, %19 ], [ 0, %.loopexit ], [ 3, %27 ]
  ret i32 %.2
}

; Function Attrs: nounwind
declare i32 @getopt(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

declare ptr @CreateImageFromFile(ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local ptr @PaletteForIdentifier(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

declare void @ApplyFloydSteinbergDither(ptr noundef, ptr noundef) local_unnamed_addr #3

declare i24 @FindClosestColorFromPalette(i24, ptr noundef) local_unnamed_addr #3

declare void @WriteImageToFile(ptr noundef, ptr noundef) local_unnamed_addr #3

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { 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 = { 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 #3 = { "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 }
attributes #5 = { cold 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"", !6, i64 0, !12, i64 8}
!15 = !{!14, !12, i64 8}
!16 = !{!17, !7, i64 0}
!17 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!18 = !{!17, !7, i64 1}
!19 = !{!17, !7, i64 2}
!20 = distinct !{!20, !10}
!21 = !{!22, !6, i64 4}
!22 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !23, i64 16, !12, i64 24}
!23 = !{!"long", !7, i64 0}
!24 = !{!22, !6, i64 0}
!25 = distinct !{!25, !10, !26}
!26 = !{!"llvm.loop.unswitch.partial.disable"}
!27 = !{!22, !12, i64 24}
!28 = distinct !{!28, !10}


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