; LLVM IR from facebook/redex :: libredex/TypeUtil.ll (ZN4type11to_datatypeEPK7DexType)

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

@.str.8 = external hidden unnamed_addr constant [70 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [2 x i8], align 1
@__PRETTY_FUNCTION__._ZN4type11to_datatypeEPK7DexType = external hidden unnamed_addr constant [44 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: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK7DexType8get_nameEv(ptr noundef nonnull align 8 dereferenceable(16)) #1 align 2

; Function Attrs: noreturn
declare void @_Z11assert_failPKcS0_jS0_10RedexErrorS0_z(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK9DexString5c_strEv(ptr noundef nonnull align 8 dereferenceable(16)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i8 @_ZN4type11to_datatypeEPK7DexType(ptr noundef %0) #3 {
  %2 = alloca i8, align 1
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = call noundef ptr @_ZNK7DexType8get_nameEv(ptr noundef nonnull align 8 dereferenceable(16) %6)
  %8 = call noundef ptr @_ZNK9DexString5c_strEv(ptr noundef nonnull align 8 dereferenceable(16) %7)
  store ptr %8, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 0
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %12 = sext i8 %11 to i32
  switch i32 %12, label %24 [
    i32 86, label %13
    i32 90, label %14
    i32 66, label %15
    i32 83, label %16
    i32 67, label %17
    i32 73, label %18
    i32 74, label %19
    i32 70, label %20
    i32 68, label %21
    i32 76, label %22
    i32 91, label %23
  ]

13:                                               ; preds = %1
  store i8 0, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %28

14:                                               ; preds = %1
  store i8 1, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %28

15:                                               ; preds = %1
  store i8 2, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %28

16:                                               ; preds = %1
  store i8 3, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %28

17:                                               ; preds = %1
  store i8 4, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %28

18:                                               ; preds = %1
  store i8 5, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %28

19:                                               ; preds = %1
  store i8 6, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %28

20:                                               ; preds = %1
  store i8 7, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %28

21:                                               ; preds = %1
  store i8 8, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %28

22:                                               ; preds = %1
  store i8 9, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %28

23:                                               ; preds = %1
  store i8 10, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %28

24:                                               ; preds = %1
  br label %25

25:                                               ; preds = %26, %24
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @_Z11assert_failPKcS0_jS0_10RedexErrorS0_z(ptr noundef @.str.12, ptr noundef @.str.8, i32 noundef 458, ptr noundef @__PRETTY_FUNCTION__._ZN4type11to_datatypeEPK7DexType, i32 noundef 2, ptr noundef @.str.13) #5
  unreachable

26:                                               ; No predecessors!
  br i1 true, label %25, label %27, !llvm.loop !10

27:                                               ; preds = %26
  unreachable

28:                                               ; preds = %23, %22, %21, %20, %19, %18, %17, %16, %15, %14, %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %29 = load i8, ptr %2, align 1
  ret i8 %29
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { noreturn "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 }
attributes #5 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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"

@.str.8 = external hidden unnamed_addr constant [70 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [2 x i8], align 1
@__PRETTY_FUNCTION__._ZN4type11to_datatypeEPK7DexType = external hidden unnamed_addr constant [44 x i8], align 1
@switch.table._ZN4type11to_datatypeEPK7DexType = private unnamed_addr constant [26 x i8] c"\02\04\08\00\07\00\00\05\06\00\09\00\00\00\00\00\00\03\00\00\00\00\00\00\01\0A", align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK7DexType8get_nameEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK9DexString5c_strEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext range(i8 0, 11) i8 @_ZN4type11to_datatypeEPK7DexType(ptr noundef nonnull %0) local_unnamed_addr #2 {
  %2 = tail call noundef ptr @_ZNK7DexType8get_nameEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %3 = tail call noundef ptr @_ZNK9DexString5c_strEv(ptr noundef nonnull align 8 dereferenceable(16) %2)
  %4 = load i8, ptr %3, align 1, !tbaa !5
  %switch.tableidx = add i8 %4, -66
  %5 = icmp ult i8 %switch.tableidx, 26
  br i1 %5, label %switch.hole_check, label %6

6:                                                ; preds = %switch.hole_check, %1
  tail call void (ptr, ptr, i32, ptr, i32, ptr, ...) @_Z11assert_failPKcS0_jS0_10RedexErrorS0_z(ptr noundef nonnull @.str.12, ptr noundef nonnull @.str.8, i32 noundef 458, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4type11to_datatypeEPK7DexType, i32 noundef 2, ptr noundef nonnull @.str.13) #3
  unreachable

switch.hole_check:                                ; preds = %1
  %switch.maskindex = zext nneg i8 %switch.tableidx to i32
  %switch.shifted = lshr i32 51512727, %switch.maskindex
  %switch.lobit = trunc i32 %switch.shifted to i1
  br i1 %switch.lobit, label %switch.lookup, label %6

switch.lookup:                                    ; preds = %switch.hole_check
  %7 = zext nneg i8 %switch.tableidx to i64
  %switch.gep = getelementptr inbounds [26 x i8], ptr @switch.table._ZN4type11to_datatypeEPK7DexType, i64 0, i64 %7
  %switch.load = load i8, ptr %switch.gep, align 1
  ret i8 %switch.load
}

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


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