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

; 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.basisu::color_rgba" = type { %union.anon }
%union.anon = type { [4 x i8] }

@_ZN6basisu20g_etc1_pixel_indicesE = external dso_local constant [2 x [2 x [8 x i32]]], align 16

; 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: 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) #1

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN6basisu11unpack_etc1ERKNS_9etc_blockEPNS_10color_rgbaEb(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef, i1 noundef zeroext) #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK6basisu9etc_block12get_flip_bitEv(ptr noundef nonnull align 8 dereferenceable(8)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK6basisu9etc_block19get_subblock_pixelsEPNS_10color_rgbaEi(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %1, i32 noundef %2) #3 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca [16 x %"class.basisu::color_rgba"], align 16
  %8 = alloca i8, align 1
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %11 = load ptr, ptr %4, align 8
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = icmp slt i32 %12, 0
  br i1 %13, label %14, label %17

14:                                               ; preds = %3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = call noundef zeroext i1 @_ZN6basisu11unpack_etc1ERKNS_9etc_blockEPNS_10color_rgbaEb(ptr noundef nonnull align 8 dereferenceable(8) %11, ptr noundef %15, i1 noundef zeroext false)
  br label %56

17:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 64, ptr %7) #4
  %18 = getelementptr inbounds [16 x %"class.basisu::color_rgba"], ptr %7, i32 0, i32 0
  %19 = getelementptr inbounds %"class.basisu::color_rgba", ptr %18, i64 16
  br label %20

20:                                               ; preds = %20, %17
  %21 = phi ptr [ %18, %17 ], [ %22, %20 ]
  call void @_ZN6basisu10color_rgbaC2Ev(ptr noundef nonnull align 1 dereferenceable(4) %21)
  %22 = getelementptr inbounds %"class.basisu::color_rgba", ptr %21, i64 1
  %23 = icmp eq ptr %22, %19
  br i1 %23, label %24, label %20

24:                                               ; preds = %20
  %25 = getelementptr inbounds [16 x %"class.basisu::color_rgba"], ptr %7, i64 0, i64 0
  %26 = call noundef zeroext i1 @_ZN6basisu11unpack_etc1ERKNS_9etc_blockEPNS_10color_rgbaEb(ptr noundef nonnull align 8 dereferenceable(8) %11, ptr noundef %25, i1 noundef zeroext false)
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #4
  %27 = call noundef zeroext i1 @_ZNK6basisu9etc_block12get_flip_bitEv(ptr noundef nonnull align 8 dereferenceable(8) %11)
  %28 = zext i1 %27 to i8
  store i8 %28, ptr %8, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %52, %24
  %30 = load i32, ptr %9, align 4, !tbaa !9
  %31 = icmp ult i32 %30, 8
  br i1 %31, label %33, label %32

32:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %55

33:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %34 = load i8, ptr %8, align 1, !tbaa !11, !range !13, !noundef !14
  %35 = trunc i8 %34 to i1
  %36 = zext i1 %35 to i64
  %37 = getelementptr inbounds [2 x [2 x [8 x i32]]], ptr @_ZN6basisu20g_etc1_pixel_indicesE, i64 0, i64 %36
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [2 x [8 x i32]], ptr %37, i64 0, i64 %39
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds [8 x i32], ptr %40, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !9
  store i32 %44, ptr %10, align 4, !tbaa !9
  %45 = load i32, ptr %10, align 4, !tbaa !9
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds [16 x %"class.basisu::color_rgba"], ptr %7, i64 0, i64 %46
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds %"class.basisu::color_rgba", ptr %48, i64 %50
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %51, ptr align 4 %47, i64 4, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %52

52:                                               ; preds = %33
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = add i32 %53, 1
  store i32 %54, ptr %9, align 4, !tbaa !9
  br label %29, !llvm.loop !17

55:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr %7) #4
  br label %56

56:                                               ; preds = %55, %14
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{i64 0, i64 4, !16}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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"

%"class.basisu::color_rgba" = type { %union.anon }
%union.anon = type { [4 x i8] }

@_ZN6basisu20g_etc1_pixel_indicesE = external dso_local local_unnamed_addr constant [2 x [2 x [8 x i32]]], align 16

; 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 nounwind uwtable
declare dso_local void @_ZN6basisu10color_rgbaC2Ev(ptr noundef nonnull align 1 dereferenceable(4)) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN6basisu11unpack_etc1ERKNS_9etc_blockEPNS_10color_rgbaEb(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef, i1 noundef zeroext) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK6basisu9etc_block12get_flip_bitEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK6basisu9etc_block19get_subblock_pixelsEPNS_10color_rgbaEi(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #2 align 2 {
  %4 = alloca [16 x %"class.basisu::color_rgba"], align 16
  %5 = icmp slt i32 %2, 0
  br i1 %5, label %6, label %8

6:                                                ; preds = %3
  %7 = tail call noundef zeroext i1 @_ZN6basisu11unpack_etc1ERKNS_9etc_blockEPNS_10color_rgbaEb(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %1, i1 noundef zeroext false)
  br label %60

8:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %4) #3
  call void @_ZN6basisu10color_rgbaC2Ev(ptr noundef nonnull align 1 dereferenceable(4) %4)
  %.ptr.1 = getelementptr inbounds i8, ptr %4, i64 4
  call void @_ZN6basisu10color_rgbaC2Ev(ptr noundef nonnull align 1 dereferenceable(4) %.ptr.1)
  %.ptr.2 = getelementptr inbounds i8, ptr %4, i64 8
  call void @_ZN6basisu10color_rgbaC2Ev(ptr noundef nonnull align 1 dereferenceable(4) %.ptr.2)
  %.ptr.3 = getelementptr inbounds i8, ptr %4, i64 12
  call void @_ZN6basisu10color_rgbaC2Ev(ptr noundef nonnull align 1 dereferenceable(4) %.ptr.3)
  %.ptr.4 = getelementptr inbounds i8, ptr %4, i64 16
  call void @_ZN6basisu10color_rgbaC2Ev(ptr noundef nonnull align 1 dereferenceable(4) %.ptr.4)
  %.ptr.5 = getelementptr inbounds i8, ptr %4, i64 20
  call void @_ZN6basisu10color_rgbaC2Ev(ptr noundef nonnull align 1 dereferenceable(4) %.ptr.5)
  %.ptr.6 = getelementptr inbounds i8, ptr %4, i64 24
  call void @_ZN6basisu10color_rgbaC2Ev(ptr noundef nonnull align 1 dereferenceable(4) %.ptr.6)
  %.ptr.7 = getelementptr inbounds i8, ptr %4, i64 28
  call void @_ZN6basisu10color_rgbaC2Ev(ptr noundef nonnull align 1 dereferenceable(4) %.ptr.7)
  %.ptr.8 = getelementptr inbounds i8, ptr %4, i64 32
  call void @_ZN6basisu10color_rgbaC2Ev(ptr noundef nonnull align 1 dereferenceable(4) %.ptr.8)
  %.ptr.9 = getelementptr inbounds i8, ptr %4, i64 36
  call void @_ZN6basisu10color_rgbaC2Ev(ptr noundef nonnull align 1 dereferenceable(4) %.ptr.9)
  %.ptr.10 = getelementptr inbounds i8, ptr %4, i64 40
  call void @_ZN6basisu10color_rgbaC2Ev(ptr noundef nonnull align 1 dereferenceable(4) %.ptr.10)
  %.ptr.11 = getelementptr inbounds i8, ptr %4, i64 44
  call void @_ZN6basisu10color_rgbaC2Ev(ptr noundef nonnull align 1 dereferenceable(4) %.ptr.11)
  %.ptr.12 = getelementptr inbounds i8, ptr %4, i64 48
  call void @_ZN6basisu10color_rgbaC2Ev(ptr noundef nonnull align 1 dereferenceable(4) %.ptr.12)
  %.ptr.13 = getelementptr inbounds i8, ptr %4, i64 52
  call void @_ZN6basisu10color_rgbaC2Ev(ptr noundef nonnull align 1 dereferenceable(4) %.ptr.13)
  %.ptr.14 = getelementptr inbounds i8, ptr %4, i64 56
  call void @_ZN6basisu10color_rgbaC2Ev(ptr noundef nonnull align 1 dereferenceable(4) %.ptr.14)
  %.ptr.15 = getelementptr inbounds i8, ptr %4, i64 60
  call void @_ZN6basisu10color_rgbaC2Ev(ptr noundef nonnull align 1 dereferenceable(4) %.ptr.15)
  %9 = call noundef zeroext i1 @_ZN6basisu11unpack_etc1ERKNS_9etc_blockEPNS_10color_rgbaEb(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull %4, i1 noundef zeroext false)
  %10 = call noundef zeroext i1 @_ZNK6basisu9etc_block12get_flip_bitEv(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %11 = zext i1 %10 to i64
  %12 = zext nneg i32 %2 to i64
  %13 = getelementptr inbounds [2 x [2 x [8 x i32]]], ptr @_ZN6basisu20g_etc1_pixel_indicesE, i64 0, i64 %11, i64 %12, i64 0
  %14 = load i32, ptr %13, align 16, !tbaa !5
  %15 = zext i32 %14 to i64
  %16 = getelementptr inbounds [16 x %"class.basisu::color_rgba"], ptr %4, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !9
  store i32 %17, ptr %1, align 1, !tbaa !9
  %18 = getelementptr inbounds [2 x [2 x [8 x i32]]], ptr @_ZN6basisu20g_etc1_pixel_indicesE, i64 0, i64 %11, i64 %12, i64 1
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds [16 x %"class.basisu::color_rgba"], ptr %4, i64 0, i64 %20
  %22 = getelementptr inbounds i8, ptr %1, i64 4
  %23 = load i32, ptr %21, align 4, !tbaa !9
  store i32 %23, ptr %22, align 1, !tbaa !9
  %24 = getelementptr inbounds [2 x [2 x [8 x i32]]], ptr @_ZN6basisu20g_etc1_pixel_indicesE, i64 0, i64 %11, i64 %12, i64 2
  %25 = load i32, ptr %24, align 8, !tbaa !5
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds [16 x %"class.basisu::color_rgba"], ptr %4, i64 0, i64 %26
  %28 = getelementptr inbounds i8, ptr %1, i64 8
  %29 = load i32, ptr %27, align 4, !tbaa !9
  store i32 %29, ptr %28, align 1, !tbaa !9
  %30 = getelementptr inbounds [2 x [2 x [8 x i32]]], ptr @_ZN6basisu20g_etc1_pixel_indicesE, i64 0, i64 %11, i64 %12, i64 3
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds [16 x %"class.basisu::color_rgba"], ptr %4, i64 0, i64 %32
  %34 = getelementptr inbounds i8, ptr %1, i64 12
  %35 = load i32, ptr %33, align 4, !tbaa !9
  store i32 %35, ptr %34, align 1, !tbaa !9
  %36 = getelementptr inbounds [2 x [2 x [8 x i32]]], ptr @_ZN6basisu20g_etc1_pixel_indicesE, i64 0, i64 %11, i64 %12, i64 4
  %37 = load i32, ptr %36, align 16, !tbaa !5
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds [16 x %"class.basisu::color_rgba"], ptr %4, i64 0, i64 %38
  %40 = getelementptr inbounds i8, ptr %1, i64 16
  %41 = load i32, ptr %39, align 4, !tbaa !9
  store i32 %41, ptr %40, align 1, !tbaa !9
  %42 = getelementptr inbounds [2 x [2 x [8 x i32]]], ptr @_ZN6basisu20g_etc1_pixel_indicesE, i64 0, i64 %11, i64 %12, i64 5
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds [16 x %"class.basisu::color_rgba"], ptr %4, i64 0, i64 %44
  %46 = getelementptr inbounds i8, ptr %1, i64 20
  %47 = load i32, ptr %45, align 4, !tbaa !9
  store i32 %47, ptr %46, align 1, !tbaa !9
  %48 = getelementptr inbounds [2 x [2 x [8 x i32]]], ptr @_ZN6basisu20g_etc1_pixel_indicesE, i64 0, i64 %11, i64 %12, i64 6
  %49 = load i32, ptr %48, align 8, !tbaa !5
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds [16 x %"class.basisu::color_rgba"], ptr %4, i64 0, i64 %50
  %52 = getelementptr inbounds i8, ptr %1, i64 24
  %53 = load i32, ptr %51, align 4, !tbaa !9
  store i32 %53, ptr %52, align 1, !tbaa !9
  %54 = getelementptr inbounds [2 x [2 x [8 x i32]]], ptr @_ZN6basisu20g_etc1_pixel_indicesE, i64 0, i64 %11, i64 %12, i64 7
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = zext i32 %55 to i64
  %57 = getelementptr inbounds [16 x %"class.basisu::color_rgba"], ptr %4, i64 0, i64 %56
  %58 = getelementptr inbounds i8, ptr %1, i64 28
  %59 = load i32, ptr %57, align 4, !tbaa !9
  store i32 %59, ptr %58, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %4) #3
  br label %60

60:                                               ; preds = %8, %6
  ret void
}

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass