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

; 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

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

declare i32 @wait(i32 noundef) #1

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #2

declare i32 @signal(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @read(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #3 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca [40 x i8], align 16
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 40, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %13 = load i32, ptr %8, align 4, !tbaa !9
  %14 = icmp sgt i32 %13, 40
  br i1 %14, label %15, label %16

15:                                               ; preds = %4
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %144

16:                                               ; preds = %4
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.s_pipe, ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = load i32, ptr %9, align 4, !tbaa !9
  %21 = icmp eq i32 %19, %20
  br i1 %21, label %22, label %79

22:                                               ; preds = %16
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.s_pipe, ptr %23, i32 0, i32 4
  %25 = load i8, ptr %24, align 1, !tbaa !13
  %26 = zext i8 %25 to i32
  %27 = icmp eq i32 %26, 1
  br i1 %27, label %28, label %79

28:                                               ; preds = %22
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.s_pipe, ptr %29, i32 0, i32 9
  %31 = load i32, ptr %30, align 4, !tbaa !14
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %33, label %35

33:                                               ; preds = %28
  %34 = load i32, ptr %9, align 4, !tbaa !9
  call void @blockProcess(i32 noundef %34)
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %144

35:                                               ; preds = %28
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.s_pipe, ptr %36, i32 0, i32 10
  %38 = load i32, ptr %37, align 4, !tbaa !15
  %39 = call i32 @wait(i32 noundef %38)
  store i32 %39, ptr %11, align 4, !tbaa !9
  %40 = load i32, ptr %11, align 4, !tbaa !9
  %41 = icmp eq i32 %40, -1
  br i1 %41, label %42, label %43

42:                                               ; preds = %35
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %144

43:                                               ; preds = %35
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.s_pipe, ptr %45, i32 0, i32 8
  %47 = getelementptr inbounds [40 x i8], ptr %46, i64 0, i64 0
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = call ptr @strncpy(ptr noundef %44, ptr noundef %47, i32 noundef %48)
  %50 = getelementptr inbounds [40 x i8], ptr %10, i64 0, i64 0
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.s_pipe, ptr %51, i32 0, i32 8
  %53 = getelementptr inbounds [40 x i8], ptr %52, i64 0, i64 0
  %54 = load i32, ptr %8, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds i8, ptr %53, i64 %55
  %57 = call ptr @strcpy(ptr noundef %50, ptr noundef %56) #4
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.s_pipe, ptr %58, i32 0, i32 8
  %60 = getelementptr inbounds [40 x i8], ptr %59, i64 0, i64 0
  %61 = call ptr @memset(ptr noundef %60, i32 noundef 0, i64 noundef 40)
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.s_pipe, ptr %62, i32 0, i32 8
  %64 = getelementptr inbounds [40 x i8], ptr %63, i64 0, i64 0
  %65 = getelementptr inbounds [40 x i8], ptr %10, i64 0, i64 0
  %66 = call ptr @strcpy(ptr noundef %64, ptr noundef %65) #4
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.s_pipe, ptr %67, i32 0, i32 9
  %69 = load i32, ptr %68, align 4, !tbaa !14
  %70 = load i32, ptr %8, align 4, !tbaa !9
  %71 = sub nsw i32 %69, %70
  %72 = add nsw i32 %71, 1
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.s_pipe, ptr %73, i32 0, i32 9
  store i32 %72, ptr %74, align 4, !tbaa !14
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.s_pipe, ptr %75, i32 0, i32 10
  %77 = load i32, ptr %76, align 4, !tbaa !15
  %78 = call i32 @signal(i32 noundef %77)
  br label %142

79:                                               ; preds = %22, %16
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.s_pipe, ptr %80, i32 0, i32 2
  %82 = load i32, ptr %81, align 4, !tbaa !16
  %83 = load i32, ptr %9, align 4, !tbaa !9
  %84 = icmp eq i32 %82, %83
  br i1 %84, label %85, label %141

85:                                               ; preds = %79
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.s_pipe, ptr %86, i32 0, i32 6
  %88 = load i8, ptr %87, align 1, !tbaa !17
  %89 = zext i8 %88 to i32
  %90 = icmp eq i32 %89, 1
  br i1 %90, label %91, label %141

91:                                               ; preds = %85
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.s_pipe, ptr %92, i32 0, i32 9
  %94 = load i32, ptr %93, align 4, !tbaa !14
  %95 = icmp eq i32 %94, 0
  br i1 %95, label %96, label %98

96:                                               ; preds = %91
  %97 = load i32, ptr %9, align 4, !tbaa !9
  call void @blockProcess(i32 noundef %97)
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %144

98:                                               ; preds = %91
  %99 = load ptr, ptr %6, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.s_pipe, ptr %99, i32 0, i32 10
  %101 = load i32, ptr %100, align 4, !tbaa !15
  %102 = call i32 @wait(i32 noundef %101)
  store i32 %102, ptr %11, align 4, !tbaa !9
  %103 = load i32, ptr %11, align 4, !tbaa !9
  %104 = icmp eq i32 %103, -1
  br i1 %104, label %105, label %106

105:                                              ; preds = %98
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %144

106:                                              ; preds = %98
  %107 = load ptr, ptr %7, align 8, !tbaa !5
  %108 = load ptr, ptr %6, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.s_pipe, ptr %108, i32 0, i32 8
  %110 = getelementptr inbounds [40 x i8], ptr %109, i64 0, i64 0
  %111 = load i32, ptr %8, align 4, !tbaa !9
  %112 = call ptr @strncpy(ptr noundef %107, ptr noundef %110, i32 noundef %111)
  %113 = getelementptr inbounds [40 x i8], ptr %10, i64 0, i64 0
  %114 = load ptr, ptr %6, align 8, !tbaa !5
  %115 = getelementptr inbounds %struct.s_pipe, ptr %114, i32 0, i32 8
  %116 = getelementptr inbounds [40 x i8], ptr %115, i64 0, i64 0
  %117 = load i32, ptr %8, align 4, !tbaa !9
  %118 = sext i32 %117 to i64
  %119 = getelementptr inbounds i8, ptr %116, i64 %118
  %120 = call ptr @strcpy(ptr noundef %113, ptr noundef %119) #4
  %121 = load ptr, ptr %6, align 8, !tbaa !5
  %122 = getelementptr inbounds %struct.s_pipe, ptr %121, i32 0, i32 8
  %123 = getelementptr inbounds [40 x i8], ptr %122, i64 0, i64 0
  %124 = call ptr @memset(ptr noundef %123, i32 noundef 0, i64 noundef 40)
  %125 = load ptr, ptr %6, align 8, !tbaa !5
  %126 = getelementptr inbounds %struct.s_pipe, ptr %125, i32 0, i32 8
  %127 = getelementptr inbounds [40 x i8], ptr %126, i64 0, i64 0
  %128 = getelementptr inbounds [40 x i8], ptr %10, i64 0, i64 0
  %129 = call ptr @strcpy(ptr noundef %127, ptr noundef %128) #4
  %130 = load ptr, ptr %6, align 8, !tbaa !5
  %131 = getelementptr inbounds %struct.s_pipe, ptr %130, i32 0, i32 9
  %132 = load i32, ptr %131, align 4, !tbaa !14
  %133 = load i32, ptr %8, align 4, !tbaa !9
  %134 = sub nsw i32 %132, %133
  %135 = load ptr, ptr %6, align 8, !tbaa !5
  %136 = getelementptr inbounds %struct.s_pipe, ptr %135, i32 0, i32 9
  store i32 %134, ptr %136, align 4, !tbaa !14
  %137 = load ptr, ptr %6, align 8, !tbaa !5
  %138 = getelementptr inbounds %struct.s_pipe, ptr %137, i32 0, i32 10
  %139 = load i32, ptr %138, align 4, !tbaa !15
  %140 = call i32 @signal(i32 noundef %139)
  br label %141

141:                                              ; preds = %106, %85, %79
  br label %142

142:                                              ; preds = %141, %43
  %143 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %143, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %144

144:                                              ; preds = %142, %105, %96, %42, %33, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr %10) #4
  %145 = load i32, ptr %5, align 4
  ret i32 %145
}

declare void @blockProcess(i32 noundef) #1

declare ptr @strncpy(ptr noundef, ptr noundef, i32 noundef) #1

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


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

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

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

declare i32 @wait(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #2

declare i32 @signal(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -2147483648, 41) i32 @read(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #3 {
  %5 = alloca [40 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %5) #5
  %6 = icmp sgt i32 %2, 40
  br i1 %6, label %65, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = icmp eq i32 %9, %3
  br i1 %10, label %11, label %36

11:                                               ; preds = %7
  %12 = getelementptr inbounds i8, ptr %0, i64 13
  %13 = load i8, ptr %12, align 1, !tbaa !10
  %14 = icmp eq i8 %13, 1
  br i1 %14, label %15, label %36

15:                                               ; preds = %11
  %16 = getelementptr inbounds i8, ptr %0, i64 60
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %15
  tail call void @blockProcess(i32 noundef %3) #5
  br label %65

20:                                               ; preds = %15
  %21 = getelementptr inbounds i8, ptr %0, i64 64
  %22 = load i32, ptr %21, align 4, !tbaa !12
  %23 = tail call i32 @wait(i32 noundef %22) #5
  %24 = icmp eq i32 %23, -1
  br i1 %24, label %65, label %25

25:                                               ; preds = %20
  %26 = getelementptr inbounds i8, ptr %0, i64 17
  %27 = tail call ptr @strncpy(ptr noundef %1, ptr noundef nonnull %26, i32 noundef %2) #5
  %28 = sext i32 %2 to i64
  %29 = getelementptr inbounds i8, ptr %26, i64 %28
  %30 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %5, ptr noundef nonnull dereferenceable(1) %29) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(40) %26, i8 noundef 0, i64 noundef 40, i1 false)
  %31 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %26, ptr noundef nonnull dereferenceable(1) %5) #5
  %32 = load i32, ptr %16, align 4, !tbaa !11
  %reass.sub = sub i32 %32, %2
  %33 = add i32 %reass.sub, 1
  store i32 %33, ptr %16, align 4, !tbaa !11
  %34 = load i32, ptr %21, align 4, !tbaa !12
  %35 = call i32 @signal(i32 noundef %34) #5
  br label %65

36:                                               ; preds = %11, %7
  %37 = getelementptr inbounds i8, ptr %0, i64 8
  %38 = load i32, ptr %37, align 4, !tbaa !13
  %39 = icmp eq i32 %38, %3
  br i1 %39, label %40, label %65

40:                                               ; preds = %36
  %41 = getelementptr inbounds i8, ptr %0, i64 15
  %42 = load i8, ptr %41, align 1, !tbaa !14
  %43 = icmp eq i8 %42, 1
  br i1 %43, label %44, label %65

44:                                               ; preds = %40
  %45 = getelementptr inbounds i8, ptr %0, i64 60
  %46 = load i32, ptr %45, align 4, !tbaa !11
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %48, label %49

48:                                               ; preds = %44
  tail call void @blockProcess(i32 noundef %3) #5
  br label %65

49:                                               ; preds = %44
  %50 = getelementptr inbounds i8, ptr %0, i64 64
  %51 = load i32, ptr %50, align 4, !tbaa !12
  %52 = tail call i32 @wait(i32 noundef %51) #5
  %53 = icmp eq i32 %52, -1
  br i1 %53, label %65, label %54

54:                                               ; preds = %49
  %55 = getelementptr inbounds i8, ptr %0, i64 17
  %56 = tail call ptr @strncpy(ptr noundef %1, ptr noundef nonnull %55, i32 noundef %2) #5
  %57 = sext i32 %2 to i64
  %58 = getelementptr inbounds i8, ptr %55, i64 %57
  %59 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %5, ptr noundef nonnull dereferenceable(1) %58) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(40) %55, i8 noundef 0, i64 noundef 40, i1 false)
  %60 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %55, ptr noundef nonnull dereferenceable(1) %5) #5
  %61 = load i32, ptr %45, align 4, !tbaa !11
  %62 = sub nsw i32 %61, %2
  store i32 %62, ptr %45, align 4, !tbaa !11
  %63 = load i32, ptr %50, align 4, !tbaa !12
  %64 = call i32 @signal(i32 noundef %63) #5
  br label %65

65:                                               ; preds = %25, %54, %40, %36, %49, %20, %4, %48, %19
  %.0 = phi i32 [ -1, %19 ], [ -1, %48 ], [ 0, %4 ], [ -1, %20 ], [ -1, %49 ], [ %2, %36 ], [ %2, %40 ], [ %2, %54 ], [ %2, %25 ]
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %5) #5
  ret i32 %.0
}

declare void @blockProcess(i32 noundef) local_unnamed_addr #1

declare ptr @strncpy(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

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

attributes #0 = { mustprogress 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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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, !7, i64 4}
!6 = !{!"s_pipe", !7, i64 0, !7, i64 4, !7, i64 8, !8, i64 12, !8, i64 13, !8, i64 14, !8, i64 15, !8, i64 16, !8, i64 17, !7, i64 60, !7, i64 64}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !8, i64 13}
!11 = !{!6, !7, i64 60}
!12 = !{!6, !7, i64 64}
!13 = !{!6, !7, i64 8}
!14 = !{!6, !8, i64 15}


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