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

; 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 }
%struct.s_pipe = type { i32, i32, i32, i8, i8, i8, i8, i8, [40 x i8], i32, i32 }

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

declare i32 @getCurrentPid(...) #1

declare ptr @getProcessFromPid(i32 noundef) #1

; 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 i64 @sys_getPipeBuffer(i64 noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4) #2 {
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  store i64 %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !5
  store i64 %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %13 = call i32 (...) @getCurrentPid()
  %14 = call ptr @getProcessFromPid(i32 noundef %13)
  store ptr %14, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  store ptr null, ptr %12, align 8, !tbaa !9
  %15 = load i64, ptr %7, align 8, !tbaa !5
  %16 = icmp ne i64 %15, 0
  br i1 %16, label %17, label %24

17:                                               ; preds = %5
  %18 = load ptr, ptr %11, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.ProcessSlot, ptr %18, i32 0, i32 1
  %20 = getelementptr inbounds %struct.Process, ptr %19, i32 0, i32 13
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  %22 = getelementptr inbounds %struct.s_pipe, ptr %21, i32 0, i32 8
  %23 = getelementptr inbounds [40 x i8], ptr %22, i64 0, i64 0
  store ptr %23, ptr %12, align 8, !tbaa !9
  br label %35

24:                                               ; preds = %5
  %25 = load i64, ptr %8, align 8, !tbaa !5
  %26 = icmp ne i64 %25, 0
  br i1 %26, label %27, label %34

27:                                               ; preds = %24
  %28 = load ptr, ptr %11, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.ProcessSlot, ptr %28, i32 0, i32 1
  %30 = getelementptr inbounds %struct.Process, ptr %29, i32 0, i32 14
  %31 = load ptr, ptr %30, align 8, !tbaa !15
  %32 = getelementptr inbounds %struct.s_pipe, ptr %31, i32 0, i32 8
  %33 = getelementptr inbounds [40 x i8], ptr %32, i64 0, i64 0
  store ptr %33, ptr %12, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %27, %24
  br label %35

35:                                               ; preds = %34, %17
  %36 = load ptr, ptr %12, align 8, !tbaa !9
  %37 = ptrtoint ptr %36 to i64
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret i64 %37
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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, !6, i64 0}
!6 = !{!"long", !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, !10, i64 480}
!12 = !{!"ProcessSlot", !10, i64 0, !13, i64 8}
!13 = !{!"Process", !14, i64 0, !14, i64 4, !7, i64 8, !14, i64 128, !14, i64 132, !7, i64 136, !7, i64 192, !14, i64 352, !10, i64 360, !10, i64 368, !10, i64 376, !7, i64 384, !14, i64 464, !10, i64 472, !10, i64 480}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !10, i64 488}


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

declare i32 @getCurrentPid(...) local_unnamed_addr #0

declare ptr @getProcessFromPid(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i64 @sys_getPipeBuffer(i64 noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4) local_unnamed_addr #1 {
  %6 = tail call i32 (...) @getCurrentPid() #2
  %7 = tail call ptr @getProcessFromPid(i32 noundef %6) #2
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %8, label %.sink.split

8:                                                ; preds = %5
  %.not4 = icmp eq i64 %2, 0
  br i1 %.not4, label %13, label %.sink.split

.sink.split:                                      ; preds = %8, %5
  %.sink = phi i64 [ 480, %5 ], [ 488, %8 ]
  %9 = getelementptr inbounds i8, ptr %7, i64 %.sink
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i64 17
  %12 = ptrtoint ptr %11 to i64
  br label %13

13:                                               ; preds = %.sink.split, %8
  %.0 = phi i64 [ 0, %8 ], [ %12, %.sink.split ]
  ret i64 %.0
}

attributes #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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass