; LLVM IR from LinearTapeFileSystem/ltfs :: src/tape_drivers (crc32c_crc)

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

@ltfs_log_level = external global i32, align 4
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 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: nounwind uwtable
declare hidden i32 @memcpy_crc32c(ptr noundef, ptr noundef, i64 noundef) #1

declare i32 @ltfsmsg_internal(i1 noundef zeroext, i32 noundef, ptr noundef, ptr noundef, ...) #2

; 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 @memcpy_crc32c_check(ptr noundef %0, ptr noundef %1, i64 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = load i64, ptr %7, align 8, !tbaa !9
  %14 = getelementptr inbounds i8, ptr %12, i64 %13
  store ptr %14, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = load i64, ptr %7, align 8, !tbaa !9
  %18 = call i32 @memcpy_crc32c(ptr noundef %15, ptr noundef %16, i64 noundef %17)
  store i32 %18, ptr %9, align 4, !tbaa !11
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i32 1
  store ptr %20, ptr %8, align 8, !tbaa !5
  %21 = load i8, ptr %19, align 1, !tbaa !13
  %22 = zext i8 %21 to i32
  store i32 %22, ptr %10, align 4, !tbaa !11
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i32 1
  store ptr %24, ptr %8, align 8, !tbaa !5
  %25 = load i8, ptr %23, align 1, !tbaa !13
  %26 = zext i8 %25 to i32
  %27 = shl i32 %26, 8
  %28 = load i32, ptr %10, align 4, !tbaa !11
  %29 = or i32 %28, %27
  store i32 %29, ptr %10, align 4, !tbaa !11
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i32 1
  store ptr %31, ptr %8, align 8, !tbaa !5
  %32 = load i8, ptr %30, align 1, !tbaa !13
  %33 = zext i8 %32 to i32
  %34 = shl i32 %33, 16
  %35 = load i32, ptr %10, align 4, !tbaa !11
  %36 = or i32 %35, %34
  store i32 %36, ptr %10, align 4, !tbaa !11
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i32 1
  store ptr %38, ptr %8, align 8, !tbaa !5
  %39 = load i8, ptr %37, align 1, !tbaa !13
  %40 = zext i8 %39 to i32
  %41 = shl i32 %40, 24
  %42 = load i32, ptr %10, align 4, !tbaa !11
  %43 = or i32 %42, %41
  store i32 %43, ptr %10, align 4, !tbaa !11
  %44 = load i32, ptr %10, align 4, !tbaa !11
  %45 = load i32, ptr %9, align 4, !tbaa !11
  %46 = icmp ne i32 %44, %45
  br i1 %46, label %47, label %60

47:                                               ; preds = %3
  br label %48

48:                                               ; preds = %47
  %49 = load i32, ptr @ltfs_log_level, align 4, !tbaa !11
  %50 = icmp sle i32 0, %49
  br i1 %50, label %51, label %57

51:                                               ; preds = %48
  %52 = load i64, ptr %7, align 8, !tbaa !9
  %53 = trunc i64 %52 to i32
  %54 = load i32, ptr %9, align 4, !tbaa !11
  %55 = load i32, ptr %10, align 4, !tbaa !11
  %56 = call i32 (i1, i32, ptr, ptr, ...) @ltfsmsg_internal(i1 noundef zeroext true, i32 noundef 0, ptr noundef null, ptr noundef @.str.2, i32 noundef %53, i32 noundef %54, i32 noundef %55)
  br label %57

57:                                               ; preds = %51, %48
  br label %58

58:                                               ; preds = %57
  br label %59

59:                                               ; preds = %58
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %74

60:                                               ; preds = %3
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr @ltfs_log_level, align 4, !tbaa !11
  %63 = icmp sle i32 3, %62
  br i1 %63, label %64, label %69

64:                                               ; preds = %61
  %65 = load i64, ptr %7, align 8, !tbaa !9
  %66 = trunc i64 %65 to i32
  %67 = load i32, ptr %10, align 4, !tbaa !11
  %68 = call i32 (i1, i32, ptr, ptr, ...) @ltfsmsg_internal(i1 noundef zeroext true, i32 noundef 3, ptr noundef null, ptr noundef @.str, ptr noundef @.str.3, i32 noundef %66, i32 noundef %67)
  br label %69

69:                                               ; preds = %64, %61
  br label %70

70:                                               ; preds = %69
  br label %71

71:                                               ; preds = %70
  %72 = load i64, ptr %7, align 8, !tbaa !9
  %73 = trunc i64 %72 to i32
  store i32 %73, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %74

74:                                               ; preds = %71, %59
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %75 = load i32, ptr %4, align 4
  ret i32 %75
}

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 = { "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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!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"

@ltfs_log_level = external local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nounwind uwtable
declare hidden i32 @memcpy_crc32c(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

declare i32 @ltfsmsg_internal(i1 noundef zeroext, i32 noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @memcpy_crc32c_check(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %1, i64 %2
  %5 = tail call i32 @memcpy_crc32c(ptr noundef %0, ptr noundef %1, i64 noundef %2)
  %6 = load i16, ptr %4, align 1
  %7 = zext i16 %6 to i32
  %8 = getelementptr inbounds i8, ptr %4, i64 2
  %9 = getelementptr inbounds i8, ptr %4, i64 3
  %10 = load i8, ptr %8, align 1, !tbaa !5
  %11 = zext i8 %10 to i32
  %12 = shl nuw nsw i32 %11, 16
  %13 = or disjoint i32 %12, %7
  %14 = load i8, ptr %9, align 1, !tbaa !5
  %15 = zext i8 %14 to i32
  %16 = shl nuw i32 %15, 24
  %17 = or disjoint i32 %13, %16
  %.not = icmp eq i32 %17, %5
  %18 = load i32, ptr @ltfs_log_level, align 4, !tbaa !8
  br i1 %.not, label %24, label %19

19:                                               ; preds = %3
  %20 = icmp sgt i32 %18, -1
  br i1 %20, label %21, label %._crit_edge

21:                                               ; preds = %19
  %22 = trunc i64 %2 to i32
  %23 = tail call i32 (i1, i32, ptr, ptr, ...) @ltfsmsg_internal(i1 noundef zeroext true, i32 noundef 0, ptr noundef null, ptr noundef nonnull @.str.2, i32 noundef %22, i32 noundef %5, i32 noundef %17) #2
  br label %._crit_edge

24:                                               ; preds = %3
  %25 = icmp sgt i32 %18, 2
  %26 = trunc i64 %2 to i32
  br i1 %25, label %27, label %._crit_edge

27:                                               ; preds = %24
  %28 = tail call i32 (i1, i32, ptr, ptr, ...) @ltfsmsg_internal(i1 noundef zeroext true, i32 noundef 3, ptr noundef null, ptr noundef nonnull @.str, ptr noundef nonnull @.str.3, i32 noundef %26, i32 noundef %5) #2
  br label %._crit_edge

._crit_edge:                                      ; preds = %24, %27, %19, %21
  %.0 = phi i32 [ -1, %21 ], [ -1, %19 ], [ %26, %27 ], [ %26, %24 ]
  ret i32 %.0
}

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


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