; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Core (RuntimeDriverInitializeCrc32Table)

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

@mCrcTable = external dso_local global [256 x i32], align 16

; 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
declare dso_local i32 @ReverseBits(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @RuntimeDriverInitializeCrc32Table() #1 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i64 0, ptr %1, align 8, !tbaa !5
  br label %4

4:                                                ; preds = %34, %0
  %5 = load i64, ptr %1, align 8, !tbaa !5
  %6 = icmp ult i64 %5, 256
  br i1 %6, label %7, label %37

7:                                                ; preds = %4
  %8 = load i64, ptr %1, align 8, !tbaa !5
  %9 = trunc i64 %8 to i32
  %10 = call i32 @ReverseBits(i32 noundef %9)
  store i32 %10, ptr %3, align 4, !tbaa !9
  store i64 0, ptr %2, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %26, %7
  %12 = load i64, ptr %2, align 8, !tbaa !5
  %13 = icmp ult i64 %12, 8
  br i1 %13, label %14, label %29

14:                                               ; preds = %11
  %15 = load i32, ptr %3, align 4, !tbaa !9
  %16 = and i32 %15, -2147483648
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %22

18:                                               ; preds = %14
  %19 = load i32, ptr %3, align 4, !tbaa !9
  %20 = shl i32 %19, 1
  %21 = xor i32 %20, 79764919
  store i32 %21, ptr %3, align 4, !tbaa !9
  br label %25

22:                                               ; preds = %14
  %23 = load i32, ptr %3, align 4, !tbaa !9
  %24 = shl i32 %23, 1
  store i32 %24, ptr %3, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %22, %18
  br label %26

26:                                               ; preds = %25
  %27 = load i64, ptr %2, align 8, !tbaa !5
  %28 = add i64 %27, 1
  store i64 %28, ptr %2, align 8, !tbaa !5
  br label %11, !llvm.loop !11

29:                                               ; preds = %11
  %30 = load i32, ptr %3, align 4, !tbaa !9
  %31 = call i32 @ReverseBits(i32 noundef %30)
  %32 = load i64, ptr %1, align 8, !tbaa !5
  %33 = getelementptr inbounds [256 x i32], ptr @mCrcTable, i64 0, i64 %32
  store i32 %31, ptr %33, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %29
  %35 = load i64, ptr %1, align 8, !tbaa !5
  %36 = add i64 %35, 1
  store i64 %36, ptr %1, align 8, !tbaa !5
  br label %4, !llvm.loop !13

37:                                               ; preds = %4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #2
  ret void
}

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 = !{!"long long", !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@mCrcTable = external dso_local local_unnamed_addr global [256 x i32], align 16

; Function Attrs: nounwind uwtable
declare dso_local i32 @ReverseBits(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @RuntimeDriverInitializeCrc32Table() local_unnamed_addr #0 {
  br label %1

1:                                                ; preds = %0, %1
  %.01115 = phi i64 [ 0, %0 ], [ %22, %1 ]
  %2 = trunc nuw nsw i64 %.01115 to i32
  %3 = tail call i32 @ReverseBits(i32 noundef %2)
  %4 = shl i32 %3, 1
  %5 = xor i32 %4, 79764919
  %.not12 = icmp slt i32 %3, 0
  %.1 = select i1 %.not12, i32 %5, i32 %4
  %6 = shl i32 %.1, 1
  %7 = xor i32 %6, 79764919
  %.not12.1 = icmp slt i32 %.1, 0
  %.1.1 = select i1 %.not12.1, i32 %7, i32 %6
  %8 = shl i32 %.1.1, 1
  %9 = xor i32 %8, 79764919
  %.not12.2 = icmp slt i32 %.1.1, 0
  %.1.2 = select i1 %.not12.2, i32 %9, i32 %8
  %10 = shl i32 %.1.2, 1
  %11 = xor i32 %10, 79764919
  %.not12.3 = icmp slt i32 %.1.2, 0
  %.1.3 = select i1 %.not12.3, i32 %11, i32 %10
  %12 = shl i32 %.1.3, 1
  %13 = xor i32 %12, 79764919
  %.not12.4 = icmp slt i32 %.1.3, 0
  %.1.4 = select i1 %.not12.4, i32 %13, i32 %12
  %14 = shl i32 %.1.4, 1
  %15 = xor i32 %14, 79764919
  %.not12.5 = icmp slt i32 %.1.4, 0
  %.1.5 = select i1 %.not12.5, i32 %15, i32 %14
  %16 = shl i32 %.1.5, 1
  %17 = xor i32 %16, 79764919
  %.not12.6 = icmp slt i32 %.1.5, 0
  %.1.6 = select i1 %.not12.6, i32 %17, i32 %16
  %18 = shl i32 %.1.6, 1
  %19 = xor i32 %18, 79764919
  %.not12.7 = icmp slt i32 %.1.6, 0
  %.1.7 = select i1 %.not12.7, i32 %19, i32 %18
  %20 = tail call i32 @ReverseBits(i32 noundef %.1.7)
  %21 = getelementptr inbounds [256 x i32], ptr @mCrcTable, i64 0, i64 %.01115
  store i32 %20, ptr %21, align 4, !tbaa !5
  %22 = add nuw nsw i64 %.01115, 1
  %exitcond.not = icmp eq i64 %22, 256
  br i1 %exitcond.not, label %23, label %1, !llvm.loop !9

23:                                               ; preds = %1
  ret void
}

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

!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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass