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

; 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.ProcessSlot = type { ptr, %struct.Process }
%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 }

@tableProcess = external dso_local global ptr, align 8

; 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
define dso_local ptr @getProcessFromPid(i32 noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %6 = load ptr, ptr @tableProcess, align 8, !tbaa !9
  store ptr %6, ptr %4, align 8, !tbaa !9
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = icmp eq i32 %7, -1
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %45

10:                                               ; preds = %1
  br label %11

11:                                               ; preds = %31, %10
  %12 = load ptr, ptr %4, align 8, !tbaa !9
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %21

14:                                               ; preds = %11
  %15 = load ptr, ptr %4, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.ProcessSlot, ptr %15, i32 0, i32 1
  %17 = getelementptr inbounds %struct.Process, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !11
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = icmp ne i32 %18, %19
  br label %21

21:                                               ; preds = %14, %11
  %22 = phi i1 [ false, %11 ], [ %20, %14 ]
  br i1 %22, label %23, label %32

23:                                               ; preds = %21
  %24 = load ptr, ptr %4, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.ProcessSlot, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  store ptr %26, ptr %4, align 8, !tbaa !9
  %27 = load ptr, ptr %4, align 8, !tbaa !9
  %28 = load ptr, ptr @tableProcess, align 8, !tbaa !9
  %29 = icmp eq ptr %27, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %23
  br label %32

31:                                               ; preds = %23
  br label %11, !llvm.loop !15

32:                                               ; preds = %30, %21
  %33 = load ptr, ptr %4, align 8, !tbaa !9
  %34 = icmp eq ptr %33, null
  br i1 %34, label %42, label %35

35:                                               ; preds = %32
  %36 = load ptr, ptr %4, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.ProcessSlot, ptr %36, i32 0, i32 1
  %38 = getelementptr inbounds %struct.Process, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !11
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = icmp ne i32 %39, %40
  br i1 %41, label %42, label %43

42:                                               ; preds = %35, %32
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %45

43:                                               ; preds = %35
  %44 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %44, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %45

45:                                               ; preds = %43, %42, %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %46 = load ptr, ptr %2, align 8
  ret ptr %46
}

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 = !{!"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, !6, i64 8}
!12 = !{!"ProcessSlot", !10, i64 0, !13, i64 8}
!13 = !{!"Process", !6, i64 0, !6, i64 4, !7, i64 8, !6, i64 128, !6, i64 132, !7, i64 136, !7, i64 192, !6, i64 352, !10, i64 360, !10, i64 368, !10, i64 376, !7, i64 384, !6, i64 464, !10, i64 472, !10, i64 480}
!14 = !{!12, !10, 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"

@tableProcess = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local ptr @getProcessFromPid(i32 noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq i32 %0, -1
  br i1 %2, label %.critedge.thread, label %3

3:                                                ; preds = %1
  %4 = load ptr, ptr @tableProcess, align 8, !tbaa !5
  %.old1.not = icmp eq ptr %4, null
  br i1 %.old1.not, label %.critedge.thread, label %.preheader

.preheader:                                       ; preds = %3, %7
  %.0 = phi ptr [ %8, %7 ], [ %4, %3 ]
  %5 = getelementptr inbounds i8, ptr %.0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %.not = icmp eq i32 %6, %0
  br i1 %.not, label %.critedge.thread18, label %7

7:                                                ; preds = %.preheader
  %8 = load ptr, ptr %.0, align 8, !tbaa !13
  %9 = icmp ne ptr %8, %4
  %10 = icmp ne ptr %8, null
  %or.cond = and i1 %9, %10
  br i1 %or.cond, label %.preheader, label %.critedge, !llvm.loop !14

.critedge:                                        ; preds = %7
  %11 = icmp eq ptr %8, null
  br i1 %11, label %.critedge.thread, label %.critedge..critedge.thread18_crit_edge

.critedge..critedge.thread18_crit_edge:           ; preds = %.critedge
  %.phi.trans.insert = getelementptr inbounds i8, ptr %8, i64 8
  %.pre = load i32, ptr %.phi.trans.insert, align 8, !tbaa !9
  br label %.critedge.thread18

.critedge.thread18:                               ; preds = %.preheader, %.critedge..critedge.thread18_crit_edge
  %12 = phi i32 [ %.pre, %.critedge..critedge.thread18_crit_edge ], [ %0, %.preheader ]
  %.120 = phi ptr [ %8, %.critedge..critedge.thread18_crit_edge ], [ %.0, %.preheader ]
  %.not16 = icmp eq i32 %12, %0
  %spec.select = select i1 %.not16, ptr %.120, ptr null
  br label %.critedge.thread

.critedge.thread:                                 ; preds = %3, %.critedge.thread18, %.critedge, %1
  %.011 = phi ptr [ null, %1 ], [ null, %.critedge ], [ %spec.select, %.critedge.thread18 ], [ null, %3 ]
  ret ptr %.011
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 8}
!10 = !{!"ProcessSlot", !6, i64 0, !11, i64 8}
!11 = !{!"Process", !12, i64 0, !12, i64 4, !7, i64 8, !12, i64 128, !12, i64 132, !7, i64 136, !7, i64 192, !12, i64 352, !6, i64 360, !6, i64 368, !6, i64 376, !7, i64 384, !12, i64 464, !6, i64 472, !6, i64 480}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !6, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass