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

@allProcess = external dso_local global i32, align 4
@tableProcess = external dso_local global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [13 x i8], align 1

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

4:                                                ; preds = %69, %0
  %5 = load ptr, ptr %1, align 8, !tbaa !5
  %6 = icmp ne ptr %5, null
  br i1 %6, label %7, label %11

7:                                                ; preds = %4
  %8 = load i32, ptr %2, align 4, !tbaa !9
  %9 = load i32, ptr @allProcess, align 4, !tbaa !9
  %10 = icmp slt i32 %8, %9
  br label %11

11:                                               ; preds = %7, %4
  %12 = phi i1 [ false, %4 ], [ %10, %7 ]
  br i1 %12, label %13, label %80

13:                                               ; preds = %11
  call void @print_string(ptr noundef @.str.3)
  %14 = load ptr, ptr %1, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.ProcessSlot, ptr %14, i32 0, i32 1
  %16 = getelementptr inbounds %struct.Process, ptr %15, i32 0, i32 5
  %17 = getelementptr inbounds [50 x i8], ptr %16, i64 0, i64 0
  call void @print_string(ptr noundef %17)
  call void @print_string(ptr noundef @.str.4)
  %18 = load ptr, ptr %1, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.ProcessSlot, ptr %18, i32 0, i32 1
  %20 = getelementptr inbounds %struct.Process, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !11
  %22 = sext i32 %21 to i64
  call void @print_int(i64 noundef %22)
  %23 = load ptr, ptr %1, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.ProcessSlot, ptr %23, i32 0, i32 1
  %25 = getelementptr inbounds %struct.Process, ptr %24, i32 0, i32 10
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %29

28:                                               ; preds = %13
  call void @print_string(ptr noundef @.str.5)
  br label %30

29:                                               ; preds = %13
  call void @print_string(ptr noundef @.str.6)
  br label %30

30:                                               ; preds = %29, %28
  call void @print_string(ptr noundef @.str.7)
  %31 = load ptr, ptr %1, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ProcessSlot, ptr %31, i32 0, i32 1
  %33 = getelementptr inbounds %struct.Process, ptr %32, i32 0, i32 3
  %34 = load i32, ptr %33, align 8, !tbaa !15
  %35 = icmp eq i32 %34, 2
  br i1 %35, label %36, label %37

36:                                               ; preds = %30
  call void @print_string(ptr noundef @.str.8)
  br label %54

37:                                               ; preds = %30
  %38 = load ptr, ptr %1, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ProcessSlot, ptr %38, i32 0, i32 1
  %40 = getelementptr inbounds %struct.Process, ptr %39, i32 0, i32 3
  %41 = load i32, ptr %40, align 8, !tbaa !15
  %42 = icmp eq i32 %41, 3
  br i1 %42, label %43, label %44

43:                                               ; preds = %37
  call void @print_string(ptr noundef @.str.9)
  br label %53

44:                                               ; preds = %37
  %45 = load ptr, ptr %1, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.ProcessSlot, ptr %45, i32 0, i32 1
  %47 = getelementptr inbounds %struct.Process, ptr %46, i32 0, i32 3
  %48 = load i32, ptr %47, align 8, !tbaa !15
  %49 = icmp eq i32 %48, 4
  br i1 %49, label %50, label %51

50:                                               ; preds = %44
  call void @print_string(ptr noundef @.str.10)
  br label %52

51:                                               ; preds = %44
  call void @print_string(ptr noundef @.str.11)
  br label %52

52:                                               ; preds = %51, %50
  br label %53

53:                                               ; preds = %52, %43
  br label %54

54:                                               ; preds = %53, %36
  %55 = load ptr, ptr %1, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.ProcessSlot, ptr %55, i32 0, i32 1
  %57 = getelementptr inbounds %struct.Process, ptr %56, i32 0, i32 4
  %58 = load i32, ptr %57, align 4, !tbaa !16
  %59 = icmp eq i32 %58, 0
  br i1 %59, label %60, label %61

60:                                               ; preds = %54
  call void @print_string(ptr noundef @.str.12)
  br label %69

61:                                               ; preds = %54
  %62 = load ptr, ptr %1, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.ProcessSlot, ptr %62, i32 0, i32 1
  %64 = getelementptr inbounds %struct.Process, ptr %63, i32 0, i32 4
  %65 = load i32, ptr %64, align 4, !tbaa !16
  %66 = icmp eq i32 %65, 1
  br i1 %66, label %67, label %68

67:                                               ; preds = %61
  call void @print_string(ptr noundef @.str.13)
  br label %68

68:                                               ; preds = %67, %61
  br label %69

69:                                               ; preds = %68, %60
  call void @print_string(ptr noundef @.str.14)
  %70 = load ptr, ptr %1, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.ProcessSlot, ptr %70, i32 0, i32 1
  %72 = getelementptr inbounds %struct.Process, ptr %71, i32 0, i32 7
  %73 = load i32, ptr %72, align 8, !tbaa !17
  %74 = sext i32 %73 to i64
  call void @print_int(i64 noundef %74)
  call void (...) @nextLine()
  %75 = load i32, ptr %2, align 4, !tbaa !9
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %2, align 4, !tbaa !9
  %77 = load ptr, ptr %1, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.ProcessSlot, ptr %77, i32 0, i32 0
  %79 = load ptr, ptr %78, align 8, !tbaa !18
  store ptr %79, ptr %1, align 8, !tbaa !5
  br label %4, !llvm.loop !19

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

declare void @print_string(ptr noundef) #2

declare void @print_int(i64 noundef) #2

declare void @nextLine(...) #2

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 = { "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, !6, i64 0}
!6 = !{!"any pointer", !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 = !{!12, !10, i64 8}
!12 = !{!"ProcessSlot", !6, i64 0, !13, i64 8}
!13 = !{!"Process", !10, i64 0, !10, i64 4, !7, i64 8, !10, i64 128, !10, i64 132, !7, i64 136, !7, i64 192, !10, i64 352, !6, i64 360, !6, i64 368, !6, i64 376, !7, i64 384, !10, i64 464, !6, i64 472, !6, i64 480}
!14 = !{!12, !6, i64 384}
!15 = !{!12, !10, i64 136}
!16 = !{!12, !10, i64 140}
!17 = !{!12, !10, i64 360}
!18 = !{!12, !6, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"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"

@allProcess = external dso_local local_unnamed_addr global i32, align 4
@tableProcess = external dso_local local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [13 x i8], align 1
@switch.table.printAllCurrentProcess = private unnamed_addr constant [3 x ptr] [ptr @.str.8, ptr @.str.9, ptr @.str.10], align 8

; Function Attrs: nounwind uwtable
define dso_local void @printAllCurrentProcess() local_unnamed_addr #0 {
  %1 = load ptr, ptr @tableProcess, align 8, !tbaa !5
  tail call void @print_string(ptr noundef nonnull @.str.2) #2
  %2 = icmp ne ptr %1, null
  %3 = load i32, ptr @allProcess, align 4
  %4 = icmp sgt i32 %3, 0
  %5 = select i1 %2, i1 %4, i1 false
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %21
  %.016 = phi i32 [ %25, %21 ], [ 0, %0 ]
  %.01215 = phi ptr [ %26, %21 ], [ %1, %0 ]
  tail call void @print_string(ptr noundef nonnull @.str.3) #2
  %6 = getelementptr inbounds i8, ptr %.01215, i64 8
  %7 = getelementptr inbounds i8, ptr %.01215, i64 144
  tail call void @print_string(ptr noundef nonnull %7) #2
  tail call void @print_string(ptr noundef nonnull @.str.4) #2
  %8 = load i32, ptr %6, align 8, !tbaa !9
  %9 = sext i32 %8 to i64
  tail call void @print_int(i64 noundef %9) #2
  %10 = getelementptr inbounds i8, ptr %.01215, i64 384
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %12 = icmp eq ptr %11, null
  %.str.5..str.6 = select i1 %12, ptr @.str.5, ptr @.str.6
  tail call void @print_string(ptr noundef nonnull %.str.5..str.6) #2
  tail call void @print_string(ptr noundef nonnull @.str.7) #2
  %13 = getelementptr inbounds i8, ptr %.01215, i64 136
  %14 = load i32, ptr %13, align 8, !tbaa !14
  %switch.tableidx = add i32 %14, -2
  %15 = icmp ult i32 %switch.tableidx, 3
  br i1 %15, label %switch.lookup, label %17

switch.lookup:                                    ; preds = %.lr.ph
  %16 = zext nneg i32 %switch.tableidx to i64
  %switch.gep = getelementptr inbounds [3 x ptr], ptr @switch.table.printAllCurrentProcess, i64 0, i64 %16
  %switch.load = load ptr, ptr %switch.gep, align 8
  br label %17

17:                                               ; preds = %.lr.ph, %switch.lookup
  %.str.9.sink = phi ptr [ %switch.load, %switch.lookup ], [ @.str.11, %.lr.ph ]
  tail call void @print_string(ptr noundef nonnull %.str.9.sink) #2
  %18 = getelementptr inbounds i8, ptr %.01215, i64 140
  %19 = load i32, ptr %18, align 4, !tbaa !15
  switch i32 %19, label %21 [
    i32 0, label %.sink.split
    i32 1, label %20
  ]

20:                                               ; preds = %17
  br label %.sink.split

.sink.split:                                      ; preds = %17, %20
  %.str.13.sink = phi ptr [ @.str.13, %20 ], [ @.str.12, %17 ]
  tail call void @print_string(ptr noundef nonnull %.str.13.sink) #2
  br label %21

21:                                               ; preds = %.sink.split, %17
  tail call void @print_string(ptr noundef nonnull @.str.14) #2
  %22 = getelementptr inbounds i8, ptr %.01215, i64 360
  %23 = load i32, ptr %22, align 8, !tbaa !16
  %24 = sext i32 %23 to i64
  tail call void @print_int(i64 noundef %24) #2
  tail call void (...) @nextLine() #2
  %25 = add nuw nsw i32 %.016, 1
  %26 = load ptr, ptr %.01215, align 8, !tbaa !17
  %27 = icmp ne ptr %26, null
  %28 = load i32, ptr @allProcess, align 4
  %29 = icmp slt i32 %25, %28
  %30 = select i1 %27, i1 %29, i1 false
  br i1 %30, label %.lr.ph, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %21, %0
  ret void
}

declare void @print_string(ptr noundef) local_unnamed_addr #1

declare void @print_int(i64 noundef) local_unnamed_addr #1

declare void @nextLine(...) 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 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 384}
!14 = !{!10, !12, i64 136}
!15 = !{!10, !12, i64 140}
!16 = !{!10, !12, i64 360}
!17 = !{!10, !6, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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