; LLVM IR from s-matyukevich/raspberry-pi-os :: exercises/lesson04/1/rs/src (sched)

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

%struct.task_struct = type { %struct.cpu_context, i64, i64, i64, i64 }
%struct.cpu_context = type { i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64 }

@task = external dso_local global [3 x ptr], align 16
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1

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

4:                                                ; preds = %22, %0
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = icmp slt i32 %5, 3
  br i1 %6, label %8, label %7

7:                                                ; preds = %4
  store i32 2, ptr %3, align 4
  br label %25

8:                                                ; preds = %4
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [3 x ptr], ptr @task, i64 0, i64 %10
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  store ptr %12, ptr %1, align 8, !tbaa !9
  %13 = load ptr, ptr %1, align 8, !tbaa !9
  %14 = icmp ne ptr %13, null
  br i1 %14, label %16, label %15

15:                                               ; preds = %8
  store i32 1, ptr %3, align 4
  br label %25

16:                                               ; preds = %8
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = load ptr, ptr %1, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.task_struct, ptr %18, i32 0, i32 0
  %20 = getelementptr inbounds %struct.cpu_context, ptr %19, i32 0, i32 11
  %21 = load i64, ptr %20, align 8, !tbaa !11
  call void (ptr, ...) @tfp_printf(ptr noundef @.str.1, i32 noundef %17, i64 noundef %21)
  br label %22

22:                                               ; preds = %16
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %2, align 4, !tbaa !5
  br label %4, !llvm.loop !15

25:                                               ; preds = %15, %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  %26 = load i32, ptr %3, align 4
  switch i32 %26, label %28 [
    i32 2, label %27
  ]

27:                                               ; preds = %25
  store i32 0, ptr %3, align 4
  br label %28

28:                                               ; preds = %27, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  %29 = load i32, ptr %3, align 4
  switch i32 %29, label %31 [
    i32 0, label %30
    i32 1, label %30
  ]

30:                                               ; preds = %28, %28
  ret void

31:                                               ; preds = %28
  unreachable
}

declare void @tfp_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

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

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !14, i64 88}
!12 = !{!"task_struct", !13, i64 0, !14, i64 104, !14, i64 112, !14, i64 120, !14, i64 128}
!13 = !{!"cpu_context", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !14, i64 40, !14, i64 48, !14, i64 56, !14, i64 64, !14, i64 72, !14, i64 80, !14, i64 88, !14, i64 96}
!14 = !{!"long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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

@task = external dso_local local_unnamed_addr global [3 x ptr], align 16
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @print_debug_tasks() local_unnamed_addr #0 {
  tail call void (ptr, ...) @tfp_printf(ptr noundef nonnull @.str) #2
  %1 = load ptr, ptr @task, align 16, !tbaa !5
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %13, label %2

2:                                                ; preds = %0
  %3 = getelementptr inbounds i8, ptr %1, i64 88
  %4 = load i64, ptr %3, align 8, !tbaa !9
  tail call void (ptr, ...) @tfp_printf(ptr noundef nonnull @.str.1, i32 noundef 0, i64 noundef %4) #2
  %5 = load ptr, ptr getelementptr inbounds (i8, ptr @task, i64 8), align 8, !tbaa !5
  %.not.1 = icmp eq ptr %5, null
  br i1 %.not.1, label %13, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %5, i64 88
  %8 = load i64, ptr %7, align 8, !tbaa !9
  tail call void (ptr, ...) @tfp_printf(ptr noundef nonnull @.str.1, i32 noundef 1, i64 noundef %8) #2
  %9 = load ptr, ptr getelementptr inbounds (i8, ptr @task, i64 16), align 16, !tbaa !5
  %.not.2 = icmp eq ptr %9, null
  br i1 %.not.2, label %13, label %10

10:                                               ; preds = %6
  %11 = getelementptr inbounds i8, ptr %9, i64 88
  %12 = load i64, ptr %11, align 8, !tbaa !9
  tail call void (ptr, ...) @tfp_printf(ptr noundef nonnull @.str.1, i32 noundef 2, i64 noundef %12) #2
  br label %13

13:                                               ; preds = %10, %6, %2, %0
  ret void
}

declare void @tfp_printf(ptr 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 88}
!10 = !{!"task_struct", !11, i64 0, !12, i64 104, !12, i64 112, !12, i64 120, !12, i64 128}
!11 = !{!"cpu_context", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96}
!12 = !{!"long", !7, i64 0}


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