; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R2Shapes/R2Image.ll (ZNK7R2Image8WritePPMEPKci)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%class.R2Image = type { i32, i32, i32, i32, ptr }

@.str = external hidden unnamed_addr constant [41 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [89 x i8], align 1
@stderr = external global ptr, align 8
@.str.14 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.39 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.46 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.48 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.51 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.52 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.54 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.55 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.56 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.57 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.58 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.59 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.60 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.61 = external hidden unnamed_addr constant [7 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 void @_Z7RNAbortPKcz(ptr noundef, ...) #1

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK7R2Image5PixelEii(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef, i32 noundef) #2 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK7R2Image8WritePPMEPKci(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1, i32 noundef %2) #4 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %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 ptr, align 8
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  %23 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %24 = load ptr, ptr %5, align 8
  %25 = getelementptr inbounds %class.R2Image, ptr %24, i32 0, i32 2
  %26 = load i32, ptr %25, align 8, !tbaa !11
  %27 = icmp eq i32 %26, 3
  br i1 %27, label %29, label %28

28:                                               ; preds = %3
  call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef @.str, ptr noundef @.str.38, i32 noundef 836, ptr noundef @.str.2)
  br label %29

29:                                               ; preds = %28, %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = call noundef ptr @strstr(ptr noundef %30, ptr noundef @.str.14) #8
  %32 = icmp ne ptr %31, null
  %33 = zext i1 %32 to i64
  %34 = select i1 %32, i32 1, i32 0
  store i32 %34, ptr %8, align 4, !tbaa !9
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %150

37:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #7
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = call noalias ptr @fopen(ptr noundef %38, ptr noundef @.str.54)
  store ptr %39, ptr %9, align 8, !tbaa !5
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = icmp ne ptr %40, null
  br i1 %41, label %46, label %42

42:                                               ; preds = %37
  %43 = load ptr, ptr @stderr, align 8, !tbaa !5
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %43, ptr noundef @.str.26, ptr noundef %44) #7
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %147

46:                                               ; preds = %37
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %52

49:                                               ; preds = %46
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %50, ptr noundef @.str.46) #7
  br label %55

52:                                               ; preds = %46
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %53, ptr noundef @.str.48) #7
  br label %55

55:                                               ; preds = %52, %49
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = getelementptr inbounds %class.R2Image, ptr %24, i32 0, i32 0
  %58 = load i32, ptr %57, align 8, !tbaa !13
  %59 = getelementptr inbounds %class.R2Image, ptr %24, i32 0, i32 1
  %60 = load i32, ptr %59, align 4, !tbaa !14
  %61 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %56, ptr noundef @.str.55, i32 noundef %58, i32 noundef %60) #7
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %62, ptr noundef @.str.56) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #7
  %64 = getelementptr inbounds %class.R2Image, ptr %24, i32 0, i32 1
  %65 = load i32, ptr %64, align 4, !tbaa !14
  %66 = sub nsw i32 %65, 1
  store i32 %66, ptr %11, align 4, !tbaa !9
  br label %67

67:                                               ; preds = %139, %55
  %68 = load i32, ptr %11, align 4, !tbaa !9
  %69 = icmp sge i32 %68, 0
  br i1 %69, label %71, label %70

70:                                               ; preds = %67
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #7
  br label %142

71:                                               ; preds = %67
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #7
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %72

72:                                               ; preds = %127, %71
  %73 = load i32, ptr %12, align 4, !tbaa !9
  %74 = getelementptr inbounds %class.R2Image, ptr %24, i32 0, i32 0
  %75 = load i32, ptr %74, align 8, !tbaa !13
  %76 = icmp slt i32 %73, %75
  br i1 %76, label %78, label %77

77:                                               ; preds = %72
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #7
  br label %130

78:                                               ; preds = %72
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #7
  %79 = load i32, ptr %12, align 4, !tbaa !9
  %80 = load i32, ptr %11, align 4, !tbaa !9
  %81 = call noundef ptr @_ZNK7R2Image5PixelEii(ptr noundef nonnull align 8 dereferenceable(24) %24, i32 noundef %79, i32 noundef %80)
  store ptr %81, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #7
  %82 = load ptr, ptr %13, align 8, !tbaa !5
  %83 = getelementptr inbounds i8, ptr %82, i32 1
  store ptr %83, ptr %13, align 8, !tbaa !5
  %84 = load i8, ptr %82, align 1, !tbaa !15
  %85 = zext i8 %84 to i32
  %86 = and i32 %85, 255
  store i32 %86, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #7
  %87 = load ptr, ptr %13, align 8, !tbaa !5
  %88 = getelementptr inbounds i8, ptr %87, i32 1
  store ptr %88, ptr %13, align 8, !tbaa !5
  %89 = load i8, ptr %87, align 1, !tbaa !15
  %90 = zext i8 %89 to i32
  %91 = and i32 %90, 255
  store i32 %91, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #7
  %92 = load ptr, ptr %13, align 8, !tbaa !5
  %93 = getelementptr inbounds i8, ptr %92, i32 1
  store ptr %93, ptr %13, align 8, !tbaa !5
  %94 = load i8, ptr %92, align 1, !tbaa !15
  %95 = zext i8 %94 to i32
  %96 = and i32 %95, 255
  store i32 %96, ptr %16, align 4, !tbaa !9
  %97 = load i32, ptr %8, align 4, !tbaa !9
  %98 = icmp ne i32 %97, 0
  br i1 %98, label %99, label %112

99:                                               ; preds = %78
  %100 = load ptr, ptr %9, align 8, !tbaa !5
  %101 = load i32, ptr %14, align 4, !tbaa !9
  %102 = sitofp i32 %101 to double
  %103 = load i32, ptr %15, align 4, !tbaa !9
  %104 = sitofp i32 %103 to double
  %105 = fmul double 5.900000e-01, %104
  %106 = call double @llvm.fmuladd.f64(double 3.000000e-01, double %102, double %105)
  %107 = load i32, ptr %16, align 4, !tbaa !9
  %108 = sitofp i32 %107 to double
  %109 = call double @llvm.fmuladd.f64(double 1.100000e-01, double %108, double %106)
  %110 = fptosi double %109 to i32
  %111 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %100, ptr noundef @.str.57, i32 noundef %110) #7
  br label %118

112:                                              ; preds = %78
  %113 = load ptr, ptr %9, align 8, !tbaa !5
  %114 = load i32, ptr %14, align 4, !tbaa !9
  %115 = load i32, ptr %15, align 4, !tbaa !9
  %116 = load i32, ptr %16, align 4, !tbaa !9
  %117 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %113, ptr noundef @.str.58, i32 noundef %114, i32 noundef %115, i32 noundef %116) #7
  br label %118

118:                                              ; preds = %112, %99
  %119 = load i32, ptr %12, align 4, !tbaa !9
  %120 = add nsw i32 %119, 1
  %121 = srem i32 %120, 4
  %122 = icmp eq i32 %121, 0
  br i1 %122, label %123, label %126

123:                                              ; preds = %118
  %124 = load ptr, ptr %9, align 8, !tbaa !5
  %125 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %124, ptr noundef @.str.59) #7
  br label %126

126:                                              ; preds = %123, %118
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #7
  br label %127

127:                                              ; preds = %126
  %128 = load i32, ptr %12, align 4, !tbaa !9
  %129 = add nsw i32 %128, 1
  store i32 %129, ptr %12, align 4, !tbaa !9
  br label %72, !llvm.loop !16

130:                                              ; preds = %77
  %131 = getelementptr inbounds %class.R2Image, ptr %24, i32 0, i32 0
  %132 = load i32, ptr %131, align 8, !tbaa !13
  %133 = srem i32 %132, 4
  %134 = icmp ne i32 %133, 0
  br i1 %134, label %135, label %138

135:                                              ; preds = %130
  %136 = load ptr, ptr %9, align 8, !tbaa !5
  %137 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %136, ptr noundef @.str.59) #7
  br label %138

138:                                              ; preds = %135, %130
  br label %139

139:                                              ; preds = %138
  %140 = load i32, ptr %11, align 4, !tbaa !9
  %141 = add nsw i32 %140, -1
  store i32 %141, ptr %11, align 4, !tbaa !9
  br label %67, !llvm.loop !18

142:                                              ; preds = %70
  %143 = load ptr, ptr %9, align 8, !tbaa !5
  %144 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %143, ptr noundef @.str.59) #7
  %145 = load ptr, ptr %9, align 8, !tbaa !5
  %146 = call i32 @fclose(ptr noundef %145)
  store i32 0, ptr %10, align 4
  br label %147

147:                                              ; preds = %142, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #7
  %148 = load i32, ptr %10, align 4
  switch i32 %148, label %254 [
    i32 0, label %149
  ]

149:                                              ; preds = %147
  br label %245

150:                                              ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #7
  %151 = load ptr, ptr %6, align 8, !tbaa !5
  %152 = call noalias ptr @fopen(ptr noundef %151, ptr noundef @.str.39)
  store ptr %152, ptr %17, align 8, !tbaa !5
  %153 = load ptr, ptr %17, align 8, !tbaa !5
  %154 = icmp ne ptr %153, null
  br i1 %154, label %159, label %155

155:                                              ; preds = %150
  %156 = load ptr, ptr @stderr, align 8, !tbaa !5
  %157 = load ptr, ptr %6, align 8, !tbaa !5
  %158 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %156, ptr noundef @.str.26, ptr noundef %157) #7
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %242

159:                                              ; preds = %150
  %160 = load i32, ptr %8, align 4, !tbaa !9
  %161 = icmp ne i32 %160, 0
  br i1 %161, label %162, label %165

162:                                              ; preds = %159
  %163 = load ptr, ptr %17, align 8, !tbaa !5
  %164 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %163, ptr noundef @.str.51) #7
  br label %168

165:                                              ; preds = %159
  %166 = load ptr, ptr %17, align 8, !tbaa !5
  %167 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %166, ptr noundef @.str.52) #7
  br label %168

168:                                              ; preds = %165, %162
  %169 = load ptr, ptr %17, align 8, !tbaa !5
  %170 = getelementptr inbounds %class.R2Image, ptr %24, i32 0, i32 0
  %171 = load i32, ptr %170, align 8, !tbaa !13
  %172 = getelementptr inbounds %class.R2Image, ptr %24, i32 0, i32 1
  %173 = load i32, ptr %172, align 4, !tbaa !14
  %174 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %169, ptr noundef @.str.55, i32 noundef %171, i32 noundef %173) #7
  %175 = load ptr, ptr %17, align 8, !tbaa !5
  %176 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %175, ptr noundef @.str.56) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #7
  %177 = getelementptr inbounds %class.R2Image, ptr %24, i32 0, i32 1
  %178 = load i32, ptr %177, align 4, !tbaa !14
  %179 = sub nsw i32 %178, 1
  store i32 %179, ptr %18, align 4, !tbaa !9
  br label %180

180:                                              ; preds = %236, %168
  %181 = load i32, ptr %18, align 4, !tbaa !9
  %182 = icmp sge i32 %181, 0
  br i1 %182, label %184, label %183

183:                                              ; preds = %180
  store i32 8, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #7
  br label %239

184:                                              ; preds = %180
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #7
  store i32 0, ptr %19, align 4, !tbaa !9
  br label %185

185:                                              ; preds = %232, %184
  %186 = load i32, ptr %19, align 4, !tbaa !9
  %187 = getelementptr inbounds %class.R2Image, ptr %24, i32 0, i32 0
  %188 = load i32, ptr %187, align 8, !tbaa !13
  %189 = icmp slt i32 %186, %188
  br i1 %189, label %191, label %190

190:                                              ; preds = %185
  store i32 11, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #7
  br label %235

191:                                              ; preds = %185
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #7
  %192 = load i32, ptr %19, align 4, !tbaa !9
  %193 = load i32, ptr %18, align 4, !tbaa !9
  %194 = call noundef ptr @_ZNK7R2Image5PixelEii(ptr noundef nonnull align 8 dereferenceable(24) %24, i32 noundef %192, i32 noundef %193)
  store ptr %194, ptr %20, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #7
  %195 = load ptr, ptr %20, align 8, !tbaa !5
  %196 = getelementptr inbounds i8, ptr %195, i32 1
  store ptr %196, ptr %20, align 8, !tbaa !5
  %197 = load i8, ptr %195, align 1, !tbaa !15
  %198 = zext i8 %197 to i32
  %199 = and i32 %198, 255
  store i32 %199, ptr %21, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #7
  %200 = load ptr, ptr %20, align 8, !tbaa !5
  %201 = getelementptr inbounds i8, ptr %200, i32 1
  store ptr %201, ptr %20, align 8, !tbaa !5
  %202 = load i8, ptr %200, align 1, !tbaa !15
  %203 = zext i8 %202 to i32
  %204 = and i32 %203, 255
  store i32 %204, ptr %22, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #7
  %205 = load ptr, ptr %20, align 8, !tbaa !5
  %206 = getelementptr inbounds i8, ptr %205, i32 1
  store ptr %206, ptr %20, align 8, !tbaa !5
  %207 = load i8, ptr %205, align 1, !tbaa !15
  %208 = zext i8 %207 to i32
  %209 = and i32 %208, 255
  store i32 %209, ptr %23, align 4, !tbaa !9
  %210 = load i32, ptr %8, align 4, !tbaa !9
  %211 = icmp ne i32 %210, 0
  br i1 %211, label %212, label %225

212:                                              ; preds = %191
  %213 = load ptr, ptr %17, align 8, !tbaa !5
  %214 = load i32, ptr %21, align 4, !tbaa !9
  %215 = sitofp i32 %214 to double
  %216 = load i32, ptr %22, align 4, !tbaa !9
  %217 = sitofp i32 %216 to double
  %218 = fmul double 5.900000e-01, %217
  %219 = call double @llvm.fmuladd.f64(double 3.000000e-01, double %215, double %218)
  %220 = load i32, ptr %23, align 4, !tbaa !9
  %221 = sitofp i32 %220 to double
  %222 = call double @llvm.fmuladd.f64(double 1.100000e-01, double %221, double %219)
  %223 = fptosi double %222 to i32
  %224 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %213, ptr noundef @.str.60, i32 noundef %223) #7
  br label %231

225:                                              ; preds = %191
  %226 = load ptr, ptr %17, align 8, !tbaa !5
  %227 = load i32, ptr %21, align 4, !tbaa !9
  %228 = load i32, ptr %22, align 4, !tbaa !9
  %229 = load i32, ptr %23, align 4, !tbaa !9
  %230 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %226, ptr noundef @.str.61, i32 noundef %227, i32 noundef %228, i32 noundef %229) #7
  br label %231

231:                                              ; preds = %225, %212
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #7
  br label %232

232:                                              ; preds = %231
  %233 = load i32, ptr %19, align 4, !tbaa !9
  %234 = add nsw i32 %233, 1
  store i32 %234, ptr %19, align 4, !tbaa !9
  br label %185, !llvm.loop !19

235:                                              ; preds = %190
  br label %236

236:                                              ; preds = %235
  %237 = load i32, ptr %18, align 4, !tbaa !9
  %238 = add nsw i32 %237, -1
  store i32 %238, ptr %18, align 4, !tbaa !9
  br label %180, !llvm.loop !20

239:                                              ; preds = %183
  %240 = load ptr, ptr %17, align 8, !tbaa !5
  %241 = call i32 @fclose(ptr noundef %240)
  store i32 0, ptr %10, align 4
  br label %242

242:                                              ; preds = %239, %155
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #7
  %243 = load i32, ptr %10, align 4
  switch i32 %243, label %254 [
    i32 0, label %244
  ]

244:                                              ; preds = %242
  br label %245

245:                                              ; preds = %244, %149
  %246 = getelementptr inbounds %class.R2Image, ptr %24, i32 0, i32 0
  %247 = load i32, ptr %246, align 8, !tbaa !13
  %248 = getelementptr inbounds %class.R2Image, ptr %24, i32 0, i32 1
  %249 = load i32, ptr %248, align 4, !tbaa !14
  %250 = mul nsw i32 %247, %249
  %251 = getelementptr inbounds %class.R2Image, ptr %24, i32 0, i32 2
  %252 = load i32, ptr %251, align 8, !tbaa !11
  %253 = mul nsw i32 %250, %252
  store i32 %253, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %254

254:                                              ; preds = %245, %242, %147
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  %255 = load i32, ptr %4, align 4
  ret i32 %255
}

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

declare i32 @fclose(ptr noundef) #1

; Function Attrs: nounwind willreturn memory(read)
declare noundef ptr @strstr(ptr noundef, ptr noundef) #5

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #6

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 = { inlinehint mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { 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 uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { nounwind willreturn memory(read) "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(read) }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"_ZTS7R2Image", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !6, i64 16}
!13 = !{!12, !10, i64 0}
!14 = !{!12, !10, i64 4}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}
!19 = distinct !{!19, !17}
!20 = distinct !{!20, !17}


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

@.str = external hidden unnamed_addr constant [41 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [89 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.14 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.39 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.46 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.48 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.51 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.52 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.54 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.55 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.56 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.57 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.58 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.59 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.60 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.61 = external hidden unnamed_addr constant [7 x i8], align 1

declare void @_Z7RNAbortPKcz(ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK7R2Image5PixelEii(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef, i32 noundef) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK7R2Image8WritePPMEPKci(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #3 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = icmp eq i32 %5, 3
  br i1 %6, label %8, label %7

7:                                                ; preds = %3
  tail call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef nonnull @.str, ptr noundef nonnull @.str.38, i32 noundef 836, ptr noundef nonnull @.str.2)
  br label %8

8:                                                ; preds = %7, %3
  %9 = tail call noundef ptr @strstr(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.14) #6
  %.not = icmp eq ptr %9, null
  %.not72 = icmp eq i32 %2, 0
  br i1 %.not72, label %78, label %10

10:                                               ; preds = %8
  %11 = tail call noalias ptr @fopen(ptr noundef %1, ptr noundef nonnull @.str.54)
  %.not74.not = icmp eq ptr %11, null
  br i1 %.not74.not, label %.thread, label %14

.thread:                                          ; preds = %10
  %12 = load ptr, ptr @stderr, align 8, !tbaa !11
  %13 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef nonnull @.str.26, ptr noundef %1) #7
  br label %134

14:                                               ; preds = %10
  %.str.48..str.46 = select i1 %.not, ptr @.str.48, ptr @.str.46
  %15 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %11, ptr noundef nonnull %.str.48..str.46) #8
  %16 = load i32, ptr %0, align 8, !tbaa !12
  %17 = getelementptr inbounds i8, ptr %0, i64 4
  %18 = load i32, ptr %17, align 4, !tbaa !13
  %19 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %11, ptr noundef nonnull @.str.55, i32 noundef %16, i32 noundef %18) #8
  %20 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %11, ptr noundef nonnull @.str.56) #8
  %21 = load i32, ptr %17, align 4, !tbaa !13
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %.preheader77.lr.ph, label %._crit_edge81

.preheader77.lr.ph:                               ; preds = %14
  %.06679 = add nsw i32 %21, -1
  br i1 %.not, label %.preheader77.us, label %.preheader77

.preheader77.us:                                  ; preds = %.preheader77.lr.ph, %28
  %.06680.us = phi i32 [ %.066.us, %28 ], [ %.06679, %.preheader77.lr.ph ]
  %23 = load i32, ptr %0, align 8, !tbaa !12
  %24 = icmp sgt i32 %23, 0
  br i1 %24, label %.lr.ph.us, label %._crit_edge.split.us.us

._crit_edge.split.us.us:                          ; preds = %45, %.preheader77.us
  %.lcssa.us = phi i32 [ %23, %.preheader77.us ], [ %46, %45 ]
  %25 = and i32 %.lcssa.us, 3
  %.not75.us = icmp eq i32 %25, 0
  br i1 %.not75.us, label %28, label %26

26:                                               ; preds = %._crit_edge.split.us.us
  %27 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %11, ptr noundef nonnull @.str.59) #8
  br label %28

28:                                               ; preds = %26, %._crit_edge.split.us.us
  %.066.us = add nsw i32 %.06680.us, -1
  %29 = icmp sgt i32 %.06680.us, 0
  br i1 %29, label %.preheader77.us, label %._crit_edge81, !llvm.loop !14

.lr.ph.us:                                        ; preds = %.preheader77.us, %45
  %.06778.us.us = phi i32 [ %40, %45 ], [ 0, %.preheader77.us ]
  %30 = tail call noundef ptr @_ZNK7R2Image5PixelEii(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %.06778.us.us, i32 noundef %.06680.us)
  %31 = getelementptr inbounds i8, ptr %30, i64 1
  %32 = load i8, ptr %30, align 1, !tbaa !16
  %33 = getelementptr inbounds i8, ptr %30, i64 2
  %34 = load i8, ptr %31, align 1, !tbaa !16
  %35 = load i8, ptr %33, align 1, !tbaa !16
  %36 = zext i8 %35 to i32
  %37 = zext i8 %34 to i32
  %38 = zext i8 %32 to i32
  %39 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %11, ptr noundef nonnull @.str.58, i32 noundef %38, i32 noundef %37, i32 noundef %36) #8
  %40 = add nuw nsw i32 %.06778.us.us, 1
  %41 = and i32 %40, 3
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %45

43:                                               ; preds = %.lr.ph.us
  %44 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %11, ptr noundef nonnull @.str.59) #8
  br label %45

45:                                               ; preds = %43, %.lr.ph.us
  %46 = load i32, ptr %0, align 8, !tbaa !12
  %47 = icmp slt i32 %40, %46
  br i1 %47, label %.lr.ph.us, label %._crit_edge.split.us.us, !llvm.loop !17

.preheader77:                                     ; preds = %.preheader77.lr.ph, %75
  %.06680 = phi i32 [ %.066, %75 ], [ %.06679, %.preheader77.lr.ph ]
  %48 = load i32, ptr %0, align 8, !tbaa !12
  %49 = icmp sgt i32 %48, 0
  br i1 %49, label %.lr.ph, label %._crit_edge.split

._crit_edge.split:                                ; preds = %70, %.preheader77
  %.lcssa = phi i32 [ %48, %.preheader77 ], [ %71, %70 ]
  %50 = and i32 %.lcssa, 3
  %.not75 = icmp eq i32 %50, 0
  br i1 %.not75, label %75, label %73

.lr.ph:                                           ; preds = %.preheader77, %70
  %.06778 = phi i32 [ %65, %70 ], [ 0, %.preheader77 ]
  %51 = tail call noundef ptr @_ZNK7R2Image5PixelEii(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %.06778, i32 noundef %.06680)
  %52 = getelementptr inbounds i8, ptr %51, i64 1
  %53 = load i8, ptr %51, align 1, !tbaa !16
  %54 = getelementptr inbounds i8, ptr %51, i64 2
  %55 = load i8, ptr %52, align 1, !tbaa !16
  %56 = load i8, ptr %54, align 1, !tbaa !16
  %57 = uitofp i8 %53 to double
  %58 = uitofp i8 %55 to double
  %59 = fmul double %58, 5.900000e-01
  %60 = tail call double @llvm.fmuladd.f64(double %57, double 3.000000e-01, double %59)
  %61 = uitofp i8 %56 to double
  %62 = tail call double @llvm.fmuladd.f64(double %61, double 1.100000e-01, double %60)
  %63 = fptosi double %62 to i32
  %64 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %11, ptr noundef nonnull @.str.57, i32 noundef %63) #8
  %65 = add nuw nsw i32 %.06778, 1
  %66 = and i32 %65, 3
  %67 = icmp eq i32 %66, 0
  br i1 %67, label %68, label %70

68:                                               ; preds = %.lr.ph
  %69 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %11, ptr noundef nonnull @.str.59) #8
  br label %70

70:                                               ; preds = %68, %.lr.ph
  %71 = load i32, ptr %0, align 8, !tbaa !12
  %72 = icmp slt i32 %65, %71
  br i1 %72, label %.lr.ph, label %._crit_edge.split, !llvm.loop !17

73:                                               ; preds = %._crit_edge.split
  %74 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %11, ptr noundef nonnull @.str.59) #8
  br label %75

75:                                               ; preds = %._crit_edge.split, %73
  %.066 = add nsw i32 %.06680, -1
  %76 = icmp sgt i32 %.06680, 0
  br i1 %76, label %.preheader77, label %._crit_edge81, !llvm.loop !14

._crit_edge81:                                    ; preds = %75, %28, %14
  %77 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %11, ptr noundef nonnull @.str.59) #8
  br label %._crit_edge

78:                                               ; preds = %8
  %79 = tail call noalias ptr @fopen(ptr noundef %1, ptr noundef nonnull @.str.39)
  %.not73.not = icmp eq ptr %79, null
  br i1 %.not73.not, label %.thread76, label %82

.thread76:                                        ; preds = %78
  %80 = load ptr, ptr @stderr, align 8, !tbaa !11
  %81 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %80, ptr noundef nonnull @.str.26, ptr noundef %1) #7
  br label %134

82:                                               ; preds = %78
  %.str.52..str.51 = select i1 %.not, ptr @.str.52, ptr @.str.51
  %83 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %79, ptr noundef nonnull %.str.52..str.51) #8
  %84 = load i32, ptr %0, align 8, !tbaa !12
  %85 = getelementptr inbounds i8, ptr %0, i64 4
  %86 = load i32, ptr %85, align 4, !tbaa !13
  %87 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %79, ptr noundef nonnull @.str.55, i32 noundef %84, i32 noundef %86) #8
  %88 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %79, ptr noundef nonnull @.str.56) #8
  %89 = load i32, ptr %85, align 4, !tbaa !13
  %90 = icmp sgt i32 %89, 0
  %91 = load i32, ptr %0, align 8
  %92 = icmp sgt i32 %91, 0
  %or.cond = select i1 %90, i1 %92, i1 false
  br i1 %or.cond, label %.preheader, label %._crit_edge

.loopexit:                                        ; preds = %.lr.ph83.split, %.lr.ph83.split.us, %.preheader
  %93 = phi i32 [ %95, %.preheader ], [ %108, %.lr.ph83.split.us ], [ %125, %.lr.ph83.split ]
  %94 = icmp sgt i32 %.06985.in, 1
  br i1 %94, label %.preheader, label %._crit_edge, !llvm.loop !18

.preheader:                                       ; preds = %82, %.loopexit
  %95 = phi i32 [ %93, %.loopexit ], [ %91, %82 ]
  %.06985.in = phi i32 [ %.06985, %.loopexit ], [ %89, %82 ]
  %.06985 = add nsw i32 %.06985.in, -1
  %96 = icmp sgt i32 %95, 0
  br i1 %96, label %.lr.ph83, label %.loopexit

.lr.ph83:                                         ; preds = %.preheader
  br i1 %.not, label %.lr.ph83.split.us, label %.lr.ph83.split

.lr.ph83.split.us:                                ; preds = %.lr.ph83, %.lr.ph83.split.us
  %.06882.us = phi i32 [ %107, %.lr.ph83.split.us ], [ 0, %.lr.ph83 ]
  %97 = tail call noundef ptr @_ZNK7R2Image5PixelEii(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %.06882.us, i32 noundef %.06985)
  %98 = getelementptr inbounds i8, ptr %97, i64 1
  %99 = load i8, ptr %97, align 1, !tbaa !16
  %100 = getelementptr inbounds i8, ptr %97, i64 2
  %101 = load i8, ptr %98, align 1, !tbaa !16
  %102 = load i8, ptr %100, align 1, !tbaa !16
  %103 = zext i8 %102 to i32
  %104 = zext i8 %101 to i32
  %105 = zext i8 %99 to i32
  %106 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %79, ptr noundef nonnull @.str.61, i32 noundef %105, i32 noundef %104, i32 noundef %103) #8
  %107 = add nuw nsw i32 %.06882.us, 1
  %108 = load i32, ptr %0, align 8, !tbaa !12
  %109 = icmp slt i32 %107, %108
  br i1 %109, label %.lr.ph83.split.us, label %.loopexit, !llvm.loop !20

.lr.ph83.split:                                   ; preds = %.lr.ph83, %.lr.ph83.split
  %.06882 = phi i32 [ %124, %.lr.ph83.split ], [ 0, %.lr.ph83 ]
  %110 = tail call noundef ptr @_ZNK7R2Image5PixelEii(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %.06882, i32 noundef %.06985)
  %111 = getelementptr inbounds i8, ptr %110, i64 1
  %112 = load i8, ptr %110, align 1, !tbaa !16
  %113 = getelementptr inbounds i8, ptr %110, i64 2
  %114 = load i8, ptr %111, align 1, !tbaa !16
  %115 = load i8, ptr %113, align 1, !tbaa !16
  %116 = uitofp i8 %112 to double
  %117 = uitofp i8 %114 to double
  %118 = fmul double %117, 5.900000e-01
  %119 = tail call double @llvm.fmuladd.f64(double %116, double 3.000000e-01, double %118)
  %120 = uitofp i8 %115 to double
  %121 = tail call double @llvm.fmuladd.f64(double %120, double 1.100000e-01, double %119)
  %122 = fptosi double %121 to i32
  %123 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %79, ptr noundef nonnull @.str.60, i32 noundef %122) #8
  %124 = add nuw nsw i32 %.06882, 1
  %125 = load i32, ptr %0, align 8, !tbaa !12
  %126 = icmp slt i32 %124, %125
  br i1 %126, label %.lr.ph83.split, label %.loopexit, !llvm.loop !20

._crit_edge:                                      ; preds = %.loopexit, %82, %._crit_edge81
  %.sink = phi ptr [ %11, %._crit_edge81 ], [ %79, %82 ], [ %79, %.loopexit ]
  %127 = tail call i32 @fclose(ptr noundef nonnull %.sink)
  %128 = load i32, ptr %0, align 8, !tbaa !12
  %129 = getelementptr inbounds i8, ptr %0, i64 4
  %130 = load i32, ptr %129, align 4, !tbaa !13
  %131 = mul nsw i32 %130, %128
  %132 = load i32, ptr %4, align 8, !tbaa !5
  %133 = mul nsw i32 %131, %132
  br label %134

134:                                              ; preds = %.thread76, %.thread, %._crit_edge
  %.2 = phi i32 [ %133, %._crit_edge ], [ 0, %.thread ], [ 0, %.thread76 ]
  ret i32 %.2
}

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare noundef ptr @strstr(ptr noundef, ptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #5

attributes #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 = { inlinehint mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #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 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { nounwind willreturn memory(read) }
attributes #7 = { cold nounwind }
attributes #8 = { 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, !7, i64 8}
!6 = !{!"_ZTS7R2Image", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !7, i64 4}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!8, !8, i64 0}
!17 = distinct !{!17, !15}
!18 = distinct !{!18, !15, !19}
!19 = !{!"llvm.loop.unswitch.partial.disable"}
!20 = distinct !{!20, !15}


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