; LLVM IR from gulrak/filesystem :: test/impl_test.ll (ZN3ghc10filesystem6detail19consumeUtf8FragmentEjhRj)

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

@_ZZN3ghc10filesystem6detail19consumeUtf8FragmentEjhRjE15utf8_state_info = external hidden constant [32 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN3ghc10filesystem6detail19consumeUtf8FragmentEjhRj(i32 noundef %0, i8 noundef zeroext %1, ptr noundef nonnull align 4 dereferenceable(4) %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i8, align 1
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  %8 = load i8, ptr %5, align 1, !tbaa !9
  %9 = zext i8 %8 to i32
  %10 = icmp slt i32 %9, 128
  br i1 %10, label %11, label %12

11:                                               ; preds = %3
  br label %26

12:                                               ; preds = %3
  %13 = load i8, ptr %5, align 1, !tbaa !9
  %14 = zext i8 %13 to i32
  %15 = ashr i32 %14, 3
  %16 = and i32 %15, 15
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [32 x i32], ptr @_ZZN3ghc10filesystem6detail19consumeUtf8FragmentEjhRjE15utf8_state_info, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = load i8, ptr %5, align 1, !tbaa !9
  %21 = zext i8 %20 to i32
  %22 = and i32 %21, 7
  %23 = shl i32 %22, 2
  %24 = lshr i32 %19, %23
  %25 = and i32 %24, 15
  br label %26

26:                                               ; preds = %12, %11
  %27 = phi i32 [ 0, %11 ], [ %25, %12 ]
  %28 = trunc i32 %27 to i8
  store i8 %28, ptr %7, align 1, !tbaa !9
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %39

31:                                               ; preds = %26
  %32 = load ptr, ptr %6, align 8, !tbaa !10
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = shl i32 %33, 6
  %35 = load i8, ptr %5, align 1, !tbaa !9
  %36 = zext i8 %35 to i32
  %37 = and i32 %36, 63
  %38 = or i32 %34, %37
  br label %46

39:                                               ; preds = %26
  %40 = load i8, ptr %7, align 1, !tbaa !9
  %41 = zext i8 %40 to i32
  %42 = lshr i32 255, %41
  %43 = load i8, ptr %5, align 1, !tbaa !9
  %44 = zext i8 %43 to i32
  %45 = and i32 %42, %44
  br label %46

46:                                               ; preds = %39, %31
  %47 = phi i32 [ %38, %31 ], [ %45, %39 ]
  %48 = load ptr, ptr %6, align 8, !tbaa !10
  store i32 %47, ptr %48, align 4, !tbaa !5
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = icmp eq i32 %49, 8
  br i1 %50, label %51, label %52

51:                                               ; preds = %46
  br label %63

52:                                               ; preds = %46
  %53 = load i8, ptr %7, align 1, !tbaa !9
  %54 = zext i8 %53 to i32
  %55 = add nsw i32 %54, 16
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [32 x i32], ptr @_ZZN3ghc10filesystem6detail19consumeUtf8FragmentEjhRjE15utf8_state_info, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = shl i32 %59, 2
  %61 = lshr i32 %58, %60
  %62 = and i32 %61, 15
  br label %63

63:                                               ; preds = %52, %51
  %64 = phi i32 [ 8, %51 ], [ %62, %52 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  ret i32 %64
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !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"

@_ZZN3ghc10filesystem6detail19consumeUtf8FragmentEjhRjE15utf8_state_info = external hidden local_unnamed_addr constant [32 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local noundef range(i32 0, 16) i32 @_ZN3ghc10filesystem6detail19consumeUtf8FragmentEjhRj(i32 noundef %0, i8 noundef zeroext %1, ptr nocapture noundef nonnull align 4 dereferenceable(4) %2) local_unnamed_addr #0 {
  %4 = zext i8 %1 to i32
  %5 = icmp sgt i8 %1, -1
  br i1 %5, label %16, label %6

6:                                                ; preds = %3
  %7 = lshr i32 %4, 3
  %8 = and i32 %7, 15
  %9 = zext nneg i32 %8 to i64
  %10 = getelementptr inbounds [32 x i32], ptr @_ZZN3ghc10filesystem6detail19consumeUtf8FragmentEjhRjE15utf8_state_info, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = shl nuw nsw i32 %4, 2
  %13 = and i32 %12, 28
  %14 = lshr i32 %11, %13
  %15 = and i32 %14, 15
  br label %16

16:                                               ; preds = %3, %6
  %17 = phi i32 [ %15, %6 ], [ 0, %3 ]
  %.not = icmp eq i32 %0, 0
  br i1 %.not, label %.thread, label %20

.thread:                                          ; preds = %16
  %18 = lshr i32 255, %17
  %19 = and i32 %18, %4
  store i32 %19, ptr %2, align 4, !tbaa !5
  br label %26

20:                                               ; preds = %16
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = shl i32 %21, 6
  %23 = and i32 %4, 63
  %24 = or disjoint i32 %22, %23
  store i32 %24, ptr %2, align 4, !tbaa !5
  %25 = icmp eq i32 %0, 8
  br i1 %25, label %34, label %26

26:                                               ; preds = %.thread, %20
  %27 = or disjoint i32 %17, 16
  %28 = zext nneg i32 %27 to i64
  %29 = getelementptr inbounds [32 x i32], ptr @_ZZN3ghc10filesystem6detail19consumeUtf8FragmentEjhRjE15utf8_state_info, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = shl i32 %0, 2
  %32 = lshr i32 %30, %31
  %33 = and i32 %32, 15
  br label %34

34:                                               ; preds = %20, %26
  %35 = phi i32 [ %33, %26 ], [ 8, %20 ]
  ret i32 %35
}

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


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