; LLVM IR from haytham-hammioui/CS50x-2024 :: Week 4 Memory/Problem set 4/filter-less (filter)

; 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.BITMAPFILEHEADER = type <{ i16, i32, i16, i16, i32 }>
%struct.BITMAPINFOHEADER = type { i32, i32, i32, i16, i16, i32, i32, i32, i32, i32, i32 }
%struct.RGBTRIPLE = type { i8, i8, i8 }

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [26 x i8], align 1
@optind = external global i32, align 4
@.str.3 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [35 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 i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca %struct.BITMAPFILEHEADER, align 1
  %14 = alloca %struct.BITMAPINFOHEADER, align 1
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca ptr, align 8
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca i32, 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) #6
  store ptr @.str, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #6
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = load ptr, ptr %5, align 8, !tbaa !9
  %24 = load ptr, ptr %6, align 8, !tbaa !9
  %25 = call i32 @getopt(i32 noundef %22, ptr noundef %23, ptr noundef %24) #6
  %26 = trunc i32 %25 to i8
  store i8 %26, ptr %7, align 1, !tbaa !11
  %27 = load i8, ptr %7, align 1, !tbaa !11
  %28 = sext i8 %27 to i32
  %29 = icmp eq i32 %28, 63
  br i1 %29, label %30, label %32

30:                                               ; preds = %2
  %31 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %224

32:                                               ; preds = %2
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = load ptr, ptr %5, align 8, !tbaa !9
  %35 = load ptr, ptr %6, align 8, !tbaa !9
  %36 = call i32 @getopt(i32 noundef %33, ptr noundef %34, ptr noundef %35) #6
  %37 = icmp ne i32 %36, -1
  br i1 %37, label %38, label %40

38:                                               ; preds = %32
  %39 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  store i32 2, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %224

40:                                               ; preds = %32
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = load i32, ptr @optind, align 4, !tbaa !5
  %43 = add nsw i32 %42, 2
  %44 = icmp ne i32 %41, %43
  br i1 %44, label %45, label %47

45:                                               ; preds = %40
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  store i32 3, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %224

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

63:                                               ; preds = %47
  %64 = load ptr, ptr %9, align 8, !tbaa !9
  %65 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, ptr noundef %64)
  store i32 4, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %223

66:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  %67 = load ptr, ptr %10, align 8, !tbaa !9
  %68 = call noalias ptr @fopen(ptr noundef %67, ptr noundef @.str.6)
  store ptr %68, ptr %12, align 8, !tbaa !9
  %69 = load ptr, ptr %12, align 8, !tbaa !9
  %70 = icmp eq ptr %69, null
  br i1 %70, label %71, label %76

71:                                               ; preds = %66
  %72 = load ptr, ptr %11, align 8, !tbaa !9
  %73 = call i32 @fclose(ptr noundef %72)
  %74 = load ptr, ptr %10, align 8, !tbaa !9
  %75 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, ptr noundef %74)
  store i32 5, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %222

76:                                               ; preds = %66
  call void @llvm.lifetime.start.p0(i64 14, ptr %13) #6
  %77 = load ptr, ptr %11, align 8, !tbaa !9
  %78 = call i64 @fread(ptr noundef %13, i64 noundef 14, i64 noundef 1, ptr noundef %77)
  call void @llvm.lifetime.start.p0(i64 40, ptr %14) #6
  %79 = load ptr, ptr %11, align 8, !tbaa !9
  %80 = call i64 @fread(ptr noundef %14, i64 noundef 40, i64 noundef 1, ptr noundef %79)
  %81 = getelementptr inbounds %struct.BITMAPFILEHEADER, ptr %13, i32 0, i32 0
  %82 = load i16, ptr %81, align 1, !tbaa !12
  %83 = zext i16 %82 to i32
  %84 = icmp ne i32 %83, 19778
  br i1 %84, label %102, label %85

85:                                               ; preds = %76
  %86 = getelementptr inbounds %struct.BITMAPFILEHEADER, ptr %13, i32 0, i32 4
  %87 = load i32, ptr %86, align 1, !tbaa !15
  %88 = icmp ne i32 %87, 54
  br i1 %88, label %102, label %89

89:                                               ; preds = %85
  %90 = getelementptr inbounds %struct.BITMAPINFOHEADER, ptr %14, i32 0, i32 0
  %91 = load i32, ptr %90, align 1, !tbaa !16
  %92 = icmp ne i32 %91, 40
  br i1 %92, label %102, label %93

93:                                               ; preds = %89
  %94 = getelementptr inbounds %struct.BITMAPINFOHEADER, ptr %14, i32 0, i32 4
  %95 = load i16, ptr %94, align 1, !tbaa !18
  %96 = zext i16 %95 to i32
  %97 = icmp ne i32 %96, 24
  br i1 %97, label %102, label %98

98:                                               ; preds = %93
  %99 = getelementptr inbounds %struct.BITMAPINFOHEADER, ptr %14, i32 0, i32 5
  %100 = load i32, ptr %99, align 1, !tbaa !19
  %101 = icmp ne i32 %100, 0
  br i1 %101, label %102, label %108

102:                                              ; preds = %98, %93, %89, %85, %76
  %103 = load ptr, ptr %12, align 8, !tbaa !9
  %104 = call i32 @fclose(ptr noundef %103)
  %105 = load ptr, ptr %11, align 8, !tbaa !9
  %106 = call i32 @fclose(ptr noundef %105)
  %107 = call i32 (ptr, ...) @printf(ptr noundef @.str.8)
  store i32 6, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %221

108:                                              ; preds = %98
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #6
  %109 = getelementptr inbounds %struct.BITMAPINFOHEADER, ptr %14, i32 0, i32 2
  %110 = load i32, ptr %109, align 1, !tbaa !20
  %111 = call i32 @llvm.abs.i32(i32 %110, i1 true)
  store i32 %111, ptr %15, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #6
  %112 = getelementptr inbounds %struct.BITMAPINFOHEADER, ptr %14, i32 0, i32 1
  %113 = load i32, ptr %112, align 1, !tbaa !21
  store i32 %113, ptr %16, align 4, !tbaa !5
  %114 = load i32, ptr %16, align 4, !tbaa !5
  %115 = zext i32 %114 to i64
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #6
  %116 = load i32, ptr %15, align 4, !tbaa !5
  %117 = sext i32 %116 to i64
  %118 = load i32, ptr %16, align 4, !tbaa !5
  %119 = sext i32 %118 to i64
  %120 = mul i64 %119, 3
  %121 = call noalias ptr @calloc(i64 noundef %117, i64 noundef %120) #7
  store ptr %121, ptr %17, align 8, !tbaa !9
  %122 = load ptr, ptr %17, align 8, !tbaa !9
  %123 = icmp eq ptr %122, null
  br i1 %123, label %124, label %130

124:                                              ; preds = %108
  %125 = call i32 (ptr, ...) @printf(ptr noundef @.str.9)
  %126 = load ptr, ptr %12, align 8, !tbaa !9
  %127 = call i32 @fclose(ptr noundef %126)
  %128 = load ptr, ptr %11, align 8, !tbaa !9
  %129 = call i32 @fclose(ptr noundef %128)
  store i32 7, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %220

130:                                              ; preds = %108
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #6
  %131 = load i32, ptr %16, align 4, !tbaa !5
  %132 = sext i32 %131 to i64
  %133 = mul i64 %132, 3
  %134 = urem i64 %133, 4
  %135 = sub i64 4, %134
  %136 = urem i64 %135, 4
  %137 = trunc i64 %136 to i32
  store i32 %137, ptr %18, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #6
  store i32 0, ptr %19, align 4, !tbaa !5
  br label %138

138:                                              ; preds = %157, %130
  %139 = load i32, ptr %19, align 4, !tbaa !5
  %140 = load i32, ptr %15, align 4, !tbaa !5
  %141 = icmp slt i32 %139, %140
  br i1 %141, label %143, label %142

142:                                              ; preds = %138
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #6
  br label %160

143:                                              ; preds = %138
  %144 = load ptr, ptr %17, align 8, !tbaa !9
  %145 = load i32, ptr %19, align 4, !tbaa !5
  %146 = sext i32 %145 to i64
  %147 = mul nsw i64 %146, %115
  %148 = getelementptr inbounds %struct.RGBTRIPLE, ptr %144, i64 %147
  %149 = load i32, ptr %16, align 4, !tbaa !5
  %150 = sext i32 %149 to i64
  %151 = load ptr, ptr %11, align 8, !tbaa !9
  %152 = call i64 @fread(ptr noundef %148, i64 noundef 3, i64 noundef %150, ptr noundef %151)
  %153 = load ptr, ptr %11, align 8, !tbaa !9
  %154 = load i32, ptr %18, align 4, !tbaa !5
  %155 = sext i32 %154 to i64
  %156 = call i32 @fseek(ptr noundef %153, i64 noundef %155, i32 noundef 1)
  br label %157

157:                                              ; preds = %143
  %158 = load i32, ptr %19, align 4, !tbaa !5
  %159 = add nsw i32 %158, 1
  store i32 %159, ptr %19, align 4, !tbaa !5
  br label %138, !llvm.loop !22

160:                                              ; preds = %142
  %161 = load i8, ptr %7, align 1, !tbaa !11
  %162 = sext i8 %161 to i32
  switch i32 %162, label %179 [
    i32 98, label %163
    i32 103, label %167
    i32 114, label %171
    i32 115, label %175
  ]

163:                                              ; preds = %160
  %164 = load i32, ptr %15, align 4, !tbaa !5
  %165 = load i32, ptr %16, align 4, !tbaa !5
  %166 = load ptr, ptr %17, align 8, !tbaa !9
  call void @blur(i32 noundef %164, i32 noundef %165, ptr noundef %166)
  br label %179

167:                                              ; preds = %160
  %168 = load i32, ptr %15, align 4, !tbaa !5
  %169 = load i32, ptr %16, align 4, !tbaa !5
  %170 = load ptr, ptr %17, align 8, !tbaa !9
  call void @grayscale(i32 noundef %168, i32 noundef %169, ptr noundef %170)
  br label %179

171:                                              ; preds = %160
  %172 = load i32, ptr %15, align 4, !tbaa !5
  %173 = load i32, ptr %16, align 4, !tbaa !5
  %174 = load ptr, ptr %17, align 8, !tbaa !9
  call void @reflect(i32 noundef %172, i32 noundef %173, ptr noundef %174)
  br label %179

175:                                              ; preds = %160
  %176 = load i32, ptr %15, align 4, !tbaa !5
  %177 = load i32, ptr %16, align 4, !tbaa !5
  %178 = load ptr, ptr %17, align 8, !tbaa !9
  call void @sepia(i32 noundef %176, i32 noundef %177, ptr noundef %178)
  br label %179

179:                                              ; preds = %175, %171, %167, %163, %160
  %180 = load ptr, ptr %12, align 8, !tbaa !9
  %181 = call i64 @fwrite(ptr noundef %13, i64 noundef 14, i64 noundef 1, ptr noundef %180)
  %182 = load ptr, ptr %12, align 8, !tbaa !9
  %183 = call i64 @fwrite(ptr noundef %14, i64 noundef 40, i64 noundef 1, ptr noundef %182)
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #6
  store i32 0, ptr %20, align 4, !tbaa !5
  br label %184

184:                                              ; preds = %211, %179
  %185 = load i32, ptr %20, align 4, !tbaa !5
  %186 = load i32, ptr %15, align 4, !tbaa !5
  %187 = icmp slt i32 %185, %186
  br i1 %187, label %189, label %188

188:                                              ; preds = %184
  store i32 6, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #6
  br label %214

189:                                              ; preds = %184
  %190 = load ptr, ptr %17, align 8, !tbaa !9
  %191 = load i32, ptr %20, align 4, !tbaa !5
  %192 = sext i32 %191 to i64
  %193 = mul nsw i64 %192, %115
  %194 = getelementptr inbounds %struct.RGBTRIPLE, ptr %190, i64 %193
  %195 = load i32, ptr %16, align 4, !tbaa !5
  %196 = sext i32 %195 to i64
  %197 = load ptr, ptr %12, align 8, !tbaa !9
  %198 = call i64 @fwrite(ptr noundef %194, i64 noundef 3, i64 noundef %196, ptr noundef %197)
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #6
  store i32 0, ptr %21, align 4, !tbaa !5
  br label %199

199:                                              ; preds = %207, %189
  %200 = load i32, ptr %21, align 4, !tbaa !5
  %201 = load i32, ptr %18, align 4, !tbaa !5
  %202 = icmp slt i32 %200, %201
  br i1 %202, label %204, label %203

203:                                              ; preds = %199
  store i32 9, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #6
  br label %210

204:                                              ; preds = %199
  %205 = load ptr, ptr %12, align 8, !tbaa !9
  %206 = call i32 @fputc(i32 noundef 0, ptr noundef %205)
  br label %207

207:                                              ; preds = %204
  %208 = load i32, ptr %21, align 4, !tbaa !5
  %209 = add nsw i32 %208, 1
  store i32 %209, ptr %21, align 4, !tbaa !5
  br label %199, !llvm.loop !24

210:                                              ; preds = %203
  br label %211

211:                                              ; preds = %210
  %212 = load i32, ptr %20, align 4, !tbaa !5
  %213 = add nsw i32 %212, 1
  store i32 %213, ptr %20, align 4, !tbaa !5
  br label %184, !llvm.loop !25

214:                                              ; preds = %188
  %215 = load ptr, ptr %17, align 8, !tbaa !9
  call void @free(ptr noundef %215) #6
  %216 = load ptr, ptr %11, align 8, !tbaa !9
  %217 = call i32 @fclose(ptr noundef %216)
  %218 = load ptr, ptr %12, align 8, !tbaa !9
  %219 = call i32 @fclose(ptr noundef %218)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #6
  br label %220

220:                                              ; preds = %214, %124
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #6
  br label %221

221:                                              ; preds = %220, %102
  call void @llvm.lifetime.end.p0(i64 40, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 14, ptr %13) #6
  br label %222

222:                                              ; preds = %221, %71
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  br label %223

223:                                              ; preds = %222, %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  br label %224

224:                                              ; preds = %223, %45, %38, %30
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %225 = load i32, ptr %3, align 4
  ret i32 %225
}

; 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

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

declare noalias ptr @fopen(ptr noundef, ptr noundef) #3

declare i32 @fclose(ptr noundef) #3

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #4

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #5

declare i32 @fseek(ptr noundef, i64 noundef, i32 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 @blur(i32 noundef, i32 noundef, ptr noundef) #3

declare void @grayscale(i32 noundef, i32 noundef, ptr noundef) #3

declare void @reflect(i32 noundef, i32 noundef, ptr noundef) #3

declare void @sepia(i32 noundef, i32 noundef, ptr noundef) #3

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #3

declare i32 @fputc(i32 noundef, ptr noundef) #3

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

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 nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind allocsize(0,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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0,1) }

!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 = !{!7, !7, i64 0}
!12 = !{!13, !14, i64 0}
!13 = !{!"", !14, i64 0, !6, i64 2, !14, i64 6, !14, i64 8, !6, i64 10}
!14 = !{!"short", !7, i64 0}
!15 = !{!13, !6, i64 10}
!16 = !{!17, !6, i64 0}
!17 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !14, i64 12, !14, i64 14, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36}
!18 = !{!17, !14, i64 14}
!19 = !{!17, !6, i64 16}
!20 = !{!17, !6, i64 8}
!21 = !{!17, !6, i64 4}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = distinct !{!24, !23}
!25 = distinct !{!25, !23}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.BITMAPFILEHEADER = type <{ i16, i32, i16, i16, i32 }>
%struct.BITMAPINFOHEADER = type { i32, i32, i32, i16, i16, i32, i32, i32, i32, i32, i32 }
%struct.RGBTRIPLE = type { i8, i8, i8 }

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [26 x i8], align 1
@optind = external local_unnamed_addr global i32, align 4
@.str.3 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [35 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 8) i32 @main(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca %struct.BITMAPFILEHEADER, align 2
  %4 = alloca %struct.BITMAPINFOHEADER, align 4
  %5 = tail call i32 @getopt(i32 noundef %0, ptr noundef %1, ptr noundef nonnull @.str) #8
  %sext = shl i32 %5, 24
  %6 = ashr exact i32 %sext, 24
  %7 = icmp eq i32 %sext, 1056964608
  br i1 %7, label %8, label %10

8:                                                ; preds = %2
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %100

10:                                               ; preds = %2
  %11 = tail call i32 @getopt(i32 noundef %0, ptr noundef %1, ptr noundef nonnull @.str) #8
  %.not = icmp eq i32 %11, -1
  br i1 %.not, label %14, label %12

12:                                               ; preds = %10
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %100

14:                                               ; preds = %10
  %15 = load i32, ptr @optind, align 4, !tbaa !5
  %16 = add nsw i32 %15, 2
  %.not86 = icmp eq i32 %16, %0
  br i1 %.not86, label %19, label %17

17:                                               ; preds = %14
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %100

19:                                               ; preds = %14
  %20 = sext i32 %15 to i64
  %21 = getelementptr inbounds ptr, ptr %1, i64 %20
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = getelementptr i8, ptr %21, i64 8
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = tail call noalias ptr @fopen(ptr noundef %22, ptr noundef nonnull @.str.4)
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %29

27:                                               ; preds = %19
  %28 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, ptr noundef %22)
  br label %100

29:                                               ; preds = %19
  %30 = tail call noalias ptr @fopen(ptr noundef %24, ptr noundef nonnull @.str.6)
  %31 = icmp eq ptr %30, null
  br i1 %31, label %32, label %35

32:                                               ; preds = %29
  %33 = tail call i32 @fclose(ptr noundef nonnull %25)
  %34 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef %24)
  br label %100

35:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 14, ptr nonnull %3) #8
  %36 = call i64 @fread(ptr noundef nonnull %3, i64 noundef 14, i64 noundef 1, ptr noundef nonnull %25)
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %4) #8
  %37 = call i64 @fread(ptr noundef nonnull %4, i64 noundef 40, i64 noundef 1, ptr noundef nonnull %25)
  %38 = load i16, ptr %3, align 2, !tbaa !11
  %39 = icmp ne i16 %38, 19778
  %40 = getelementptr inbounds i8, ptr %3, i64 10
  %41 = load i32, ptr %40, align 2
  %42 = icmp ne i32 %41, 54
  %or.cond = select i1 %39, i1 true, i1 %42
  %43 = load i32, ptr %4, align 4
  %44 = icmp ne i32 %43, 40
  %or.cond5 = select i1 %or.cond, i1 true, i1 %44
  %45 = getelementptr inbounds i8, ptr %4, i64 14
  %46 = load i16, ptr %45, align 2
  %47 = icmp ne i16 %46, 24
  %or.cond9 = select i1 %or.cond5, i1 true, i1 %47
  %48 = getelementptr inbounds i8, ptr %4, i64 16
  %49 = load i32, ptr %48, align 4
  %50 = icmp ne i32 %49, 0
  %or.cond12 = select i1 %or.cond9, i1 true, i1 %50
  br i1 %or.cond12, label %51, label %55

51:                                               ; preds = %35
  %52 = tail call i32 @fclose(ptr noundef nonnull %30)
  %53 = tail call i32 @fclose(ptr noundef nonnull %25)
  %54 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  br label %99

55:                                               ; preds = %35
  %56 = getelementptr inbounds i8, ptr %4, i64 8
  %57 = load i32, ptr %56, align 4, !tbaa !14
  %58 = tail call i32 @llvm.abs.i32(i32 %57, i1 true)
  %59 = getelementptr inbounds i8, ptr %4, i64 4
  %60 = load i32, ptr %59, align 4, !tbaa !16
  %61 = zext i32 %60 to i64
  %62 = zext nneg i32 %58 to i64
  %63 = sext i32 %60 to i64
  %64 = mul nsw i64 %63, 3
  %65 = tail call noalias ptr @calloc(i64 noundef %62, i64 noundef %64) #9
  %66 = icmp eq ptr %65, null
  br i1 %66, label %67, label %71

67:                                               ; preds = %55
  %68 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9)
  %69 = tail call i32 @fclose(ptr noundef nonnull %30)
  %70 = tail call i32 @fclose(ptr noundef nonnull %25)
  br label %99

71:                                               ; preds = %55
  %72 = trunc i64 %64 to i32
  %73 = sub i32 0, %72
  %74 = and i32 %73, 3
  %.not96 = icmp eq i32 %57, 0
  br i1 %.not96, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %71
  %75 = zext nneg i32 %74 to i64
  br label %76

._crit_edge:                                      ; preds = %76, %71
  switch i32 %6, label %85 [
    i32 98, label %81
    i32 103, label %82
    i32 114, label %83
    i32 115, label %84
  ]

76:                                               ; preds = %.lr.ph, %76
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %76 ]
  %77 = mul nuw nsw i64 %indvars.iv, %61
  %78 = getelementptr inbounds %struct.RGBTRIPLE, ptr %65, i64 %77
  %79 = tail call i64 @fread(ptr noundef nonnull %78, i64 noundef 3, i64 noundef %63, ptr noundef nonnull %25)
  %80 = tail call i32 @fseek(ptr noundef nonnull %25, i64 noundef %75, i32 noundef 1)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %62
  br i1 %exitcond.not, label %._crit_edge, label %76, !llvm.loop !17

81:                                               ; preds = %._crit_edge
  tail call void @blur(i32 noundef %58, i32 noundef %60, ptr noundef nonnull %65) #8
  br label %85

82:                                               ; preds = %._crit_edge
  tail call void @grayscale(i32 noundef %58, i32 noundef %60, ptr noundef nonnull %65) #8
  br label %85

83:                                               ; preds = %._crit_edge
  tail call void @reflect(i32 noundef %58, i32 noundef %60, ptr noundef nonnull %65) #8
  br label %85

84:                                               ; preds = %._crit_edge
  tail call void @sepia(i32 noundef %58, i32 noundef %60, ptr noundef nonnull %65) #8
  br label %85

85:                                               ; preds = %84, %83, %82, %81, %._crit_edge
  %86 = call i64 @fwrite(ptr noundef nonnull %3, i64 noundef 14, i64 noundef 1, ptr noundef nonnull %30)
  %87 = call i64 @fwrite(ptr noundef nonnull %4, i64 noundef 40, i64 noundef 1, ptr noundef nonnull %30)
  br i1 %.not96, label %._crit_edge95, label %.lr.ph94

.lr.ph94:                                         ; preds = %85
  %.not98 = icmp eq i32 %74, 0
  br i1 %.not98, label %.lr.ph94.split, label %.lr.ph90.us

.lr.ph90.us:                                      ; preds = %.lr.ph94, %._crit_edge91.us
  %indvars.iv102 = phi i64 [ %indvars.iv.next103, %._crit_edge91.us ], [ 0, %.lr.ph94 ]
  %88 = mul nuw nsw i64 %indvars.iv102, %61
  %89 = getelementptr inbounds %struct.RGBTRIPLE, ptr %65, i64 %88
  %90 = tail call i64 @fwrite(ptr noundef nonnull %89, i64 noundef 3, i64 noundef %63, ptr noundef nonnull %30)
  br label %91

91:                                               ; preds = %.lr.ph90.us, %91
  %.088.us = phi i32 [ 0, %.lr.ph90.us ], [ %93, %91 ]
  %92 = tail call i32 @fputc(i32 noundef 0, ptr noundef nonnull %30)
  %93 = add nuw nsw i32 %.088.us, 1
  %exitcond101.not = icmp eq i32 %93, %74
  br i1 %exitcond101.not, label %._crit_edge91.us, label %91, !llvm.loop !19

._crit_edge91.us:                                 ; preds = %91
  %indvars.iv.next103 = add nuw nsw i64 %indvars.iv102, 1
  %exitcond106.not = icmp eq i64 %indvars.iv.next103, %62
  br i1 %exitcond106.not, label %._crit_edge95, label %.lr.ph90.us, !llvm.loop !20

._crit_edge95:                                    ; preds = %._crit_edge91.us, %.lr.ph94.split, %85
  tail call void @free(ptr noundef %65) #8
  %94 = tail call i32 @fclose(ptr noundef nonnull %25)
  %95 = tail call i32 @fclose(ptr noundef nonnull %30)
  br label %99

.lr.ph94.split:                                   ; preds = %.lr.ph94, %.lr.ph94.split
  %indvars.iv107 = phi i64 [ %indvars.iv.next108, %.lr.ph94.split ], [ 0, %.lr.ph94 ]
  %96 = mul nuw nsw i64 %indvars.iv107, %61
  %97 = getelementptr inbounds %struct.RGBTRIPLE, ptr %65, i64 %96
  %98 = tail call i64 @fwrite(ptr noundef nonnull %97, i64 noundef 3, i64 noundef %63, ptr noundef nonnull %30)
  %indvars.iv.next108 = add nuw nsw i64 %indvars.iv107, 1
  %exitcond111.not = icmp eq i64 %indvars.iv.next108, %62
  br i1 %exitcond111.not, label %._crit_edge95, label %.lr.ph94.split, !llvm.loop !20

99:                                               ; preds = %67, %._crit_edge95, %51
  %.1 = phi i32 [ 6, %51 ], [ 7, %67 ], [ 0, %._crit_edge95 ]
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %4) #8
  call void @llvm.lifetime.end.p0(i64 14, ptr nonnull %3) #8
  br label %100

100:                                              ; preds = %27, %99, %32, %17, %12, %8
  %.4 = phi i32 [ 1, %8 ], [ 2, %12 ], [ 3, %17 ], [ 4, %27 ], [ 5, %32 ], [ %.1, %99 ]
  ret i32 %.4
}

; Function Attrs: mustprogress 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) local_unnamed_addr #2

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

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #3

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #4

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #5

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

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

declare void @blur(i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #6

declare void @grayscale(i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #6

declare void @reflect(i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #6

declare void @sepia(i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #6

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

; Function Attrs: nofree nounwind
declare noundef i32 @fputc(i32 noundef, ptr nocapture 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

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 = { mustprogress 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 = { 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 #4 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) 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 #6 = { "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,1) }

!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 = !{!12, !13, i64 0}
!12 = !{!"", !13, i64 0, !6, i64 2, !13, i64 6, !13, i64 8, !6, i64 10}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !6, i64 8}
!15 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !13, i64 12, !13, i64 14, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36}
!16 = !{!15, !6, i64 4}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}
!20 = distinct !{!20, !18}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass