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

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

@pipePIDs = external dso_local global i32, align 4

declare ptr @getProcessFromPid(i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @createPipeStruct(ptr dead_on_unwind noalias writable sret(%struct.s_pipe) align 4 %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %1, ptr %4, align 4, !tbaa !5
  store i32 %2, ptr %5, align 4, !tbaa !5
  %6 = load i32, ptr @pipePIDs, align 4, !tbaa !5
  %7 = add nsw i32 %6, 1
  store i32 %7, ptr @pipePIDs, align 4, !tbaa !5
  %8 = getelementptr inbounds %struct.s_pipe, ptr %0, i32 0, i32 0
  store i32 %6, ptr %8, align 4, !tbaa !9
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = getelementptr inbounds %struct.s_pipe, ptr %0, i32 0, i32 1
  store i32 %9, ptr %10, align 4, !tbaa !11
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = getelementptr inbounds %struct.s_pipe, ptr %0, i32 0, i32 2
  store i32 %11, ptr %12, align 4, !tbaa !12
  %13 = getelementptr inbounds %struct.s_pipe, ptr %0, i32 0, i32 3
  store i8 0, ptr %13, align 4, !tbaa !13
  %14 = getelementptr inbounds %struct.s_pipe, ptr %0, i32 0, i32 4
  store i8 1, ptr %14, align 1, !tbaa !14
  %15 = getelementptr inbounds %struct.s_pipe, ptr %0, i32 0, i32 5
  store i8 1, ptr %15, align 2, !tbaa !15
  %16 = getelementptr inbounds %struct.s_pipe, ptr %0, i32 0, i32 6
  store i8 1, ptr %16, align 1, !tbaa !16
  %17 = getelementptr inbounds %struct.s_pipe, ptr %0, i32 0, i32 7
  store i8 1, ptr %17, align 4, !tbaa !17
  %18 = getelementptr inbounds %struct.s_pipe, ptr %0, i32 0, i32 9
  store i32 0, ptr %18, align 4, !tbaa !18
  %19 = getelementptr inbounds %struct.s_pipe, ptr %0, i32 0, i32 8
  %20 = getelementptr inbounds [40 x i8], ptr %19, i64 0, i64 0
  %21 = call ptr @memset(ptr noundef %20, i32 noundef 0, i64 noundef 40)
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = call ptr @getProcessFromPid(i32 noundef %22)
  %24 = getelementptr inbounds %struct.ProcessSlot, ptr %23, i32 0, i32 1
  %25 = getelementptr inbounds %struct.Process, ptr %24, i32 0, i32 5
  %26 = getelementptr inbounds [50 x i8], ptr %25, i64 0, i64 0
  %27 = call i32 @getFreeMutex(ptr noundef %26)
  %28 = getelementptr inbounds %struct.s_pipe, ptr %0, i32 0, i32 10
  store i32 %27, ptr %28, align 4, !tbaa !19
  ret void
}

declare ptr @memset(ptr noundef, i32 noundef, i64 noundef) #0

declare i32 @getFreeMutex(ptr noundef) #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" }

!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, !6, i64 0}
!10 = !{!"s_pipe", !6, i64 0, !6, i64 4, !6, i64 8, !7, i64 12, !7, i64 13, !7, i64 14, !7, i64 15, !7, i64 16, !7, i64 17, !6, i64 60, !6, i64 64}
!11 = !{!10, !6, i64 4}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !7, i64 12}
!14 = !{!10, !7, i64 13}
!15 = !{!10, !7, i64 14}
!16 = !{!10, !7, i64 15}
!17 = !{!10, !7, i64 16}
!18 = !{!10, !6, i64 60}
!19 = !{!10, !6, i64 64}


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

@pipePIDs = external dso_local local_unnamed_addr global i32, align 4

declare ptr @getProcessFromPid(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @createPipeStruct(ptr dead_on_unwind noalias nocapture writable writeonly sret(%struct.s_pipe) align 4 %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = load i32, ptr @pipePIDs, align 4, !tbaa !5
  %5 = add nsw i32 %4, 1
  store i32 %5, ptr @pipePIDs, align 4, !tbaa !5
  store i32 %4, ptr %0, align 4, !tbaa !9
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %1, ptr %6, align 4, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %2, ptr %7, align 4, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %0, i64 12
  store i8 0, ptr %8, align 4, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %0, i64 13
  %10 = getelementptr inbounds i8, ptr %0, i64 60
  store i32 16843009, ptr %9, align 1
  store i32 0, ptr %10, align 4, !tbaa !14
  %11 = getelementptr inbounds i8, ptr %0, i64 17
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(40) %11, i8 noundef 0, i64 noundef 40, i1 false)
  %12 = tail call ptr @getProcessFromPid(i32 noundef %2) #3
  %13 = getelementptr inbounds i8, ptr %12, i64 144
  %14 = tail call i32 @getFreeMutex(ptr noundef nonnull %13) #3
  %15 = getelementptr inbounds i8, ptr %0, i64 64
  store i32 %14, ptr %15, align 4, !tbaa !15
  ret void
}

declare i32 @getFreeMutex(ptr noundef) local_unnamed_addr #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !6, i64 0}
!10 = !{!"s_pipe", !6, i64 0, !6, i64 4, !6, i64 8, !7, i64 12, !7, i64 13, !7, i64 14, !7, i64 15, !7, i64 16, !7, i64 17, !6, i64 60, !6, i64 64}
!11 = !{!10, !6, i64 4}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !7, i64 12}
!14 = !{!10, !6, i64 60}
!15 = !{!10, !6, i64 64}


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