; LLVM IR from rociodellasala/TP3_SO :: Kernel (scheduler)

; 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.Process = type { i32, i32, [30 x i32], i32, i32, [50 x i8], [20 x ptr], i32, ptr, ptr, ptr, [10 x ptr], i32, ptr, ptr }
%struct.ThreadSlot = type { ptr, %struct.Thread }
%struct.Thread = type { i32, ptr, ptr, ptr, i32, i32 }

; 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
define dso_local void @deleteThreadFromProcess(ptr dead_on_unwind noalias writable sret(%struct.Process) align 8 %0, ptr noundef byval(%struct.Process) align 8 %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %5 = getelementptr inbounds %struct.Process, ptr %1, i32 0, i32 8
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %6, ptr %3, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  br label %7

7:                                                ; preds = %18, %2
  %8 = load ptr, ptr %3, align 8, !tbaa !11
  %9 = getelementptr inbounds %struct.ThreadSlot, ptr %8, i32 0, i32 1
  %10 = getelementptr inbounds %struct.Thread, ptr %9, i32 0, i32 0
  %11 = load i32, ptr %10, align 8, !tbaa !12
  %12 = getelementptr inbounds %struct.Process, ptr %1, i32 0, i32 9
  %13 = load ptr, ptr %12, align 8, !tbaa !15
  %14 = getelementptr inbounds %struct.ThreadSlot, ptr %13, i32 0, i32 1
  %15 = getelementptr inbounds %struct.Thread, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !12
  %17 = icmp ne i32 %11, %16
  br i1 %17, label %18, label %23

18:                                               ; preds = %7
  %19 = load ptr, ptr %3, align 8, !tbaa !11
  store ptr %19, ptr %4, align 8, !tbaa !11
  %20 = load ptr, ptr %3, align 8, !tbaa !11
  %21 = getelementptr inbounds %struct.ThreadSlot, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !16
  store ptr %22, ptr %3, align 8, !tbaa !11
  br label %7, !llvm.loop !17

23:                                               ; preds = %7
  %24 = load ptr, ptr %3, align 8, !tbaa !11
  %25 = getelementptr inbounds %struct.ThreadSlot, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  %27 = load ptr, ptr %4, align 8, !tbaa !11
  %28 = getelementptr inbounds %struct.ThreadSlot, ptr %27, i32 0, i32 0
  store ptr %26, ptr %28, align 8, !tbaa !16
  %29 = getelementptr inbounds %struct.Process, ptr %1, i32 0, i32 7
  %30 = load i32, ptr %29, align 8, !tbaa !19
  %31 = add nsw i32 %30, -1
  store i32 %31, ptr %29, align 8, !tbaa !19
  %32 = getelementptr inbounds %struct.Process, ptr %1, i32 0, i32 7
  %33 = load i32, ptr %32, align 8, !tbaa !19
  %34 = icmp eq i32 %33, 1
  br i1 %34, label %35, label %47

35:                                               ; preds = %23
  %36 = getelementptr inbounds %struct.Process, ptr %1, i32 0, i32 8
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ThreadSlot, ptr %37, i32 0, i32 1
  %39 = getelementptr inbounds %struct.Thread, ptr %38, i32 0, i32 4
  %40 = load i32, ptr %39, align 8, !tbaa !20
  %41 = icmp eq i32 %40, 4
  br i1 %41, label %42, label %47

42:                                               ; preds = %35
  %43 = getelementptr inbounds %struct.Process, ptr %1, i32 0, i32 8
  %44 = load ptr, ptr %43, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.ThreadSlot, ptr %44, i32 0, i32 1
  %46 = getelementptr inbounds %struct.Thread, ptr %45, i32 0, i32 4
  store i32 3, ptr %46, align 8, !tbaa !20
  br label %47

47:                                               ; preds = %42, %35, %23
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %0, ptr align 8 %1, i64 488, i1 false), !tbaa.struct !21
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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, !10, i64 360}
!6 = !{!"Process", !7, i64 0, !7, i64 4, !8, i64 8, !7, i64 128, !7, i64 132, !8, i64 136, !8, i64 192, !7, i64 352, !10, i64 360, !10, i64 368, !10, i64 376, !8, i64 384, !7, i64 464, !10, i64 472, !10, i64 480}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!13, !7, i64 8}
!13 = !{!"ThreadSlot", !10, i64 0, !14, i64 8}
!14 = !{!"Thread", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !7, i64 32, !7, i64 36}
!15 = !{!6, !10, i64 368}
!16 = !{!13, !10, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!6, !7, i64 352}
!20 = !{!13, !7, i64 40}
!21 = !{i64 0, i64 4, !22, i64 4, i64 4, !22, i64 8, i64 120, !23, i64 128, i64 4, !22, i64 132, i64 4, !22, i64 136, i64 50, !23, i64 192, i64 160, !23, i64 352, i64 4, !22, i64 360, i64 8, !11, i64 368, i64 8, !11, i64 376, i64 8, !11, i64 384, i64 80, !23, i64 464, i64 4, !22, i64 472, i64 8, !11, i64 480, i64 8, !11}
!22 = !{!7, !7, i64 0}
!23 = !{!8, !8, 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"

%struct.Process = type { i32, i32, [30 x i32], i32, i32, [50 x i8], [20 x ptr], i32, ptr, ptr, ptr, [10 x ptr], i32, ptr, ptr }

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @deleteThreadFromProcess(ptr dead_on_unwind noalias nocapture writable writeonly sret(%struct.Process) align 8 %0, ptr nocapture noundef byval(%struct.Process) align 8 %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %1, i64 360
  %4 = getelementptr inbounds i8, ptr %1, i64 368
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 8
  %7 = load i32, ptr %6, align 8, !tbaa !11
  br label %8

8:                                                ; preds = %8, %2
  %.05.in = phi ptr [ %3, %2 ], [ %.05, %8 ]
  %.0 = phi ptr [ undef, %2 ], [ %.05, %8 ]
  %.05 = load ptr, ptr %.05.in, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %.05, i64 8
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %.not = icmp eq i32 %10, %7
  br i1 %.not, label %11, label %8, !llvm.loop !15

11:                                               ; preds = %8
  %12 = load ptr, ptr %.05, align 8, !tbaa !17
  store ptr %12, ptr %.0, align 8, !tbaa !17
  %13 = getelementptr inbounds i8, ptr %1, i64 352
  %14 = load i32, ptr %13, align 8, !tbaa !18
  %15 = add nsw i32 %14, -1
  store i32 %15, ptr %13, align 8, !tbaa !18
  %16 = icmp eq i32 %15, 1
  br i1 %16, label %17, label %23

17:                                               ; preds = %11
  %18 = load ptr, ptr %3, align 8, !tbaa !19
  %19 = getelementptr inbounds i8, ptr %18, i64 40
  %20 = load i32, ptr %19, align 8, !tbaa !20
  %21 = icmp eq i32 %20, 4
  br i1 %21, label %22, label %23

22:                                               ; preds = %17
  store i32 3, ptr %19, align 8, !tbaa !20
  br label %23

23:                                               ; preds = %22, %17, %11
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(488) %0, ptr noundef nonnull align 8 dereferenceable(488) %1, i64 488, i1 false), !tbaa.struct !21
  ret void
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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, !10, i64 368}
!6 = !{!"Process", !7, i64 0, !7, i64 4, !8, i64 8, !7, i64 128, !7, i64 132, !8, i64 136, !8, i64 192, !7, i64 352, !10, i64 360, !10, i64 368, !10, i64 376, !8, i64 384, !7, i64 464, !10, i64 472, !10, i64 480}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !7, i64 8}
!12 = !{!"ThreadSlot", !10, i64 0, !13, i64 8}
!13 = !{!"Thread", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !7, i64 32, !7, i64 36}
!14 = !{!10, !10, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!12, !10, i64 0}
!18 = !{!6, !7, i64 352}
!19 = !{!6, !10, i64 360}
!20 = !{!12, !7, i64 40}
!21 = !{i64 0, i64 4, !22, i64 4, i64 4, !22, i64 8, i64 120, !23, i64 128, i64 4, !22, i64 132, i64 4, !22, i64 136, i64 50, !23, i64 192, i64 160, !23, i64 352, i64 4, !22, i64 360, i64 8, !14, i64 368, i64 8, !14, i64 376, i64 8, !14, i64 384, i64 80, !23, i64 464, i64 4, !22, i64 472, i64 8, !14, i64 480, i64 8, !14}
!22 = !{!7, !7, i64 0}
!23 = !{!8, !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass