; LLVM IR from cornell-zhang/rosetta :: optical-flow/imageLib/ImageIO.ll (Z12WriteFileTGA6CImagePKc)

; 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.CShape = type { i32, i32, i32 }
%struct.CTargaHead = type { i8, i8, i8, [2 x i8], [2 x i8], i8, i16, i16, i16, i16, i8, i8 }

@_ZTI6CError = external dso_local constant { ptr, ptr, ptr }, align 8
@.str.8 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [37 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 noalias ptr @fopen(ptr noundef, ptr noundef) #1

declare ptr @__cxa_allocate_exception(i64)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6CErrorC2EPKcS1_(ptr noundef nonnull align 8 dereferenceable(1032), ptr noundef, ptr noundef) unnamed_addr #2 align 2

declare i32 @__gxx_personality_v0(...)

declare void @__cxa_free_exception(ptr)

; Function Attrs: nounwind
declare void @_ZNSt9exceptionD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #3

declare void @__cxa_throw(ptr, ptr, ptr)

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

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

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

declare i32 @fclose(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z12WriteFileTGA6CImagePKc(ptr noundef %0, ptr noundef %1) #6 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.CShape, align 4
  %6 = alloca { i64, i32 }, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca %struct.CTargaHead, align 2
  %11 = alloca i8, align 1
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 12, ptr %5) #8
  %17 = call { i64, i32 } @_ZN6CImage5ShapeEv(ptr noundef nonnull align 8 dereferenceable(76) %0)
  store { i64, i32 } %17, ptr %6, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %5, ptr align 8 %6, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #8
  %18 = getelementptr inbounds %struct.CShape, ptr %5, i32 0, i32 2
  %19 = load i32, ptr %18, align 4, !tbaa !9
  store i32 %19, ptr %7, align 4, !tbaa !12
  %20 = load i32, ptr %7, align 4, !tbaa !12
  %21 = icmp ne i32 %20, 1
  br i1 %21, label %22, label %36

22:                                               ; preds = %2
  %23 = load i32, ptr %7, align 4, !tbaa !12
  %24 = icmp ne i32 %23, 3
  br i1 %24, label %25, label %36

25:                                               ; preds = %22
  %26 = load i32, ptr %7, align 4, !tbaa !12
  %27 = icmp ne i32 %26, 4
  br i1 %27, label %28, label %36

28:                                               ; preds = %25
  %29 = call ptr @__cxa_allocate_exception(i64 1032) #8
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  invoke void @_ZN6CErrorC2EPKcS1_(ptr noundef nonnull align 8 dereferenceable(1032) %29, ptr noundef @.str.8, ptr noundef %30)
          to label %31 unwind label %32

31:                                               ; preds = %28
  call void @__cxa_throw(ptr %29, ptr @_ZTI6CError, ptr @_ZNSt9exceptionD2Ev) #9
  unreachable

32:                                               ; preds = %28
  %33 = landingpad { ptr, i32 }
          cleanup
  %34 = extractvalue { ptr, i32 } %33, 0
  store ptr %34, ptr %8, align 8
  %35 = extractvalue { ptr, i32 } %33, 1
  store i32 %35, ptr %9, align 4
  call void @__cxa_free_exception(ptr %29) #8
  br label %140

36:                                               ; preds = %25, %22, %2
  call void @llvm.lifetime.start.p0(i64 18, ptr %10) #8
  call void @llvm.memset.p0.i64(ptr align 2 %10, i8 0, i64 18, i1 false)
  %37 = load i32, ptr %7, align 4, !tbaa !12
  %38 = icmp eq i32 %37, 1
  %39 = zext i1 %38 to i64
  %40 = select i1 %38, i32 3, i32 2
  %41 = trunc i32 %40 to i8
  %42 = getelementptr inbounds %struct.CTargaHead, ptr %10, i32 0, i32 2
  store i8 %41, ptr %42, align 2, !tbaa !13
  %43 = getelementptr inbounds %struct.CShape, ptr %5, i32 0, i32 0
  %44 = load i32, ptr %43, align 4, !tbaa !16
  %45 = trunc i32 %44 to i16
  %46 = getelementptr inbounds %struct.CTargaHead, ptr %10, i32 0, i32 8
  store i16 %45, ptr %46, align 2, !tbaa !17
  %47 = getelementptr inbounds %struct.CShape, ptr %5, i32 0, i32 1
  %48 = load i32, ptr %47, align 4, !tbaa !18
  %49 = trunc i32 %48 to i16
  %50 = getelementptr inbounds %struct.CTargaHead, ptr %10, i32 0, i32 9
  store i16 %49, ptr %50, align 2, !tbaa !19
  %51 = load i32, ptr %7, align 4, !tbaa !12
  %52 = mul nsw i32 8, %51
  %53 = trunc i32 %52 to i8
  %54 = getelementptr inbounds %struct.CTargaHead, ptr %10, i32 0, i32 10
  store i8 %53, ptr %54, align 2, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #8
  store i8 0, ptr %11, align 1, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #8
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = call noalias ptr @fopen(ptr noundef %55, ptr noundef @.str.9)
  store ptr %56, ptr %12, align 8, !tbaa !5
  %57 = load ptr, ptr %12, align 8, !tbaa !5
  %58 = icmp eq ptr %57, null
  br i1 %58, label %59, label %67

59:                                               ; preds = %36
  %60 = call ptr @__cxa_allocate_exception(i64 1032) #8
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  invoke void @_ZN6CErrorC2EPKcS1_(ptr noundef nonnull align 8 dereferenceable(1032) %60, ptr noundef @.str.10, ptr noundef %61)
          to label %62 unwind label %63

62:                                               ; preds = %59
  call void @__cxa_throw(ptr %60, ptr @_ZTI6CError, ptr @_ZNSt9exceptionD2Ev) #9
  unreachable

63:                                               ; preds = %59
  %64 = landingpad { ptr, i32 }
          cleanup
  %65 = extractvalue { ptr, i32 } %64, 0
  store ptr %65, ptr %8, align 8
  %66 = extractvalue { ptr, i32 } %64, 1
  store i32 %66, ptr %9, align 4
  call void @__cxa_free_exception(ptr %60) #8
  br label %139

67:                                               ; preds = %36
  %68 = load ptr, ptr %12, align 8, !tbaa !5
  %69 = call i64 @fwrite(ptr noundef %10, i64 noundef 18, i64 noundef 1, ptr noundef %68)
  %70 = icmp ne i64 %69, 1
  br i1 %70, label %71, label %79

71:                                               ; preds = %67
  %72 = call ptr @__cxa_allocate_exception(i64 1032) #8
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  invoke void @_ZN6CErrorC2EPKcS1_(ptr noundef nonnull align 8 dereferenceable(1032) %72, ptr noundef @.str.11, ptr noundef %73)
          to label %74 unwind label %75

74:                                               ; preds = %71
  call void @__cxa_throw(ptr %72, ptr @_ZTI6CError, ptr @_ZNSt9exceptionD2Ev) #9
  unreachable

75:                                               ; preds = %71
  %76 = landingpad { ptr, i32 }
          cleanup
  %77 = extractvalue { ptr, i32 } %76, 0
  store ptr %77, ptr %8, align 8
  %78 = extractvalue { ptr, i32 } %76, 1
  store i32 %78, ptr %9, align 4
  call void @__cxa_free_exception(ptr %72) #8
  br label %139

79:                                               ; preds = %67
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #8
  store i32 0, ptr %13, align 4, !tbaa !12
  br label %80

80:                                               ; preds = %123, %79
  %81 = load i32, ptr %13, align 4, !tbaa !12
  %82 = getelementptr inbounds %struct.CShape, ptr %5, i32 0, i32 1
  %83 = load i32, ptr %82, align 4, !tbaa !18
  %84 = icmp slt i32 %81, %83
  br i1 %84, label %86, label %85

85:                                               ; preds = %80
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #8
  br label %126

86:                                               ; preds = %80
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #8
  %87 = load i8, ptr %11, align 1, !tbaa !21, !range !23, !noundef !24
  %88 = trunc i8 %87 to i1
  br i1 %88, label %89, label %95

89:                                               ; preds = %86
  %90 = getelementptr inbounds %struct.CShape, ptr %5, i32 0, i32 1
  %91 = load i32, ptr %90, align 4, !tbaa !18
  %92 = sub nsw i32 %91, 1
  %93 = load i32, ptr %13, align 4, !tbaa !12
  %94 = sub nsw i32 %92, %93
  br label %97

95:                                               ; preds = %86
  %96 = load i32, ptr %13, align 4, !tbaa !12
  br label %97

97:                                               ; preds = %95, %89
  %98 = phi i32 [ %94, %89 ], [ %96, %95 ]
  store i32 %98, ptr %14, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #8
  %99 = load i32, ptr %14, align 4, !tbaa !12
  %100 = call noundef ptr @_ZN6CImage12PixelAddressEiii(ptr noundef nonnull align 8 dereferenceable(76) %0, i32 noundef 0, i32 noundef %99, i32 noundef 0)
  store ptr %100, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #8
  %101 = getelementptr inbounds %struct.CShape, ptr %5, i32 0, i32 0
  %102 = load i32, ptr %101, align 4, !tbaa !16
  %103 = getelementptr inbounds %struct.CShape, ptr %5, i32 0, i32 2
  %104 = load i32, ptr %103, align 4, !tbaa !9
  %105 = mul nsw i32 %102, %104
  store i32 %105, ptr %16, align 4, !tbaa !12
  %106 = load ptr, ptr %15, align 8, !tbaa !5
  %107 = load i32, ptr %16, align 4, !tbaa !12
  %108 = sext i32 %107 to i64
  %109 = load ptr, ptr %12, align 8, !tbaa !5
  %110 = call i64 @fwrite(ptr noundef %106, i64 noundef 1, i64 noundef %108, ptr noundef %109)
  %111 = trunc i64 %110 to i32
  %112 = load i32, ptr %16, align 4, !tbaa !12
  %113 = icmp ne i32 %111, %112
  br i1 %113, label %114, label %122

114:                                              ; preds = %97
  %115 = call ptr @__cxa_allocate_exception(i64 1032) #8
  %116 = load ptr, ptr %4, align 8, !tbaa !5
  invoke void @_ZN6CErrorC2EPKcS1_(ptr noundef nonnull align 8 dereferenceable(1032) %115, ptr noundef @.str.11, ptr noundef %116)
          to label %117 unwind label %118

117:                                              ; preds = %114
  call void @__cxa_throw(ptr %115, ptr @_ZTI6CError, ptr @_ZNSt9exceptionD2Ev) #9
  unreachable

118:                                              ; preds = %114
  %119 = landingpad { ptr, i32 }
          cleanup
  %120 = extractvalue { ptr, i32 } %119, 0
  store ptr %120, ptr %8, align 8
  %121 = extractvalue { ptr, i32 } %119, 1
  store i32 %121, ptr %9, align 4
  call void @__cxa_free_exception(ptr %115) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #8
  br label %139

122:                                              ; preds = %97
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #8
  br label %123

123:                                              ; preds = %122
  %124 = load i32, ptr %13, align 4, !tbaa !12
  %125 = add nsw i32 %124, 1
  store i32 %125, ptr %13, align 4, !tbaa !12
  br label %80, !llvm.loop !25

126:                                              ; preds = %85
  %127 = load ptr, ptr %12, align 8, !tbaa !5
  %128 = call i32 @fclose(ptr noundef %127)
  %129 = icmp ne i32 %128, 0
  br i1 %129, label %130, label %138

130:                                              ; preds = %126
  %131 = call ptr @__cxa_allocate_exception(i64 1032) #8
  %132 = load ptr, ptr %4, align 8, !tbaa !5
  invoke void @_ZN6CErrorC2EPKcS1_(ptr noundef nonnull align 8 dereferenceable(1032) %131, ptr noundef @.str.12, ptr noundef %132)
          to label %133 unwind label %134

133:                                              ; preds = %130
  call void @__cxa_throw(ptr %131, ptr @_ZTI6CError, ptr @_ZNSt9exceptionD2Ev) #9
  unreachable

134:                                              ; preds = %130
  %135 = landingpad { ptr, i32 }
          cleanup
  %136 = extractvalue { ptr, i32 } %135, 0
  store ptr %136, ptr %8, align 8
  %137 = extractvalue { ptr, i32 } %135, 1
  store i32 %137, ptr %9, align 4
  call void @__cxa_free_exception(ptr %131) #8
  br label %139

138:                                              ; preds = %126
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #8
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #8
  call void @llvm.lifetime.end.p0(i64 18, ptr %10) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #8
  call void @llvm.lifetime.end.p0(i64 12, ptr %5) #8
  ret void

139:                                              ; preds = %134, %118, %75, %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #8
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #8
  call void @llvm.lifetime.end.p0(i64 18, ptr %10) #8
  br label %140

140:                                              ; preds = %139, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #8
  call void @llvm.lifetime.end.p0(i64 12, ptr %5) #8
  br label %141

141:                                              ; preds = %140
  %142 = load ptr, ptr %8, align 8
  %143 = load i32, ptr %9, align 4
  %144 = insertvalue { ptr, i32 } poison, ptr %142, 0
  %145 = insertvalue { ptr, i32 } %144, i32 %143, 1
  resume { ptr, i32 } %145
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { i64, i32 } @_ZN6CImage5ShapeEv(ptr noundef nonnull align 8 dereferenceable(76)) #2 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #7

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

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

!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, !11, i64 8}
!10 = !{!"_ZTS6CShape", !11, i64 0, !11, i64 4, !11, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !7, i64 2}
!14 = !{!"_ZTS10CTargaHead", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 5, !7, i64 7, !15, i64 8, !15, i64 10, !15, i64 12, !15, i64 14, !7, i64 16, !7, i64 17}
!15 = !{!"short", !7, i64 0}
!16 = !{!10, !11, i64 0}
!17 = !{!14, !15, i64 12}
!18 = !{!10, !11, i64 4}
!19 = !{!14, !15, i64 14}
!20 = !{!14, !7, i64 16}
!21 = !{!22, !22, i64 0}
!22 = !{!"bool", !7, i64 0}
!23 = !{i8 0, i8 2}
!24 = !{}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}


; 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.CTargaHead = type { i8, i8, i8, [2 x i8], [2 x i8], i8, i16, i16, i16, i16, i8, i8 }

@_ZTI6CError = external dso_local constant { ptr, ptr, ptr }, align 8
@.str.8 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [37 x i8], align 1

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

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

declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6CErrorC2EPKcS1_(ptr noundef nonnull align 8 dereferenceable(1032), ptr noundef, ptr noundef) unnamed_addr #2 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind
declare void @_ZNSt9exceptionD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #3

declare void @__cxa_throw(ptr, ptr, ptr) local_unnamed_addr

; Function Attrs: mustprogress 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 @_ZN6CImage12PixelAddressEiii(ptr noundef nonnull align 8 dereferenceable(76), i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #4 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z12WriteFileTGA6CImagePKc(ptr noundef nonnull %0, ptr noundef %1) local_unnamed_addr #5 personality ptr @__gxx_personality_v0 {
  %3 = alloca %struct.CTargaHead, align 2
  %4 = tail call { i64, i32 } @_ZN6CImage5ShapeEv(ptr noundef nonnull align 8 dereferenceable(76) %0)
  %.fca.1.extract = extractvalue { i64, i32 } %4, 1
  switch i32 %.fca.1.extract, label %5 [
    i32 4, label %7
    i32 3, label %7
    i32 1, label %7
  ]

5:                                                ; preds = %2
  %6 = tail call ptr @__cxa_allocate_exception(i64 1032) #7
  tail call void @_ZN6CErrorC2EPKcS1_(ptr noundef nonnull align 8 dereferenceable(1032) %6, ptr noundef nonnull @.str.8, ptr noundef %1)
  tail call void @__cxa_throw(ptr nonnull %6, ptr nonnull @_ZTI6CError, ptr nonnull @_ZNSt9exceptionD2Ev) #8
  unreachable

7:                                                ; preds = %2, %2, %2
  %.fca.0.extract = extractvalue { i64, i32 } %4, 0
  call void @llvm.lifetime.start.p0(i64 18, ptr nonnull %3) #7
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 2 dereferenceable(18) %3, i8 0, i64 18, i1 false)
  %8 = icmp eq i32 %.fca.1.extract, 1
  %9 = select i1 %8, i8 3, i8 2
  %10 = getelementptr inbounds i8, ptr %3, i64 2
  store i8 %9, ptr %10, align 2, !tbaa !5
  %.sroa.020.0.extract.trunc = trunc i64 %.fca.0.extract to i32
  %11 = trunc i64 %.fca.0.extract to i16
  %12 = getelementptr inbounds i8, ptr %3, i64 12
  store i16 %11, ptr %12, align 2, !tbaa !10
  %.sroa.020.4.extract.shift = lshr i64 %.fca.0.extract, 32
  %.sroa.020.4.extract.trunc = trunc nuw i64 %.sroa.020.4.extract.shift to i32
  %13 = trunc i64 %.sroa.020.4.extract.shift to i16
  %14 = getelementptr inbounds i8, ptr %3, i64 14
  store i16 %13, ptr %14, align 2, !tbaa !11
  %.fca.1.extract.tr = trunc nuw i32 %.fca.1.extract to i8
  %15 = shl nuw nsw i8 %.fca.1.extract.tr, 3
  %16 = getelementptr inbounds i8, ptr %3, i64 16
  store i8 %15, ptr %16, align 2, !tbaa !12
  %17 = tail call noalias ptr @fopen(ptr noundef %1, ptr noundef nonnull @.str.9)
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %21

19:                                               ; preds = %7
  %20 = tail call ptr @__cxa_allocate_exception(i64 1032) #7
  tail call void @_ZN6CErrorC2EPKcS1_(ptr noundef nonnull align 8 dereferenceable(1032) %20, ptr noundef nonnull @.str.10, ptr noundef %1)
  tail call void @__cxa_throw(ptr nonnull %20, ptr nonnull @_ZTI6CError, ptr nonnull @_ZNSt9exceptionD2Ev) #8
  unreachable

21:                                               ; preds = %7
  %22 = call i64 @fwrite(ptr noundef nonnull %3, i64 noundef 18, i64 noundef 1, ptr noundef nonnull %17)
  %.not = icmp eq i64 %22, 1
  br i1 %.not, label %.preheader, label %26

.preheader:                                       ; preds = %21
  %23 = icmp sgt i32 %.sroa.020.4.extract.trunc, 0
  br i1 %23, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %24 = mul nsw i32 %.fca.1.extract, %.sroa.020.0.extract.trunc
  %25 = sext i32 %24 to i64
  br label %31

26:                                               ; preds = %21
  %27 = tail call ptr @__cxa_allocate_exception(i64 1032) #7
  tail call void @_ZN6CErrorC2EPKcS1_(ptr noundef nonnull align 8 dereferenceable(1032) %27, ptr noundef nonnull @.str.11, ptr noundef %1)
  tail call void @__cxa_throw(ptr nonnull %27, ptr nonnull @_ZTI6CError, ptr nonnull @_ZNSt9exceptionD2Ev) #8
  unreachable

28:                                               ; preds = %31
  %29 = add nuw nsw i32 %.039, 1
  %exitcond.not = icmp eq i32 %29, %.sroa.020.4.extract.trunc
  br i1 %exitcond.not, label %._crit_edge, label %31, !llvm.loop !13

._crit_edge:                                      ; preds = %28, %.preheader
  %30 = tail call i32 @fclose(ptr noundef nonnull %17)
  %.not37 = icmp eq i32 %30, 0
  br i1 %.not37, label %39, label %37

31:                                               ; preds = %.lr.ph, %28
  %.039 = phi i32 [ 0, %.lr.ph ], [ %29, %28 ]
  %32 = tail call noundef ptr @_ZN6CImage12PixelAddressEiii(ptr noundef nonnull align 8 dereferenceable(76) %0, i32 noundef 0, i32 noundef %.039, i32 noundef 0)
  %33 = tail call i64 @fwrite(ptr noundef %32, i64 noundef 1, i64 noundef %25, ptr noundef nonnull %17)
  %34 = trunc i64 %33 to i32
  %.not38 = icmp eq i32 %24, %34
  br i1 %.not38, label %28, label %35

35:                                               ; preds = %31
  %36 = tail call ptr @__cxa_allocate_exception(i64 1032) #7
  tail call void @_ZN6CErrorC2EPKcS1_(ptr noundef nonnull align 8 dereferenceable(1032) %36, ptr noundef nonnull @.str.11, ptr noundef %1)
  tail call void @__cxa_throw(ptr nonnull %36, ptr nonnull @_ZTI6CError, ptr nonnull @_ZNSt9exceptionD2Ev) #8
  unreachable

37:                                               ; preds = %._crit_edge
  %38 = tail call ptr @__cxa_allocate_exception(i64 1032) #7
  tail call void @_ZN6CErrorC2EPKcS1_(ptr noundef nonnull align 8 dereferenceable(1032) %38, ptr noundef nonnull @.str.12, ptr noundef %1)
  tail call void @__cxa_throw(ptr nonnull %38, ptr nonnull @_ZTI6CError, ptr nonnull @_ZNSt9exceptionD2Ev) #8
  unreachable

39:                                               ; preds = %._crit_edge
  call void @llvm.lifetime.end.p0(i64 18, ptr nonnull %3) #7
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { i64, i32 } @_ZN6CImage5ShapeEv(ptr noundef nonnull align 8 dereferenceable(76)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #6

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

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

!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 2}
!6 = !{!"_ZTS10CTargaHead", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 5, !7, i64 7, !9, i64 8, !9, i64 10, !9, i64 12, !9, i64 14, !7, i64 16, !7, i64 17}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"short", !7, i64 0}
!10 = !{!6, !9, i64 12}
!11 = !{!6, !9, i64 14}
!12 = !{!6, !7, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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