; LLVM IR from joembedded/JesFs :: jesfs_hl (fs_track_crc32)

; 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: nounwind uwtable
define dso_local i32 @fs_track_crc32(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  br label %8

8:                                                ; preds = %38, %3
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = add i32 %9, -1
  store i32 %10, ptr %5, align 4, !tbaa !9
  %11 = icmp ne i32 %9, 0
  br i1 %11, label %12, label %39

12:                                               ; preds = %8
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i32 1
  store ptr %14, ptr %4, align 8, !tbaa !5
  %15 = load i8, ptr %13, align 1, !tbaa !11
  %16 = zext i8 %15 to i32
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = xor i32 %17, %16
  store i32 %18, ptr %6, align 4, !tbaa !9
  store i8 0, ptr %7, align 1, !tbaa !11
  br label %19

19:                                               ; preds = %35, %12
  %20 = load i8, ptr %7, align 1, !tbaa !11
  %21 = zext i8 %20 to i32
  %22 = icmp slt i32 %21, 8
  br i1 %22, label %23, label %38

23:                                               ; preds = %19
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = and i32 %24, 1
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %31

27:                                               ; preds = %23
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = lshr i32 %28, 1
  %30 = xor i32 %29, -306674912
  store i32 %30, ptr %6, align 4, !tbaa !9
  br label %34

31:                                               ; preds = %23
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = lshr i32 %32, 1
  store i32 %33, ptr %6, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %31, %27
  br label %35

35:                                               ; preds = %34
  %36 = load i8, ptr %7, align 1, !tbaa !11
  %37 = add i8 %36, 1
  store i8 %37, ptr %7, align 1, !tbaa !11
  br label %19, !llvm.loop !12

38:                                               ; preds = %19
  br label %8, !llvm.loop !14

39:                                               ; preds = %8
  %40 = load i32, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  ret i32 %40
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local i32 @fs_track_crc32(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %.not14 = icmp eq i32 %1, 0
  br i1 %.not14, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.in = phi i32 [ %4, %.lr.ph ], [ %1, %3 ]
  %.0816 = phi i32 [ %.2.7, %.lr.ph ], [ %2, %3 ]
  %.01015 = phi ptr [ %32, %.lr.ph ], [ %0, %3 ]
  %4 = add i32 %.in, -1
  %5 = load i8, ptr %.01015, align 1, !tbaa !5
  %6 = zext i8 %5 to i32
  %7 = xor i32 %.0816, %6
  %8 = and i32 %7, 1
  %.not11 = icmp eq i32 %8, 0
  %9 = lshr i32 %7, 1
  %10 = xor i32 %9, -306674912
  %.2 = select i1 %.not11, i32 %9, i32 %10
  %11 = and i32 %.2, 1
  %.not11.1 = icmp eq i32 %11, 0
  %12 = lshr i32 %.2, 1
  %13 = xor i32 %12, -306674912
  %.2.1 = select i1 %.not11.1, i32 %12, i32 %13
  %14 = and i32 %.2.1, 1
  %.not11.2 = icmp eq i32 %14, 0
  %15 = lshr i32 %.2.1, 1
  %16 = xor i32 %15, -306674912
  %.2.2 = select i1 %.not11.2, i32 %15, i32 %16
  %17 = and i32 %.2.2, 1
  %.not11.3 = icmp eq i32 %17, 0
  %18 = lshr i32 %.2.2, 1
  %19 = xor i32 %18, -306674912
  %.2.3 = select i1 %.not11.3, i32 %18, i32 %19
  %20 = and i32 %.2.3, 1
  %.not11.4 = icmp eq i32 %20, 0
  %21 = lshr i32 %.2.3, 1
  %22 = xor i32 %21, -306674912
  %.2.4 = select i1 %.not11.4, i32 %21, i32 %22
  %23 = and i32 %.2.4, 1
  %.not11.5 = icmp eq i32 %23, 0
  %24 = lshr i32 %.2.4, 1
  %25 = xor i32 %24, -306674912
  %.2.5 = select i1 %.not11.5, i32 %24, i32 %25
  %26 = and i32 %.2.5, 1
  %.not11.6 = icmp eq i32 %26, 0
  %27 = lshr i32 %.2.5, 1
  %28 = xor i32 %27, -306674912
  %.2.6 = select i1 %.not11.6, i32 %27, i32 %28
  %29 = and i32 %.2.6, 1
  %.not11.7 = icmp eq i32 %29, 0
  %30 = lshr i32 %.2.6, 1
  %31 = xor i32 %30, -306674912
  %.2.7 = select i1 %.not11.7, i32 %30, i32 %31
  %32 = getelementptr inbounds i8, ptr %.01015, i64 1
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !8

._crit_edge:                                      ; preds = %.lr.ph, %3
  %.08.lcssa = phi i32 [ %2, %3 ], [ %.2.7, %.lr.ph ]
  ret i32 %.08.lcssa
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) 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/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass