; LLVM IR from narke/Aragveli :: src/kernel/arch/x86 (smp)

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

@.str = external hidden unnamed_addr constant [20 x i8], align 1
@g_activeCpuCount = external global i8, align 1
@g_acpiCpuCount = external global i64, align 8
@g_acpiCpuIds = external global [16 x i8], align 16
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @SmpInit() #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  call void (ptr, ...) @printf(ptr noundef @.str)
  store volatile i8 1, ptr @g_activeCpuCount, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  %6 = call i64 (...) @LocalApicGetId()
  store i64 %6, ptr %1, align 8, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  store i64 0, ptr %2, align 8, !tbaa !8
  br label %7

7:                                                ; preds = %23, %0
  %8 = load i64, ptr %2, align 8, !tbaa !8
  %9 = load i64, ptr @g_acpiCpuCount, align 8, !tbaa !8
  %10 = icmp ult i64 %8, %9
  br i1 %10, label %12, label %11

11:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  br label %26

12:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %13 = load i64, ptr %2, align 8, !tbaa !8
  %14 = getelementptr inbounds [16 x i8], ptr @g_acpiCpuIds, i64 0, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %16 = zext i8 %15 to i64
  store i64 %16, ptr %3, align 8, !tbaa !8
  %17 = load i64, ptr %3, align 8, !tbaa !8
  %18 = load i64, ptr %1, align 8, !tbaa !8
  %19 = icmp ne i64 %17, %18
  br i1 %19, label %20, label %22

20:                                               ; preds = %12
  %21 = load i64, ptr %3, align 8, !tbaa !8
  call void @LocalApicSendInit(i64 noundef %21)
  br label %22

22:                                               ; preds = %20, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  br label %23

23:                                               ; preds = %22
  %24 = load i64, ptr %2, align 8, !tbaa !8
  %25 = add i64 %24, 1
  store i64 %25, ptr %2, align 8, !tbaa !8
  br label %7, !llvm.loop !10

26:                                               ; preds = %11
  call void @PitWait(i64 noundef 10)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store i64 0, ptr %4, align 8, !tbaa !8
  br label %27

27:                                               ; preds = %43, %26
  %28 = load i64, ptr %4, align 8, !tbaa !8
  %29 = load i64, ptr @g_acpiCpuCount, align 8, !tbaa !8
  %30 = icmp ult i64 %28, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %46

32:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %33 = load i64, ptr %4, align 8, !tbaa !8
  %34 = getelementptr inbounds [16 x i8], ptr @g_acpiCpuIds, i64 0, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !5
  %36 = zext i8 %35 to i64
  store i64 %36, ptr %5, align 8, !tbaa !8
  %37 = load i64, ptr %5, align 8, !tbaa !8
  %38 = load i64, ptr %1, align 8, !tbaa !8
  %39 = icmp ne i64 %37, %38
  br i1 %39, label %40, label %42

40:                                               ; preds = %32
  %41 = load i64, ptr %5, align 8, !tbaa !8
  call void @LocalApicSendStartup(i64 noundef %41, i64 noundef 8)
  br label %42

42:                                               ; preds = %40, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %43

43:                                               ; preds = %42
  %44 = load i64, ptr %4, align 8, !tbaa !8
  %45 = add i64 %44, 1
  store i64 %45, ptr %4, align 8, !tbaa !8
  br label %27, !llvm.loop !12

46:                                               ; preds = %31
  call void @PitWait(i64 noundef 1)
  br label %47

47:                                               ; preds = %52, %46
  %48 = load volatile i8, ptr @g_activeCpuCount, align 1, !tbaa !5
  %49 = zext i8 %48 to i64
  %50 = load i64, ptr @g_acpiCpuCount, align 8, !tbaa !8
  %51 = icmp ne i64 %49, %50
  br i1 %51, label %52, label %55

52:                                               ; preds = %47
  %53 = load volatile i8, ptr @g_activeCpuCount, align 1, !tbaa !5
  %54 = zext i8 %53 to i32
  call void (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %54)
  call void @PitWait(i64 noundef 1)
  br label %47, !llvm.loop !13

55:                                               ; preds = %47
  call void (ptr, ...) @printf(ptr noundef @.str.2)
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret void
}

declare void @printf(ptr noundef, ...) #1

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

declare i64 @LocalApicGetId(...) #1

declare void @LocalApicSendInit(i64 noundef) #1

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

declare void @PitWait(i64 noundef) #1

declare void @LocalApicSendStartup(i64 noundef, i64 noundef) #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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"long", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}


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

@.str = external hidden unnamed_addr constant [20 x i8], align 1
@g_activeCpuCount = external global i8, align 1
@g_acpiCpuCount = external local_unnamed_addr global i64, align 8
@g_acpiCpuIds = external local_unnamed_addr global [16 x i8], align 16
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @SmpInit() local_unnamed_addr #0 {
  tail call void (ptr, ...) @printf(ptr noundef nonnull @.str) #2
  store volatile i8 1, ptr @g_activeCpuCount, align 1, !tbaa !5
  %1 = tail call i64 (...) @LocalApicGetId() #2
  %2 = load i64, ptr @g_acpiCpuCount, align 8, !tbaa !8
  %.not26 = icmp eq i64 %2, 0
  br i1 %.not26, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %9, %0
  tail call void @PitWait(i64 noundef 10) #2
  %3 = load i64, ptr @g_acpiCpuCount, align 8, !tbaa !8
  %.not27 = icmp eq i64 %3, 0
  br i1 %.not27, label %._crit_edge21, label %.lr.ph20

.lr.ph:                                           ; preds = %0, %9
  %4 = phi i64 [ %10, %9 ], [ %2, %0 ]
  %.017 = phi i64 [ %11, %9 ], [ 0, %0 ]
  %5 = getelementptr inbounds [16 x i8], ptr @g_acpiCpuIds, i64 0, i64 %.017
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %7 = zext i8 %6 to i64
  %.not16 = icmp eq i64 %1, %7
  br i1 %.not16, label %9, label %8

8:                                                ; preds = %.lr.ph
  tail call void @LocalApicSendInit(i64 noundef %7) #2
  %.pre = load i64, ptr @g_acpiCpuCount, align 8, !tbaa !8
  br label %9

9:                                                ; preds = %8, %.lr.ph
  %10 = phi i64 [ %.pre, %8 ], [ %4, %.lr.ph ]
  %11 = add nuw i64 %.017, 1
  %12 = icmp ult i64 %11, %10
  br i1 %12, label %.lr.ph, label %._crit_edge, !llvm.loop !10

._crit_edge21:                                    ; preds = %21, %._crit_edge
  tail call void @PitWait(i64 noundef 1) #2
  %13 = load volatile i8, ptr @g_activeCpuCount, align 1, !tbaa !5
  %14 = zext i8 %13 to i64
  %15 = load i64, ptr @g_acpiCpuCount, align 8, !tbaa !8
  %.not22 = icmp eq i64 %15, %14
  br i1 %.not22, label %._crit_edge25, label %.lr.ph24

.lr.ph20:                                         ; preds = %._crit_edge, %21
  %16 = phi i64 [ %22, %21 ], [ %3, %._crit_edge ]
  %.01218 = phi i64 [ %23, %21 ], [ 0, %._crit_edge ]
  %17 = getelementptr inbounds [16 x i8], ptr @g_acpiCpuIds, i64 0, i64 %.01218
  %18 = load i8, ptr %17, align 1, !tbaa !5
  %19 = zext i8 %18 to i64
  %.not15 = icmp eq i64 %1, %19
  br i1 %.not15, label %21, label %20

20:                                               ; preds = %.lr.ph20
  tail call void @LocalApicSendStartup(i64 noundef %19, i64 noundef 8) #2
  %.pre28 = load i64, ptr @g_acpiCpuCount, align 8, !tbaa !8
  br label %21

21:                                               ; preds = %20, %.lr.ph20
  %22 = phi i64 [ %.pre28, %20 ], [ %16, %.lr.ph20 ]
  %23 = add nuw i64 %.01218, 1
  %24 = icmp ult i64 %23, %22
  br i1 %24, label %.lr.ph20, label %._crit_edge21, !llvm.loop !12

.lr.ph24:                                         ; preds = %._crit_edge21, %.lr.ph24
  %25 = load volatile i8, ptr @g_activeCpuCount, align 1, !tbaa !5
  %26 = zext i8 %25 to i32
  tail call void (ptr, ...) @printf(ptr noundef nonnull @.str.1, i32 noundef %26) #2
  tail call void @PitWait(i64 noundef 1) #2
  %27 = load volatile i8, ptr @g_activeCpuCount, align 1, !tbaa !5
  %28 = zext i8 %27 to i64
  %29 = load i64, ptr @g_acpiCpuCount, align 8, !tbaa !8
  %.not = icmp eq i64 %29, %28
  br i1 %.not, label %._crit_edge25, label %.lr.ph24, !llvm.loop !13

._crit_edge25:                                    ; preds = %.lr.ph24, %._crit_edge21
  tail call void (ptr, ...) @printf(ptr noundef nonnull @.str.2) #2
  ret void
}

declare void @printf(ptr noundef, ...) local_unnamed_addr #1

declare i64 @LocalApicGetId(...) local_unnamed_addr #1

declare void @LocalApicSendInit(i64 noundef) local_unnamed_addr #1

declare void @PitWait(i64 noundef) local_unnamed_addr #1

declare void @LocalApicSendStartup(i64 noundef, i64 noundef) local_unnamed_addr #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 = { "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 = !{!"long", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass