; LLVM IR from facebookresearch/habitat-sim :: src/deps/basis-universal/encoder (basisu_gpu_texture)

; 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.basisu::out_file_header" = type { %"struct.basisu::packed_uint", %"struct.basisu::packed_uint", %"struct.basisu::packed_uint", %"struct.basisu::packed_uint" }
%"struct.basisu::packed_uint" = type { [4 x i8] }

@.str.10 = external hidden unnamed_addr constant [3 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

; 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 uwtable
declare dso_local noundef ptr @_ZNK6basisu9gpu_image7get_ptrEv(ptr noundef nonnull align 8 dereferenceable(48)) #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK6basisu9gpu_image17get_size_in_bytesEv(ptr noundef nonnull align 8 dereferenceable(48)) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(4) ptr @_ZN6basisu11packed_uintILj4EEaSEm(ptr noundef nonnull align 1 dereferenceable(4), i64 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN6basisu19write_3dfx_out_fileEPKcRKNS_9gpu_imageE(ptr noundef %0, ptr noundef nonnull align 8 dereferenceable(48) %1) #3 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %"struct.basisu::out_file_header", align 1
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #5
  call void @_ZN6basisu15out_file_headerC2Ev(ptr noundef nonnull align 1 dereferenceable(16) %6)
  %9 = getelementptr inbounds %"struct.basisu::out_file_header", ptr %6, i32 0, i32 0
  %10 = getelementptr inbounds %"struct.basisu::packed_uint", ptr %9, i32 0, i32 0
  %11 = getelementptr inbounds [4 x i8], ptr %10, i64 0, i64 0
  store i8 67, ptr %11, align 1, !tbaa !9
  %12 = getelementptr inbounds %"struct.basisu::out_file_header", ptr %6, i32 0, i32 0
  %13 = getelementptr inbounds %"struct.basisu::packed_uint", ptr %12, i32 0, i32 0
  %14 = getelementptr inbounds [4 x i8], ptr %13, i64 0, i64 1
  store i8 88, ptr %14, align 1, !tbaa !9
  %15 = getelementptr inbounds %"struct.basisu::out_file_header", ptr %6, i32 0, i32 0
  %16 = getelementptr inbounds %"struct.basisu::packed_uint", ptr %15, i32 0, i32 0
  %17 = getelementptr inbounds [4 x i8], ptr %16, i64 0, i64 2
  store i8 69, ptr %17, align 1, !tbaa !9
  %18 = getelementptr inbounds %"struct.basisu::out_file_header", ptr %6, i32 0, i32 0
  %19 = getelementptr inbounds %"struct.basisu::packed_uint", ptr %18, i32 0, i32 0
  %20 = getelementptr inbounds [4 x i8], ptr %19, i64 0, i64 3
  store i8 84, ptr %20, align 1, !tbaa !9
  %21 = getelementptr inbounds %"struct.basisu::out_file_header", ptr %6, i32 0, i32 1
  %22 = call noundef nonnull align 1 dereferenceable(4) ptr @_ZN6basisu11packed_uintILj4EEaSEm(ptr noundef nonnull align 1 dereferenceable(4) %21, i64 noundef 0)
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = call noundef i32 @_ZNK6basisu9gpu_image12get_blocks_xEv(ptr noundef nonnull align 8 dereferenceable(48) %23)
  %25 = mul i32 %24, 8
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds %"struct.basisu::out_file_header", ptr %6, i32 0, i32 2
  %28 = call noundef nonnull align 1 dereferenceable(4) ptr @_ZN6basisu11packed_uintILj4EEaSEm(ptr noundef nonnull align 1 dereferenceable(4) %27, i64 noundef %26)
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = call noundef i32 @_ZNK6basisu9gpu_image12get_blocks_yEv(ptr noundef nonnull align 8 dereferenceable(48) %29)
  %31 = mul i32 %30, 4
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds %"struct.basisu::out_file_header", ptr %6, i32 0, i32 3
  %34 = call noundef nonnull align 1 dereferenceable(4) ptr @_ZN6basisu11packed_uintILj4EEaSEm(ptr noundef nonnull align 1 dereferenceable(4) %33, i64 noundef %32)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store ptr null, ptr %7, align 8, !tbaa !5
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = call noalias ptr @fopen(ptr noundef %35, ptr noundef @.str.10)
  store ptr %36, ptr %7, align 8, !tbaa !5
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %40, label %39

39:                                               ; preds = %2
  store i1 false, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %53

40:                                               ; preds = %2
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = call i64 @fwrite(ptr noundef %6, i64 noundef 16, i64 noundef 1, ptr noundef %41)
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = call noundef ptr @_ZNK6basisu9gpu_image7get_ptrEv(ptr noundef nonnull align 8 dereferenceable(48) %43)
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = call noundef i32 @_ZNK6basisu9gpu_image17get_size_in_bytesEv(ptr noundef nonnull align 8 dereferenceable(48) %45)
  %47 = zext i32 %46 to i64
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = call i64 @fwrite(ptr noundef %44, i64 noundef %47, i64 noundef 1, ptr noundef %48)
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = call i32 @fclose(ptr noundef %50)
  %52 = icmp ne i32 %51, -1
  store i1 %52, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %53

53:                                               ; preds = %40, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #5
  %54 = load i1, ptr %3, align 1
  ret i1 %54
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN6basisu15out_file_headerC2Ev(ptr noundef nonnull align 1 dereferenceable(16)) unnamed_addr #1 align 2

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

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

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

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

declare i32 @fclose(ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 #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 = { 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 = { "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 }

!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 = !{!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"

%"struct.basisu::out_file_header" = type { %"struct.basisu::packed_uint", %"struct.basisu::packed_uint", %"struct.basisu::packed_uint", %"struct.basisu::packed_uint" }
%"struct.basisu::packed_uint" = type { [4 x i8] }

@.str.10 = external hidden unnamed_addr constant [3 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZNK6basisu9gpu_image7get_ptrEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK6basisu9gpu_image17get_size_in_bytesEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(4) ptr @_ZN6basisu11packed_uintILj4EEaSEm(ptr noundef nonnull align 1 dereferenceable(4), i64 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN6basisu19write_3dfx_out_fileEPKcRKNS_9gpu_imageE(ptr nocapture noundef readonly %0, ptr noundef nonnull align 8 dereferenceable(48) %1) local_unnamed_addr #3 {
  %3 = alloca %"struct.basisu::out_file_header", align 4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #5
  call void @_ZN6basisu15out_file_headerC2Ev(ptr noundef nonnull align 1 dereferenceable(16) %3)
  store <4 x i8> <i8 67, i8 88, i8 69, i8 84>, ptr %3, align 4, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 4
  %5 = call noundef nonnull align 1 dereferenceable(4) ptr @_ZN6basisu11packed_uintILj4EEaSEm(ptr noundef nonnull align 1 dereferenceable(4) %4, i64 noundef 0)
  %6 = call noundef i32 @_ZNK6basisu9gpu_image12get_blocks_xEv(ptr noundef nonnull align 8 dereferenceable(48) %1)
  %7 = shl i32 %6, 3
  %8 = zext i32 %7 to i64
  %9 = getelementptr inbounds i8, ptr %3, i64 8
  %10 = call noundef nonnull align 1 dereferenceable(4) ptr @_ZN6basisu11packed_uintILj4EEaSEm(ptr noundef nonnull align 1 dereferenceable(4) %9, i64 noundef %8)
  %11 = call noundef i32 @_ZNK6basisu9gpu_image12get_blocks_yEv(ptr noundef nonnull align 8 dereferenceable(48) %1)
  %12 = shl i32 %11, 2
  %13 = zext i32 %12 to i64
  %14 = getelementptr inbounds i8, ptr %3, i64 12
  %15 = call noundef nonnull align 1 dereferenceable(4) ptr @_ZN6basisu11packed_uintILj4EEaSEm(ptr noundef nonnull align 1 dereferenceable(4) %14, i64 noundef %13)
  %16 = call noalias ptr @fopen(ptr noundef %0, ptr noundef nonnull @.str.10)
  %.not = icmp eq ptr %16, null
  br i1 %.not, label %25, label %17

17:                                               ; preds = %2
  %18 = call i64 @fwrite(ptr noundef nonnull %3, i64 noundef 16, i64 noundef 1, ptr noundef nonnull %16)
  %19 = call noundef ptr @_ZNK6basisu9gpu_image7get_ptrEv(ptr noundef nonnull align 8 dereferenceable(48) %1)
  %20 = call noundef i32 @_ZNK6basisu9gpu_image17get_size_in_bytesEv(ptr noundef nonnull align 8 dereferenceable(48) %1)
  %21 = zext i32 %20 to i64
  %22 = call i64 @fwrite(ptr noundef %19, i64 noundef %21, i64 noundef 1, ptr noundef nonnull %16)
  %23 = call i32 @fclose(ptr noundef nonnull %16)
  %24 = icmp ne i32 %23, -1
  br label %25

25:                                               ; preds = %2, %17
  %.0 = phi i1 [ %24, %17 ], [ false, %2 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #5
  ret i1 %.0
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN6basisu15out_file_headerC2Ev(ptr noundef nonnull align 1 dereferenceable(16)) unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6basisu9gpu_image12get_blocks_xEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6basisu9gpu_image12get_blocks_yEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #2 align 2

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

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

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 #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 = { 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 = { 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 #5 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass