; LLVM IR from paroj/gltut :: glsdk/glimg/source/Util.ll (ZN5glimg23GetBlockCompressionDataENS_13PixelDataTypeE)

; 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.glimg::CompressedBlockData" = type { %"struct.glimg::Dimensions", i64 }
%"struct.glimg::Dimensions" = type { i32, i32, i32, i32 }

@.str = external hidden unnamed_addr constant [35 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [73 x i8], align 1
@__PRETTY_FUNCTION__._ZN5glimg23GetBlockCompressionDataENS_13PixelDataTypeE = external hidden unnamed_addr constant [66 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN5glimg23GetBlockCompressionDataENS_13PixelDataTypeE(ptr dead_on_unwind noalias writable sret(%"struct.glimg::CompressedBlockData") align 8 %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  store i32 %1, ptr %3, align 4, !tbaa !5
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = icmp sge i32 %4, 6
  br i1 %5, label %6, label %7

6:                                                ; preds = %2
  br label %9

7:                                                ; preds = %2
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 93, ptr noundef @__PRETTY_FUNCTION__._ZN5glimg23GetBlockCompressionDataENS_13PixelDataTypeE) #2
  unreachable

8:                                                ; No predecessors!
  br label %9

9:                                                ; preds = %8, %6
  %10 = getelementptr inbounds %"struct.glimg::CompressedBlockData", ptr %0, i32 0, i32 0
  %11 = getelementptr inbounds %"struct.glimg::Dimensions", ptr %10, i32 0, i32 0
  store i32 2, ptr %11, align 8, !tbaa !9
  %12 = getelementptr inbounds %"struct.glimg::CompressedBlockData", ptr %0, i32 0, i32 0
  %13 = getelementptr inbounds %"struct.glimg::Dimensions", ptr %12, i32 0, i32 1
  store i32 4, ptr %13, align 4, !tbaa !14
  %14 = getelementptr inbounds %"struct.glimg::CompressedBlockData", ptr %0, i32 0, i32 0
  %15 = getelementptr inbounds %"struct.glimg::Dimensions", ptr %14, i32 0, i32 2
  store i32 4, ptr %15, align 8, !tbaa !15
  %16 = load i32, ptr %3, align 4, !tbaa !5
  switch i32 %16, label %19 [
    i32 6, label %17
    i32 9, label %17
    i32 10, label %17
  ]

17:                                               ; preds = %9, %9, %9
  %18 = getelementptr inbounds %"struct.glimg::CompressedBlockData", ptr %0, i32 0, i32 1
  store i64 8, ptr %18, align 8, !tbaa !16
  br label %21

19:                                               ; preds = %9
  %20 = getelementptr inbounds %"struct.glimg::CompressedBlockData", ptr %0, i32 0, i32 1
  store i64 16, ptr %20, align 8, !tbaa !16
  br label %21

21:                                               ; preds = %19, %17
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

attributes #0 = { 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 #1 = { noreturn 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 = { noreturn 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 = !{!"_ZTSN5glimg13PixelDataTypeE", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !12, i64 0}
!10 = !{!"_ZTSN5glimg19CompressedBlockDataE", !11, i64 0, !13, i64 16}
!11 = !{!"_ZTSN5glimg10DimensionsE", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!10, !12, i64 4}
!15 = !{!10, !12, i64 8}
!16 = !{!10, !13, i64 16}


; 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.glimg::CompressedBlockData" = type { %"struct.glimg::Dimensions", i64 }
%"struct.glimg::Dimensions" = type { i32, i32, i32, i32 }

@.str = external hidden unnamed_addr constant [35 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [73 x i8], align 1
@__PRETTY_FUNCTION__._ZN5glimg23GetBlockCompressionDataENS_13PixelDataTypeE = external hidden unnamed_addr constant [66 x i8], align 1
@switch.table._ZN5glimg23GetBlockCompressionDataENS_13PixelDataTypeE = private unnamed_addr constant [5 x i64] [i64 8, i64 16, i64 16, i64 8, i64 8], align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN5glimg23GetBlockCompressionDataENS_13PixelDataTypeE(ptr dead_on_unwind noalias nocapture writable writeonly sret(%"struct.glimg::CompressedBlockData") align 8 %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp sgt i32 %1, 5
  br i1 %3, label %5, label %4

4:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 93, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN5glimg23GetBlockCompressionDataENS_13PixelDataTypeE) #2
  unreachable

5:                                                ; preds = %2
  store i32 2, ptr %0, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 4, ptr %6, align 4, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 4, ptr %7, align 8, !tbaa !13
  %switch.tableidx = add nsw i32 %1, -6
  %8 = icmp ult i32 %switch.tableidx, 5
  br i1 %8, label %switch.lookup, label %10

switch.lookup:                                    ; preds = %5
  %9 = zext nneg i32 %switch.tableidx to i64
  %switch.gep = getelementptr inbounds [5 x i64], ptr @switch.table._ZN5glimg23GetBlockCompressionDataENS_13PixelDataTypeE, i64 0, i64 %9
  %switch.load = load i64, ptr %switch.gep, align 8
  br label %10

10:                                               ; preds = %5, %switch.lookup
  %.sink = phi i64 [ %switch.load, %switch.lookup ], [ 16, %5 ]
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %.sink, ptr %11, align 8, !tbaa !14
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { noreturn 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 = { noreturn 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, !8, i64 0}
!6 = !{!"_ZTSN5glimg19CompressedBlockDataE", !7, i64 0, !11, i64 16}
!7 = !{!"_ZTSN5glimg10DimensionsE", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 12}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = !{!6, !8, i64 4}
!13 = !{!6, !8, i64 8}
!14 = !{!6, !11, i64 16}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass