; LLVM IR from ChaCheeChoo/GAAS-Engine :: GWDGenSource (main)

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

7:                                                ; preds = %41, %1
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = zext i32 %9 to i64
  %11 = getelementptr inbounds i8, ptr %8, i64 %10
  %12 = load i8, ptr %11, align 1, !tbaa !11
  %13 = sext i8 %12 to i32
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %44

15:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #2
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = load i32, ptr %4, align 4, !tbaa !9
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds i8, ptr %16, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !11
  store i8 %20, ptr %5, align 1, !tbaa !11
  %21 = load i32, ptr %3, align 4, !tbaa !9
  %22 = load i8, ptr %5, align 1, !tbaa !11
  %23 = zext i8 %22 to i32
  %24 = xor i32 %21, %23
  store i32 %24, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #2
  store i8 8, ptr %6, align 1, !tbaa !11
  br label %25

25:                                               ; preds = %38, %15
  %26 = load i8, ptr %6, align 1, !tbaa !11
  %27 = zext i8 %26 to i32
  %28 = icmp sgt i32 %27, 0
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #2
  br label %41

30:                                               ; preds = %25
  %31 = load i32, ptr %3, align 4, !tbaa !9
  %32 = lshr i32 %31, 1
  %33 = load i32, ptr %3, align 4, !tbaa !9
  %34 = and i32 %33, 1
  %35 = sub i32 0, %34
  %36 = and i32 -306674912, %35
  %37 = xor i32 %32, %36
  store i32 %37, ptr %3, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %30
  %39 = load i8, ptr %6, align 1, !tbaa !11
  %40 = add i8 %39, -1
  store i8 %40, ptr %6, align 1, !tbaa !11
  br label %25, !llvm.loop !12

41:                                               ; preds = %29
  %42 = load i32, ptr %4, align 4, !tbaa !9
  %43 = add i32 %42, 1
  store i32 %43, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #2
  br label %7, !llvm.loop !14

44:                                               ; preds = %7
  %45 = load i32, ptr %3, align 4, !tbaa !9
  %46 = xor i32 %45, -1
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %46
}

; 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 = { 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 = !{!"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(argmem: read) uwtable
define dso_local i32 @crc32(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = load i8, ptr %0, align 1, !tbaa !5
  %.not16 = icmp eq i8 %2, 0
  br i1 %.not16, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  %3 = phi i8 [ %32, %.lr.ph ], [ %2, %1 ]
  %.01118 = phi i32 [ %op.rdx20, %.lr.ph ], [ -1, %1 ]
  %.01217 = phi i32 [ %29, %.lr.ph ], [ 0, %1 ]
  %4 = zext i8 %3 to i32
  %5 = xor i32 %.01118, %4
  %6 = lshr i32 %5, 1
  %7 = and i32 %5, 1
  %8 = icmp eq i32 %7, 0
  %9 = select i1 %8, i32 0, i32 -306674912
  %10 = xor i32 %9, %6
  %11 = lshr i32 %10, 1
  %12 = and i32 %5, 2
  %13 = icmp eq i32 %12, 0
  %14 = select i1 %13, i32 0, i32 -306674912
  %15 = xor i32 %14, %11
  %16 = lshr i32 %15, 6
  %17 = insertelement <4 x i32> poison, i32 %5, i64 0
  %18 = shufflevector <4 x i32> %17, <4 x i32> poison, <4 x i32> zeroinitializer
  %19 = and <4 x i32> %18, <i32 4, i32 8, i32 16, i32 32>
  %20 = icmp eq <4 x i32> %19, zeroinitializer
  %21 = select <4 x i1> %20, <4 x i32> zeroinitializer, <4 x i32> <i32 124634137, i32 249268274, i32 498536548, i32 997073096>
  %22 = and i32 %10, 32
  %23 = icmp eq i32 %22, 0
  %24 = select i1 %23, i32 0, i32 1994146192
  %25 = and i32 %15, 32
  %26 = icmp eq i32 %25, 0
  %27 = select i1 %26, i32 0, i32 -306674912
  %28 = tail call i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> %21)
  %op.rdx = xor i32 %28, %24
  %op.rdx19 = xor i32 %27, %16
  %op.rdx20 = xor i32 %op.rdx, %op.rdx19
  %29 = add i32 %.01217, 1
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds i8, ptr %0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !5
  %.not = icmp eq i8 %32, 0
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !8

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %33 = xor i32 %op.rdx20, -1
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  %.011.lcssa = phi i32 [ 0, %1 ], [ %33, %._crit_edge.loopexit ]
  ret i32 %.011.lcssa
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.xor.v4i32(<4 x i32>) #1

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: read) 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 speculatable willreturn memory(none) }

!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,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass