; LLVM IR from CubbyFlow/RenderFlow :: Extensions/FlowEditor/sample_utils (file_tga)

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

@_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE4type = external hidden global [3 x i8], align 1
@_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE5dummy = external hidden global [9 x i8], align 1
@_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE4info = external hidden global [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1

declare i32 @fclose(ptr 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

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

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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKh(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef %5) #2 align 2 {
  %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 i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store i32 %2, ptr %10, align 4, !tbaa !9
  store i32 %3, ptr %11, align 4, !tbaa !9
  store i32 %4, ptr %12, align 4, !tbaa !11
  store ptr %5, ptr %13, align 8, !tbaa !5
  %17 = load ptr, ptr %8, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  store ptr null, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  store i32 0, ptr %15, align 4, !tbaa !9
  %18 = load ptr, ptr %9, align 8, !tbaa !5
  %19 = call noalias ptr @fopen(ptr noundef %18, ptr noundef @.str.1)
  store ptr %19, ptr %14, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %22, label %21

21:                                               ; preds = %6
  store i32 2, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %67

22:                                               ; preds = %6
  %23 = load ptr, ptr %14, align 8, !tbaa !5
  %24 = call i64 @fwrite(ptr noundef @_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE4type, i64 noundef 1, i64 noundef 3, ptr noundef %23)
  %25 = load ptr, ptr %14, align 8, !tbaa !5
  %26 = call i64 @fwrite(ptr noundef @_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE5dummy, i64 noundef 1, i64 noundef 9, ptr noundef %25)
  %27 = load i32, ptr %10, align 4, !tbaa !9
  %28 = and i32 %27, 255
  %29 = trunc i32 %28 to i8
  store i8 %29, ptr @_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE4info, align 1, !tbaa !13
  %30 = load i32, ptr %10, align 4, !tbaa !9
  %31 = ashr i32 %30, 8
  %32 = and i32 %31, 255
  %33 = trunc i32 %32 to i8
  store i8 %33, ptr getelementptr inbounds ([6 x i8], ptr @_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE4info, i64 0, i64 1), align 1, !tbaa !13
  %34 = load i32, ptr %11, align 4, !tbaa !9
  %35 = and i32 %34, 255
  %36 = trunc i32 %35 to i8
  store i8 %36, ptr getelementptr inbounds ([6 x i8], ptr @_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE4info, i64 0, i64 2), align 1, !tbaa !13
  %37 = load i32, ptr %11, align 4, !tbaa !9
  %38 = ashr i32 %37, 8
  %39 = and i32 %38, 255
  %40 = trunc i32 %39 to i8
  store i8 %40, ptr getelementptr inbounds ([6 x i8], ptr @_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE4info, i64 0, i64 3), align 1, !tbaa !13
  %41 = load i32, ptr %12, align 4, !tbaa !11
  switch i32 %41, label %45 [
    i32 6406, label %42
    i32 6407, label %43
    i32 6408, label %44
  ]

42:                                               ; preds = %22
  store i8 8, ptr getelementptr inbounds ([6 x i8], ptr @_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE4info, i64 0, i64 4), align 1, !tbaa !13
  br label %45

43:                                               ; preds = %22
  store i8 24, ptr getelementptr inbounds ([6 x i8], ptr @_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE4info, i64 0, i64 4), align 1, !tbaa !13
  br label %45

44:                                               ; preds = %22
  store i8 32, ptr getelementptr inbounds ([6 x i8], ptr @_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE4info, i64 0, i64 4), align 1, !tbaa !13
  br label %45

45:                                               ; preds = %44, %43, %42, %22
  %46 = load ptr, ptr %14, align 8, !tbaa !5
  %47 = call i64 @fwrite(ptr noundef @_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE4info, i64 noundef 1, i64 noundef 6, ptr noundef %46)
  %48 = load i32, ptr %10, align 4, !tbaa !9
  %49 = load i32, ptr %11, align 4, !tbaa !9
  %50 = mul nsw i32 %48, %49
  store i32 %50, ptr %15, align 4, !tbaa !9
  %51 = load i32, ptr %12, align 4, !tbaa !11
  switch i32 %51, label %64 [
    i32 6406, label %52
    i32 6407, label %56
    i32 6408, label %60
  ]

52:                                               ; preds = %45
  %53 = load ptr, ptr %14, align 8, !tbaa !5
  %54 = load ptr, ptr %13, align 8, !tbaa !5
  %55 = load i32, ptr %15, align 4, !tbaa !9
  call void @_ZN3TGA9writeGrayEP8_IO_FILEPKhi(ptr noundef nonnull align 8 dereferenceable(24) %17, ptr noundef %53, ptr noundef %54, i32 noundef %55)
  br label %64

56:                                               ; preds = %45
  %57 = load ptr, ptr %14, align 8, !tbaa !5
  %58 = load ptr, ptr %13, align 8, !tbaa !5
  %59 = load i32, ptr %15, align 4, !tbaa !9
  call void @_ZN3TGA14writeGrayAsRGBEP8_IO_FILEPKhi(ptr noundef nonnull align 8 dereferenceable(24) %17, ptr noundef %57, ptr noundef %58, i32 noundef %59)
  br label %64

60:                                               ; preds = %45
  %61 = load ptr, ptr %14, align 8, !tbaa !5
  %62 = load ptr, ptr %13, align 8, !tbaa !5
  %63 = load i32, ptr %15, align 4, !tbaa !9
  call void @_ZN3TGA9writeRGBAEP8_IO_FILEPKhi(ptr noundef nonnull align 8 dereferenceable(24) %17, ptr noundef %61, ptr noundef %62, i32 noundef %63)
  br label %64

64:                                               ; preds = %60, %56, %52, %45
  %65 = load ptr, ptr %14, align 8, !tbaa !5
  %66 = call i32 @fclose(ptr noundef %65)
  store i32 1, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %67

67:                                               ; preds = %64, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  %68 = load i32, ptr %7, align 4
  ret i32 %68
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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, !12, i64 0}
!12 = !{!"_ZTSN3TGA9TGAFormatE", !7, i64 0}
!13 = !{!7, !7, i64 0}


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

@_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE4type = external hidden global [3 x i8], align 1
@_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE5dummy = external hidden global [9 x i8], align 1
@_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE4info = external hidden global [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1

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

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

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

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

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

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

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

8:                                                ; preds = %6
  %9 = tail call i64 @fwrite(ptr noundef nonnull @_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE4type, i64 noundef 1, i64 noundef 3, ptr noundef nonnull %7)
  %10 = tail call i64 @fwrite(ptr noundef nonnull @_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE5dummy, i64 noundef 1, i64 noundef 9, ptr noundef nonnull %7)
  %11 = trunc i32 %2 to i8
  store i8 %11, ptr @_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE4info, align 1, !tbaa !5
  %12 = lshr i32 %2, 8
  %13 = trunc i32 %12 to i8
  store i8 %13, ptr getelementptr inbounds (i8, ptr @_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE4info, i64 1), align 1, !tbaa !5
  %14 = trunc i32 %3 to i8
  store i8 %14, ptr getelementptr inbounds (i8, ptr @_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE4info, i64 2), align 1, !tbaa !5
  %15 = lshr i32 %3, 8
  %16 = trunc i32 %15 to i8
  store i8 %16, ptr getelementptr inbounds (i8, ptr @_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE4info, i64 3), align 1, !tbaa !5
  switch i32 %4, label %23 [
    i32 6406, label %.thread
    i32 6407, label %.thread24
    i32 6408, label %.thread25
  ]

.thread:                                          ; preds = %8
  store i8 8, ptr getelementptr inbounds (i8, ptr @_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE4info, i64 4), align 1, !tbaa !5
  %17 = tail call i64 @fwrite(ptr noundef nonnull @_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE4info, i64 noundef 1, i64 noundef 6, ptr noundef nonnull %7)
  %18 = mul nsw i32 %3, %2
  tail call void @_ZN3TGA9writeGrayEP8_IO_FILEPKhi(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull %7, ptr noundef %5, i32 noundef %18)
  br label %25

.thread24:                                        ; preds = %8
  store i8 24, ptr getelementptr inbounds (i8, ptr @_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE4info, i64 4), align 1, !tbaa !5
  %19 = tail call i64 @fwrite(ptr noundef nonnull @_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE4info, i64 noundef 1, i64 noundef 6, ptr noundef nonnull %7)
  %20 = mul nsw i32 %3, %2
  tail call void @_ZN3TGA14writeGrayAsRGBEP8_IO_FILEPKhi(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull %7, ptr noundef %5, i32 noundef %20)
  br label %25

.thread25:                                        ; preds = %8
  store i8 32, ptr getelementptr inbounds (i8, ptr @_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE4info, i64 4), align 1, !tbaa !5
  %21 = tail call i64 @fwrite(ptr noundef nonnull @_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE4info, i64 noundef 1, i64 noundef 6, ptr noundef nonnull %7)
  %22 = mul nsw i32 %3, %2
  tail call void @_ZN3TGA9writeRGBAEP8_IO_FILEPKhi(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull %7, ptr noundef %5, i32 noundef %22)
  br label %25

23:                                               ; preds = %8
  %24 = tail call i64 @fwrite(ptr noundef nonnull @_ZZN3TGA20saveFromExternalDataEPKciiNS_9TGAFormatEPKhE4info, i64 noundef 1, i64 noundef 6, ptr noundef nonnull %7)
  br label %25

25:                                               ; preds = %23, %.thread25, %.thread24, %.thread
  %26 = tail call i32 @fclose(ptr noundef nonnull %7)
  br label %27

27:                                               ; preds = %6, %25
  %.0 = phi i32 [ 1, %25 ], [ 2, %6 ]
  ret i32 %.0
}

attributes #0 = { 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 #1 = { 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" }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass