; LLVM IR from facebook/redex :: libresource/ResourceTypes.ll (ZN7android22unpackLanguageOrRegionEPKccPc)

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

; 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_ZN7android22unpackLanguageOrRegionEPKccPc(ptr noundef %0, i8 noundef signext %1, ptr noundef %2) #3 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %9 = alloca i8, align 1
  %10 = alloca i8, align 1
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i8 %1, ptr %6, align 1, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 0
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %14 = sext i8 %13 to i32
  %15 = and i32 %14, 128
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %71

17:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #4
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 1
  %20 = load i8, ptr %19, align 1, !tbaa !9
  %21 = sext i8 %20 to i32
  %22 = and i32 %21, 31
  %23 = trunc i32 %22 to i8
  store i8 %23, ptr %8, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #4
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 1
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = sext i8 %26 to i32
  %28 = and i32 %27, 224
  %29 = ashr i32 %28, 5
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i64 0
  %32 = load i8, ptr %31, align 1, !tbaa !9
  %33 = sext i8 %32 to i32
  %34 = and i32 %33, 3
  %35 = shl i32 %34, 3
  %36 = add nsw i32 %29, %35
  %37 = trunc i32 %36 to i8
  store i8 %37, ptr %9, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #4
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i64 0
  %40 = load i8, ptr %39, align 1, !tbaa !9
  %41 = sext i8 %40 to i32
  %42 = and i32 %41, 124
  %43 = ashr i32 %42, 2
  %44 = trunc i32 %43 to i8
  store i8 %44, ptr %10, align 1, !tbaa !9
  %45 = load i8, ptr %8, align 1, !tbaa !9
  %46 = zext i8 %45 to i32
  %47 = load i8, ptr %6, align 1, !tbaa !9
  %48 = sext i8 %47 to i32
  %49 = add nsw i32 %46, %48
  %50 = trunc i32 %49 to i8
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %51, i64 0
  store i8 %50, ptr %52, align 1, !tbaa !9
  %53 = load i8, ptr %9, align 1, !tbaa !9
  %54 = zext i8 %53 to i32
  %55 = load i8, ptr %6, align 1, !tbaa !9
  %56 = sext i8 %55 to i32
  %57 = add nsw i32 %54, %56
  %58 = trunc i32 %57 to i8
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = getelementptr inbounds i8, ptr %59, i64 1
  store i8 %58, ptr %60, align 1, !tbaa !9
  %61 = load i8, ptr %10, align 1, !tbaa !9
  %62 = zext i8 %61 to i32
  %63 = load i8, ptr %6, align 1, !tbaa !9
  %64 = sext i8 %63 to i32
  %65 = add nsw i32 %62, %64
  %66 = trunc i32 %65 to i8
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = getelementptr inbounds i8, ptr %67, i64 2
  store i8 %66, ptr %68, align 1, !tbaa !9
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = getelementptr inbounds i8, ptr %69, i64 3
  store i8 0, ptr %70, align 1, !tbaa !9
  store i64 3, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #4
  br label %83

71:                                               ; preds = %3
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds i8, ptr %72, i64 0
  %74 = load i8, ptr %73, align 1, !tbaa !9
  %75 = icmp ne i8 %74, 0
  br i1 %75, label %76, label %81

76:                                               ; preds = %71
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %77, ptr align 1 %78, i64 2, i1 false)
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  %80 = getelementptr inbounds i8, ptr %79, i64 2
  call void @llvm.memset.p0.i64(ptr align 1 %80, i8 0, i64 2, i1 false)
  store i64 2, ptr %4, align 8
  br label %83

81:                                               ; preds = %71
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 1 %82, i8 0, i64 4, i1 false)
  store i64 0, ptr %4, align 8
  br label %83

83:                                               ; preds = %81, %76, %17
  %84 = load i64, ptr %4, align 8
  ret i64 %84
}

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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local noundef range(i64 0, 4) i64 @_ZN7android22unpackLanguageOrRegionEPKccPc(ptr nocapture noundef readonly %0, i8 noundef signext %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = load i8, ptr %0, align 1, !tbaa !5
  %.not = icmp sgt i8 %4, -1
  br i1 %.not, label %21, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 1
  %7 = load i8, ptr %6, align 1, !tbaa !5
  %8 = and i8 %7, 31
  %9 = lshr i8 %7, 5
  %10 = shl i8 %4, 3
  %11 = and i8 %10, 24
  %12 = lshr i8 %4, 2
  %13 = and i8 %12, 31
  %14 = add i8 %8, %1
  store i8 %14, ptr %2, align 1, !tbaa !5
  %15 = add i8 %11, %1
  %16 = add i8 %15, %9
  %17 = getelementptr inbounds i8, ptr %2, i64 1
  store i8 %16, ptr %17, align 1, !tbaa !5
  %18 = add i8 %13, %1
  %19 = getelementptr inbounds i8, ptr %2, i64 2
  store i8 %18, ptr %19, align 1, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %2, i64 3
  store i8 0, ptr %20, align 1, !tbaa !5
  br label %26

21:                                               ; preds = %3
  %.not20 = icmp eq i8 %4, 0
  br i1 %.not20, label %25, label %22

22:                                               ; preds = %21
  %23 = load i16, ptr %0, align 1
  store i16 %23, ptr %2, align 1
  %24 = getelementptr inbounds i8, ptr %2, i64 2
  store i16 0, ptr %24, align 1
  br label %26

25:                                               ; preds = %21
  store i32 0, ptr %2, align 1
  br label %26

26:                                               ; preds = %25, %22, %5
  %.0 = phi i64 [ 3, %5 ], [ 2, %22 ], [ 0, %25 ]
  ret i64 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass