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

; 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.R2Grid = type { %class.R2Affine, %class.R2Affine, double, ptr, [2 x i32], i32, i32 }
%class.R2Affine = type <{ %class.R2Transformation, %class.R3Matrix, i32, [4 x i8] }>
%class.R2Transformation = type { ptr }
%class.R3Matrix = type { [3 x [3 x double]] }

@stderr = external global ptr, align 8
@.str.47 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.76 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.77 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #0

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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK6R2Grid12WritePNGFileEPKc(ptr noundef nonnull align 8 dereferenceable(208) %0, ptr noundef %1) #4 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca double, align 8
  %16 = alloca i32, align 4
  %17 = alloca ptr, align 8
  %18 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %19 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = call noalias ptr @fopen(ptr noundef %20, ptr noundef @.str.47)
  store ptr %21, ptr %6, align 8, !tbaa !5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %28

24:                                               ; preds = %2
  %25 = load ptr, ptr @stderr, align 8, !tbaa !5
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef @.str.76, ptr noundef %26) #6
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %150

28:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %29 = call noalias ptr @png_create_write_struct(ptr noundef @.str.77, ptr noundef null, ptr noundef null, ptr noundef null)
  store ptr %29, ptr %8, align 8, !tbaa !5
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = icmp eq ptr %30, null
  br i1 %31, label %32, label %35

32:                                               ; preds = %28
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = call i32 @fclose(ptr noundef %33)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %149

35:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = call noalias ptr @png_create_info_struct(ptr noundef %36)
  store ptr %37, ptr %9, align 8, !tbaa !5
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = icmp eq ptr %38, null
  br i1 %39, label %40, label %43

40:                                               ; preds = %35
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = call i32 @fclose(ptr noundef %41)
  call void @png_destroy_write_struct(ptr noundef %8, ptr noundef null)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %148

43:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %44 = getelementptr inbounds %class.R2Grid, ptr %19, i32 0, i32 4
  %45 = getelementptr inbounds [2 x i32], ptr %44, i64 0, i64 0
  %46 = load i32, ptr %45, align 8, !tbaa !9
  store i32 %46, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  %47 = getelementptr inbounds %class.R2Grid, ptr %19, i32 0, i32 4
  %48 = getelementptr inbounds [2 x i32], ptr %47, i64 0, i64 1
  %49 = load i32, ptr %48, align 4, !tbaa !9
  store i32 %49, ptr %11, align 4, !tbaa !9
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = load i32, ptr %10, align 4, !tbaa !9
  %53 = load i32, ptr %11, align 4, !tbaa !9
  call void @png_set_IHDR(ptr noundef %50, ptr noundef %51, i32 noundef %52, i32 noundef %53, i32 noundef 16, i32 noundef 0, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  %54 = getelementptr inbounds %class.R2Grid, ptr %19, i32 0, i32 6
  %55 = load i32, ptr %54, align 4, !tbaa !11
  %56 = mul nsw i32 2, %55
  %57 = sext i32 %56 to i64
  %58 = call noalias noundef nonnull ptr @_Znam(i64 noundef %57) #7
  store ptr %58, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #6
  %59 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %59, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #6
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %60

60:                                               ; preds = %99, %43
  %61 = load i32, ptr %14, align 4, !tbaa !9
  %62 = getelementptr inbounds %class.R2Grid, ptr %19, i32 0, i32 6
  %63 = load i32, ptr %62, align 4, !tbaa !11
  %64 = icmp slt i32 %61, %63
  br i1 %64, label %66, label %65

65:                                               ; preds = %60
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #6
  br label %102

66:                                               ; preds = %60
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #6
  %67 = getelementptr inbounds %class.R2Grid, ptr %19, i32 0, i32 3
  %68 = load ptr, ptr %67, align 8, !tbaa !17
  %69 = load i32, ptr %14, align 4, !tbaa !9
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds double, ptr %68, i64 %70
  %72 = load double, ptr %71, align 8, !tbaa !18
  store double %72, ptr %15, align 8, !tbaa !18
  %73 = load double, ptr %15, align 8, !tbaa !18
  %74 = fcmp oeq double %73, -3.210000e+02
  br i1 %74, label %75, label %80

75:                                               ; preds = %66
  %76 = load ptr, ptr %13, align 8, !tbaa !5
  %77 = getelementptr inbounds i8, ptr %76, i32 1
  store ptr %77, ptr %13, align 8, !tbaa !5
  store i8 0, ptr %76, align 1, !tbaa !19
  %78 = load ptr, ptr %13, align 8, !tbaa !5
  %79 = getelementptr inbounds i8, ptr %78, i32 1
  store ptr %79, ptr %13, align 8, !tbaa !5
  store i8 0, ptr %78, align 1, !tbaa !19
  br label %98

80:                                               ; preds = %66
  %81 = load double, ptr %15, align 8, !tbaa !18
  %82 = fcmp ogt double %81, 6.553500e+04
  br i1 %82, label %83, label %84

83:                                               ; preds = %80
  store double 6.553500e+04, ptr %15, align 8, !tbaa !18
  br label %84

84:                                               ; preds = %83, %80
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #6
  %85 = load double, ptr %15, align 8, !tbaa !18
  %86 = fptoui double %85 to i32
  store i32 %86, ptr %16, align 4, !tbaa !9
  %87 = load i32, ptr %16, align 4, !tbaa !9
  %88 = lshr i32 %87, 8
  %89 = and i32 %88, 255
  %90 = trunc i32 %89 to i8
  %91 = load ptr, ptr %13, align 8, !tbaa !5
  %92 = getelementptr inbounds i8, ptr %91, i32 1
  store ptr %92, ptr %13, align 8, !tbaa !5
  store i8 %90, ptr %91, align 1, !tbaa !19
  %93 = load i32, ptr %16, align 4, !tbaa !9
  %94 = and i32 %93, 255
  %95 = trunc i32 %94 to i8
  %96 = load ptr, ptr %13, align 8, !tbaa !5
  %97 = getelementptr inbounds i8, ptr %96, i32 1
  store ptr %97, ptr %13, align 8, !tbaa !5
  store i8 %95, ptr %96, align 1, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #6
  br label %98

98:                                               ; preds = %84, %75
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #6
  br label %99

99:                                               ; preds = %98
  %100 = load i32, ptr %14, align 4, !tbaa !9
  %101 = add nsw i32 %100, 1
  store i32 %101, ptr %14, align 4, !tbaa !9
  br label %60, !llvm.loop !20

102:                                              ; preds = %65
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #6
  %103 = load ptr, ptr %8, align 8, !tbaa !5
  %104 = load i32, ptr %11, align 4, !tbaa !9
  %105 = sext i32 %104 to i64
  %106 = mul i64 %105, 8
  %107 = call noalias ptr @png_malloc(ptr noundef %103, i64 noundef %106)
  store ptr %107, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #6
  store i32 0, ptr %18, align 4, !tbaa !9
  br label %108

108:                                              ; preds = %128, %102
  %109 = load i32, ptr %18, align 4, !tbaa !9
  %110 = load i32, ptr %11, align 4, !tbaa !9
  %111 = icmp slt i32 %109, %110
  br i1 %111, label %113, label %112

112:                                              ; preds = %108
  store i32 5, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #6
  br label %131

113:                                              ; preds = %108
  %114 = load ptr, ptr %12, align 8, !tbaa !5
  %115 = load i32, ptr %11, align 4, !tbaa !9
  %116 = load i32, ptr %18, align 4, !tbaa !9
  %117 = sub nsw i32 %115, %116
  %118 = sub nsw i32 %117, 1
  %119 = mul nsw i32 %118, 2
  %120 = load i32, ptr %10, align 4, !tbaa !9
  %121 = mul nsw i32 %119, %120
  %122 = sext i32 %121 to i64
  %123 = getelementptr inbounds i8, ptr %114, i64 %122
  %124 = load ptr, ptr %17, align 8, !tbaa !5
  %125 = load i32, ptr %18, align 4, !tbaa !9
  %126 = sext i32 %125 to i64
  %127 = getelementptr inbounds ptr, ptr %124, i64 %126
  store ptr %123, ptr %127, align 8, !tbaa !5
  br label %128

128:                                              ; preds = %113
  %129 = load i32, ptr %18, align 4, !tbaa !9
  %130 = add nsw i32 %129, 1
  store i32 %130, ptr %18, align 4, !tbaa !9
  br label %108, !llvm.loop !22

131:                                              ; preds = %112
  %132 = load ptr, ptr %8, align 8, !tbaa !5
  %133 = load ptr, ptr %6, align 8, !tbaa !5
  call void @png_init_io(ptr noundef %132, ptr noundef %133)
  %134 = load ptr, ptr %8, align 8, !tbaa !5
  %135 = load ptr, ptr %9, align 8, !tbaa !5
  call void @png_write_info(ptr noundef %134, ptr noundef %135)
  %136 = load ptr, ptr %8, align 8, !tbaa !5
  %137 = load ptr, ptr %17, align 8, !tbaa !5
  call void @png_write_image(ptr noundef %136, ptr noundef %137)
  %138 = load ptr, ptr %8, align 8, !tbaa !5
  %139 = load ptr, ptr %9, align 8, !tbaa !5
  call void @png_write_end(ptr noundef %138, ptr noundef %139)
  %140 = load ptr, ptr %8, align 8, !tbaa !5
  %141 = load ptr, ptr %17, align 8, !tbaa !5
  call void @png_free(ptr noundef %140, ptr noundef %141)
  call void @png_destroy_write_struct(ptr noundef %8, ptr noundef %9)
  %142 = load ptr, ptr %12, align 8, !tbaa !5
  %143 = icmp eq ptr %142, null
  br i1 %143, label %145, label %144

144:                                              ; preds = %131
  call void @_ZdaPv(ptr noundef %142) #8
  br label %145

145:                                              ; preds = %144, %131
  %146 = load ptr, ptr %6, align 8, !tbaa !5
  %147 = call i32 @fclose(ptr noundef %146)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  br label %148

148:                                              ; preds = %145, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  br label %149

149:                                              ; preds = %148, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  br label %150

150:                                              ; preds = %149, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %151 = load i32, ptr %3, align 4
  ret i32 %151
}

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

declare i32 @fclose(ptr noundef) #5

declare noalias ptr @png_create_info_struct(ptr noundef) #5

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

declare noalias ptr @png_malloc(ptr noundef, i64 noundef) #5

declare void @png_free(ptr noundef, ptr noundef) #5

declare noalias ptr @png_create_write_struct(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #5

declare void @png_destroy_write_struct(ptr noundef, ptr noundef) #5

declare void @png_set_IHDR(ptr noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #5

declare void @png_write_info(ptr noundef, ptr noundef) #5

declare void @png_write_image(ptr noundef, ptr noundef) #5

declare void @png_write_end(ptr noundef, ptr noundef) #5

attributes #0 = { nobuiltin allocsize(0) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nobuiltin 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 = { 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 = { "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 = { builtin allocsize(0) }
attributes #8 = { builtin nounwind }

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

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


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str.47 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.76 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.77 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #0

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

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

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZNK6R2Grid12WritePNGFileEPKc(ptr nocapture noundef nonnull readonly align 8 dereferenceable(208) %0, ptr noundef %1) local_unnamed_addr #4 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = tail call noalias ptr @fopen(ptr noundef %1, ptr noundef nonnull @.str.47)
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %10

7:                                                ; preds = %2
  %8 = load ptr, ptr @stderr, align 8, !tbaa !5
  %9 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef nonnull @.str.76, ptr noundef %1) #6
  br label %94

10:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #7
  %11 = tail call noalias ptr @png_create_write_struct(ptr noundef nonnull @.str.77, ptr noundef null, ptr noundef null, ptr noundef null)
  store ptr %11, ptr %3, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %15

13:                                               ; preds = %10
  %14 = tail call i32 @fclose(ptr noundef nonnull %5)
  br label %93

15:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #7
  %16 = tail call noalias ptr @png_create_info_struct(ptr noundef nonnull %11)
  store ptr %16, ptr %4, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %20

18:                                               ; preds = %15
  %19 = tail call i32 @fclose(ptr noundef nonnull %5)
  call void @png_destroy_write_struct(ptr noundef nonnull %3, ptr noundef null)
  br label %92

20:                                               ; preds = %15
  %21 = getelementptr inbounds i8, ptr %0, i64 192
  %22 = load i32, ptr %21, align 8, !tbaa !9
  %23 = getelementptr inbounds i8, ptr %0, i64 196
  %24 = load i32, ptr %23, align 4, !tbaa !9
  tail call void @png_set_IHDR(ptr noundef nonnull %11, ptr noundef nonnull %16, i32 noundef %22, i32 noundef %24, i32 noundef 16, i32 noundef 0, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  %25 = getelementptr inbounds i8, ptr %0, i64 204
  %26 = load i32, ptr %25, align 4, !tbaa !11
  %27 = shl nsw i32 %26, 1
  %28 = sext i32 %27 to i64
  %29 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %28) #8
  %30 = icmp sgt i32 %26, 0
  br i1 %30, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %20
  %31 = getelementptr inbounds i8, ptr %0, i64 184
  %32 = load ptr, ptr %31, align 8, !tbaa !17
  %wide.trip.count = zext nneg i32 %26 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %33 = icmp eq i32 %26, 1
  br i1 %33, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %61

._crit_edge.loopexit.unr-lcssa:                   ; preds = %82, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %82 ]
  %.03945.unr = phi ptr [ %29, %.lr.ph ], [ %.140.1, %82 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa
  %34 = getelementptr inbounds double, ptr %32, i64 %indvars.iv.unr
  %35 = load double, ptr %34, align 8, !tbaa !18
  %36 = fcmp oeq double %35, -3.210000e+02
  br i1 %36, label %._crit_edge.loopexit.epilog-lcssa, label %37

37:                                               ; preds = %.epil.preheader
  %38 = fcmp ogt double %35, 6.553500e+04
  %.037.epil = select i1 %38, double 6.553500e+04, double %35
  %39 = fptoui double %.037.epil to i32
  %40 = lshr i32 %39, 8
  %41 = trunc i32 %40 to i8
  %42 = trunc i32 %39 to i8
  br label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %37, %.epil.preheader
  %.sink57.epil = phi i8 [ %41, %37 ], [ 0, %.epil.preheader ]
  %.sink.epil = phi i8 [ %42, %37 ], [ 0, %.epil.preheader ]
  store i8 %.sink57.epil, ptr %.03945.unr, align 1
  %43 = getelementptr inbounds i8, ptr %.03945.unr, i64 1
  store i8 %.sink.epil, ptr %43, align 1
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %20
  %44 = sext i32 %24 to i64
  %45 = shl nsw i64 %44, 3
  %46 = tail call noalias ptr @png_malloc(ptr noundef nonnull %11, i64 noundef %45)
  %47 = icmp sgt i32 %24, 0
  br i1 %47, label %.lr.ph49, label %._crit_edge50

.lr.ph49:                                         ; preds = %._crit_edge
  %48 = shl i32 %22, 1
  %wide.trip.count55 = zext nneg i32 %24 to i64
  %min.iters.check = icmp ult i32 %24, 4
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph49
  %indvars.iv52.ph = phi i64 [ 0, %.lr.ph49 ], [ %n.vec, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.lr.ph49
  %n.vec = and i64 %wide.trip.count55, 2147483644
  %broadcast.splatinsert = insertelement <2 x i32> poison, i32 %24, i64 0
  %broadcast.splat = shufflevector <2 x i32> %broadcast.splatinsert, <2 x i32> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert59 = insertelement <2 x i32> poison, i32 %48, i64 0
  %broadcast.splat60 = shufflevector <2 x i32> %broadcast.splatinsert59, <2 x i32> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <2 x i32> [ <i32 0, i32 1>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %49 = xor <2 x i32> %vec.ind, <i32 -1, i32 -1>
  %50 = add <2 x i32> %broadcast.splat, %49
  %reass.sub = sub <2 x i32> %broadcast.splat, %vec.ind
  %51 = add <2 x i32> %reass.sub, <i32 -3, i32 -3>
  %52 = mul <2 x i32> %broadcast.splat60, %50
  %53 = mul <2 x i32> %broadcast.splat60, %51
  %54 = sext <2 x i32> %52 to <2 x i64>
  %55 = sext <2 x i32> %53 to <2 x i64>
  %56 = getelementptr inbounds i8, ptr %29, <2 x i64> %54
  %57 = getelementptr inbounds i8, ptr %29, <2 x i64> %55
  %58 = getelementptr inbounds ptr, ptr %46, i64 %index
  %59 = getelementptr inbounds i8, ptr %58, i64 16
  store <2 x ptr> %56, ptr %58, align 8, !tbaa !5
  store <2 x ptr> %57, ptr %59, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %vec.ind.next = add <2 x i32> %vec.ind, <i32 4, i32 4>
  %60 = icmp eq i64 %index.next, %n.vec
  br i1 %60, label %middle.block, label %vector.body, !llvm.loop !19

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count55
  br i1 %cmp.n, label %._crit_edge50, label %scalar.ph.preheader

61:                                               ; preds = %82, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %82 ]
  %.03945 = phi ptr [ %29, %.lr.ph.new ], [ %.140.1, %82 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %82 ]
  %62 = getelementptr inbounds double, ptr %32, i64 %indvars.iv
  %63 = load double, ptr %62, align 8, !tbaa !18
  %64 = fcmp oeq double %63, -3.210000e+02
  br i1 %64, label %71, label %65

65:                                               ; preds = %61
  %66 = fcmp ogt double %63, 6.553500e+04
  %.037 = select i1 %66, double 6.553500e+04, double %63
  %67 = fptoui double %.037 to i32
  %68 = lshr i32 %67, 8
  %69 = trunc i32 %68 to i8
  %70 = trunc i32 %67 to i8
  br label %71

71:                                               ; preds = %61, %65
  %.sink57 = phi i8 [ %69, %65 ], [ 0, %61 ]
  %.sink = phi i8 [ %70, %65 ], [ 0, %61 ]
  store i8 %.sink57, ptr %.03945, align 1
  %72 = getelementptr inbounds i8, ptr %.03945, i64 1
  store i8 %.sink, ptr %72, align 1
  %.140 = getelementptr inbounds i8, ptr %.03945, i64 2
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %73 = getelementptr inbounds double, ptr %32, i64 %indvars.iv.next
  %74 = load double, ptr %73, align 8, !tbaa !18
  %75 = fcmp oeq double %74, -3.210000e+02
  br i1 %75, label %82, label %76

76:                                               ; preds = %71
  %77 = fcmp ogt double %74, 6.553500e+04
  %.037.1 = select i1 %77, double 6.553500e+04, double %74
  %78 = fptoui double %.037.1 to i32
  %79 = lshr i32 %78, 8
  %80 = trunc i32 %79 to i8
  %81 = trunc i32 %78 to i8
  br label %82

82:                                               ; preds = %76, %71
  %.sink57.1 = phi i8 [ %80, %76 ], [ 0, %71 ]
  %.sink.1 = phi i8 [ %81, %76 ], [ 0, %71 ]
  store i8 %.sink57.1, ptr %.140, align 1
  %83 = getelementptr inbounds i8, ptr %.03945, i64 3
  store i8 %.sink.1, ptr %83, align 1
  %.140.1 = getelementptr inbounds i8, ptr %.03945, i64 4
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %61, !llvm.loop !23

._crit_edge50:                                    ; preds = %scalar.ph, %middle.block, %._crit_edge
  tail call void @png_init_io(ptr noundef nonnull %11, ptr noundef nonnull %5)
  tail call void @png_write_info(ptr noundef nonnull %11, ptr noundef nonnull %16)
  tail call void @png_write_image(ptr noundef nonnull %11, ptr noundef %46)
  tail call void @png_write_end(ptr noundef nonnull %11, ptr noundef nonnull %16)
  tail call void @png_free(ptr noundef nonnull %11, ptr noundef %46)
  call void @png_destroy_write_struct(ptr noundef nonnull %3, ptr noundef nonnull %4)
  call void @_ZdaPv(ptr noundef nonnull %29) #9
  %84 = call i32 @fclose(ptr noundef nonnull %5)
  br label %92

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv52 = phi i64 [ %indvars.iv.next53, %scalar.ph ], [ %indvars.iv52.ph, %scalar.ph.preheader ]
  %85 = trunc i64 %indvars.iv52 to i32
  %86 = xor i32 %85, -1
  %87 = add i32 %24, %86
  %88 = mul i32 %48, %87
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds i8, ptr %29, i64 %89
  %91 = getelementptr inbounds ptr, ptr %46, i64 %indvars.iv52
  store ptr %90, ptr %91, align 8, !tbaa !5
  %indvars.iv.next53 = add nuw nsw i64 %indvars.iv52, 1
  %exitcond56.not = icmp eq i64 %indvars.iv.next53, %wide.trip.count55
  br i1 %exitcond56.not, label %._crit_edge50, label %scalar.ph, !llvm.loop !24

92:                                               ; preds = %._crit_edge50, %18
  %.036 = phi i32 [ 0, %18 ], [ 1, %._crit_edge50 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #7
  br label %93

93:                                               ; preds = %92, %13
  %.1 = phi i32 [ 0, %13 ], [ %.036, %92 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #7
  br label %94

94:                                               ; preds = %93, %7
  %.2 = phi i32 [ 0, %7 ], [ %.1, %93 ]
  ret i32 %.2
}

; 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

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

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

declare noalias ptr @png_malloc(ptr noundef, i64 noundef) local_unnamed_addr #5

declare void @png_free(ptr noundef, ptr noundef) local_unnamed_addr #5

declare noalias ptr @png_create_write_struct(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #5

declare void @png_destroy_write_struct(ptr noundef, ptr noundef) local_unnamed_addr #5

declare void @png_set_IHDR(ptr noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #5

declare void @png_write_info(ptr noundef, ptr noundef) local_unnamed_addr #5

declare void @png_write_image(ptr noundef, ptr noundef) local_unnamed_addr #5

declare void @png_write_end(ptr noundef, ptr noundef) local_unnamed_addr #5

attributes #0 = { nobuiltin allocsize(0) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nobuiltin 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 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 = { "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 = { cold nounwind }
attributes #7 = { nounwind }
attributes #8 = { builtin allocsize(0) }
attributes #9 = { builtin nounwind }

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

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 204}
!12 = !{!"_ZTS6R2Grid", !13, i64 0, !13, i64 88, !16, i64 176, !6, i64 184, !7, i64 192, !10, i64 200, !10, i64 204}
!13 = !{!"_ZTS8R2Affine", !14, i64 0, !15, i64 8, !10, i64 80}
!14 = !{!"_ZTS16R2Transformation"}
!15 = !{!"_ZTS8R3Matrix", !7, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = !{!12, !6, i64 184}
!18 = !{!16, !16, i64 0}
!19 = distinct !{!19, !20, !21, !22}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!"llvm.loop.isvectorized", i32 1}
!22 = !{!"llvm.loop.unroll.runtime.disable"}
!23 = distinct !{!23, !20}
!24 = distinct !{!24, !20, !22, !21}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass