; LLVM IR from aap/pdp6 :: tools (mkpty)

; 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.timespec = type { i64, i64 }
%struct.pollfd = type { i32, i16, i16 }

@hupslp = external dso_local global %struct.timespec, align 8
@.str = external hidden unnamed_addr constant [11 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 @readwrite(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca [2 x %struct.pollfd], align 16
  %11 = alloca i8, align 1
  %12 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #3
  %13 = load i32, ptr %7, align 4, !tbaa !5
  %14 = getelementptr inbounds [2 x %struct.pollfd], ptr %10, i64 0, i64 0
  %15 = getelementptr inbounds %struct.pollfd, ptr %14, i32 0, i32 0
  store i32 %13, ptr %15, align 16, !tbaa !9
  %16 = getelementptr inbounds [2 x %struct.pollfd], ptr %10, i64 0, i64 0
  %17 = getelementptr inbounds %struct.pollfd, ptr %16, i32 0, i32 1
  store i16 1, ptr %17, align 4, !tbaa !12
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = getelementptr inbounds [2 x %struct.pollfd], ptr %10, i64 0, i64 1
  %20 = getelementptr inbounds %struct.pollfd, ptr %19, i32 0, i32 0
  store i32 %18, ptr %20, align 8, !tbaa !9
  %21 = getelementptr inbounds [2 x %struct.pollfd], ptr %10, i64 0, i64 1
  %22 = getelementptr inbounds %struct.pollfd, ptr %21, i32 0, i32 1
  store i16 1, ptr %22, align 4, !tbaa !12
  br label %23

23:                                               ; preds = %88, %4
  %24 = getelementptr inbounds [2 x %struct.pollfd], ptr %10, i64 0, i64 0
  %25 = getelementptr inbounds %struct.pollfd, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 16, !tbaa !9
  %27 = icmp ne i32 %26, -1
  br i1 %27, label %28, label %89

28:                                               ; preds = %23
  %29 = getelementptr inbounds [2 x %struct.pollfd], ptr %10, i64 0, i64 0
  %30 = call i32 @poll(ptr noundef %29, i64 noundef 2, i32 noundef -1)
  store i32 %30, ptr %9, align 4, !tbaa !5
  %31 = load i32, ptr %9, align 4, !tbaa !5
  %32 = icmp slt i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %28
  call void @perror(ptr noundef @.str)
  store i32 1, ptr %12, align 4
  br label %90

34:                                               ; preds = %28
  %35 = load i32, ptr %9, align 4, !tbaa !5
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %34
  store i32 1, ptr %12, align 4
  br label %90

38:                                               ; preds = %34
  %39 = getelementptr inbounds [2 x %struct.pollfd], ptr %10, i64 0, i64 0
  %40 = getelementptr inbounds %struct.pollfd, ptr %39, i32 0, i32 2
  %41 = load i16, ptr %40, align 2, !tbaa !13
  %42 = sext i16 %41 to i32
  %43 = and i32 %42, 16
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %47

45:                                               ; preds = %38
  %46 = call i32 @nanosleep(ptr noundef @hupslp, ptr noundef null)
  br label %47

47:                                               ; preds = %45, %38
  %48 = getelementptr inbounds [2 x %struct.pollfd], ptr %10, i64 0, i64 0
  %49 = getelementptr inbounds %struct.pollfd, ptr %48, i32 0, i32 2
  %50 = load i16, ptr %49, align 2, !tbaa !13
  %51 = sext i16 %50 to i32
  %52 = and i32 %51, 1
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %54, label %65

54:                                               ; preds = %47
  %55 = load i32, ptr %7, align 4, !tbaa !5
  %56 = call i64 @read(i32 noundef %55, ptr noundef %11, i64 noundef 1)
  %57 = trunc i64 %56 to i32
  store i32 %57, ptr %9, align 4, !tbaa !5
  %58 = load i32, ptr %9, align 4, !tbaa !5
  %59 = icmp sle i32 %58, 0
  br i1 %59, label %60, label %61

60:                                               ; preds = %54
  store i32 1, ptr %12, align 4
  br label %90

61:                                               ; preds = %54
  %62 = load i32, ptr %6, align 4, !tbaa !5
  %63 = call i64 @write(i32 noundef %62, ptr noundef %11, i64 noundef 1)
  br label %64

64:                                               ; preds = %61
  br label %65

65:                                               ; preds = %64, %47
  %66 = getelementptr inbounds [2 x %struct.pollfd], ptr %10, i64 0, i64 1
  %67 = getelementptr inbounds %struct.pollfd, ptr %66, i32 0, i32 2
  %68 = load i16, ptr %67, align 2, !tbaa !13
  %69 = sext i16 %68 to i32
  %70 = and i32 %69, 1
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %72, label %88

72:                                               ; preds = %65
  %73 = load i32, ptr %5, align 4, !tbaa !5
  %74 = call i64 @read(i32 noundef %73, ptr noundef %11, i64 noundef 1)
  %75 = trunc i64 %74 to i32
  store i32 %75, ptr %9, align 4, !tbaa !5
  %76 = load i32, ptr %9, align 4, !tbaa !5
  %77 = icmp sle i32 %76, 0
  br i1 %77, label %78, label %79

78:                                               ; preds = %72
  store i32 1, ptr %12, align 4
  br label %90

79:                                               ; preds = %72
  %80 = load i8, ptr %11, align 1, !tbaa !14
  %81 = sext i8 %80 to i32
  %82 = icmp eq i32 %81, 29
  br i1 %82, label %83, label %84

83:                                               ; preds = %79
  store i32 1, ptr %12, align 4
  br label %90

84:                                               ; preds = %79
  %85 = load i32, ptr %8, align 4, !tbaa !5
  %86 = call i64 @write(i32 noundef %85, ptr noundef %11, i64 noundef 1)
  br label %87

87:                                               ; preds = %84
  br label %88

88:                                               ; preds = %87, %65
  br label %23, !llvm.loop !15

89:                                               ; preds = %23
  store i32 0, ptr %12, align 4
  br label %90

90:                                               ; preds = %89, %83, %78, %60, %37, %33
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  %91 = load i32, ptr %12, align 4
  switch i32 %91, label %93 [
    i32 0, label %92
    i32 1, label %92
  ]

92:                                               ; preds = %90, %90
  ret void

93:                                               ; preds = %90
  unreachable
}

declare i32 @poll(ptr noundef, i64 noundef, i32 noundef) #2

declare void @perror(ptr noundef) #2

declare i32 @nanosleep(ptr noundef, ptr noundef) #2

declare i64 @read(i32 noundef, ptr noundef, i64 noundef) #2

declare i64 @write(i32 noundef, ptr noundef, i64 noundef) #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"pollfd", !6, i64 0, !11, i64 4, !11, i64 6}
!11 = !{!"short", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!10, !11, i64 6}
!14 = !{!7, !7, 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"

%struct.timespec = type { i64, i64 }
%struct.pollfd = type { i32, i16, i16 }

@hupslp = external dso_local global %struct.timespec, align 8
@.str = external hidden unnamed_addr constant [11 x i8], align 1

; 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

; Function Attrs: nounwind uwtable
define dso_local void @readwrite(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = alloca [2 x %struct.pollfd], align 16
  %6 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #5
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %6) #5
  store i32 %2, ptr %5, align 16, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %5, i64 4
  store i16 1, ptr %7, align 4, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %5, i64 8
  store i32 %0, ptr %8, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %5, i64 12
  store i16 1, ptr %9, align 4, !tbaa !11
  %.not14 = icmp eq i32 %2, -1
  br i1 %.not14, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %10 = getelementptr inbounds i8, ptr %5, i64 6
  %11 = getelementptr inbounds i8, ptr %5, i64 14
  br label %12

12:                                               ; preds = %.lr.ph, %43
  %13 = call i32 @poll(ptr noundef nonnull %5, i64 noundef 2, i32 noundef -1) #5
  %14 = icmp slt i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %12
  call void @perror(ptr noundef nonnull @.str) #6
  br label %.loopexit

16:                                               ; preds = %12
  %17 = icmp eq i32 %13, 0
  br i1 %17, label %.loopexit, label %18

18:                                               ; preds = %16
  %19 = load i16, ptr %10, align 2, !tbaa !12
  %20 = and i16 %19, 16
  %.not10 = icmp eq i16 %20, 0
  br i1 %.not10, label %23, label %21

21:                                               ; preds = %18
  %22 = call i32 @nanosleep(ptr noundef nonnull @hupslp, ptr noundef null) #5
  %.pre = load i16, ptr %10, align 2, !tbaa !12
  br label %23

23:                                               ; preds = %21, %18
  %24 = phi i16 [ %.pre, %21 ], [ %19, %18 ]
  %25 = and i16 %24, 1
  %.not11 = icmp eq i16 %25, 0
  br i1 %.not11, label %32, label %26

26:                                               ; preds = %23
  %27 = call i64 @read(i32 noundef %2, ptr noundef nonnull %6, i64 noundef 1) #5
  %28 = trunc i64 %27 to i32
  %29 = icmp slt i32 %28, 1
  br i1 %29, label %.loopexit, label %30

30:                                               ; preds = %26
  %31 = call i64 @write(i32 noundef %1, ptr noundef nonnull %6, i64 noundef 1) #5
  br label %32

32:                                               ; preds = %30, %23
  %33 = load i16, ptr %11, align 2, !tbaa !12
  %34 = and i16 %33, 1
  %.not12 = icmp eq i16 %34, 0
  br i1 %.not12, label %43, label %35

35:                                               ; preds = %32
  %36 = call i64 @read(i32 noundef %0, ptr noundef nonnull %6, i64 noundef 1) #5
  %37 = trunc i64 %36 to i32
  %38 = icmp slt i32 %37, 1
  %39 = load i8, ptr %6, align 1
  %40 = icmp eq i8 %39, 29
  %or.cond = select i1 %38, i1 true, i1 %40
  br i1 %or.cond, label %.loopexit, label %41

41:                                               ; preds = %35
  %42 = call i64 @write(i32 noundef %3, ptr noundef nonnull %6, i64 noundef 1) #5
  br label %43

43:                                               ; preds = %41, %32
  %44 = load i32, ptr %5, align 16, !tbaa !5
  %.not = icmp eq i32 %44, -1
  br i1 %.not, label %.loopexit, label %12, !llvm.loop !13

.loopexit:                                        ; preds = %16, %26, %35, %43, %4, %15
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #5
  ret void
}

declare i32 @poll(ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare void @perror(ptr nocapture noundef readonly) local_unnamed_addr #3

declare i32 @nanosleep(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree
declare noundef i64 @read(i32 noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #4

; Function Attrs: nofree
declare noundef i64 @write(i32 noundef, ptr nocapture noundef readonly, i64 noundef) local_unnamed_addr #4

attributes #0 = { mustprogress 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 = { nofree 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 #4 = { nofree "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 #5 = { nounwind }
attributes #6 = { cold }

!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 0}
!6 = !{!"pollfd", !7, i64 0, !10, i64 4, !10, i64 6}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!6, !10, i64 4}
!12 = !{!6, !10, i64 6}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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