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

; 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 = %123, %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 %124

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 %125

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 %125

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 %74

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 %125

61:                                               ; preds = %54
  %62 = load i8, ptr %11, align 1, !tbaa !14
  %63 = sext i8 %62 to i32
  %64 = and i32 %63, 127
  %65 = trunc i32 %64 to i8
  store i8 %65, ptr %11, align 1, !tbaa !14
  %66 = load i8, ptr %11, align 1, !tbaa !14
  %67 = sext i8 %66 to i32
  %68 = icmp slt i32 %67, 96
  br i1 %68, label %69, label %72

69:                                               ; preds = %61
  %70 = load i32, ptr %6, align 4, !tbaa !5
  %71 = call i64 @write(i32 noundef %70, ptr noundef %11, i64 noundef 1)
  br label %72

72:                                               ; preds = %69, %61
  br label %73

73:                                               ; preds = %72
  br label %74

74:                                               ; preds = %73, %47
  %75 = getelementptr inbounds [2 x %struct.pollfd], ptr %10, i64 0, i64 1
  %76 = getelementptr inbounds %struct.pollfd, ptr %75, i32 0, i32 2
  %77 = load i16, ptr %76, align 2, !tbaa !13
  %78 = sext i16 %77 to i32
  %79 = and i32 %78, 1
  %80 = icmp ne i32 %79, 0
  br i1 %80, label %81, label %123

81:                                               ; preds = %74
  %82 = load i32, ptr %5, align 4, !tbaa !5
  %83 = call i64 @read(i32 noundef %82, ptr noundef %11, i64 noundef 1)
  %84 = trunc i64 %83 to i32
  store i32 %84, ptr %9, align 4, !tbaa !5
  %85 = load i32, ptr %9, align 4, !tbaa !5
  %86 = icmp sle i32 %85, 0
  br i1 %86, label %87, label %88

87:                                               ; preds = %81
  store i32 1, ptr %12, align 4
  br label %125

88:                                               ; preds = %81
  %89 = load i8, ptr %11, align 1, !tbaa !14
  %90 = sext i8 %89 to i32
  %91 = and i32 %90, 127
  %92 = trunc i32 %91 to i8
  store i8 %92, ptr %11, align 1, !tbaa !14
  %93 = load i8, ptr %11, align 1, !tbaa !14
  %94 = sext i8 %93 to i32
  %95 = icmp eq i32 %94, 29
  br i1 %95, label %96, label %97

96:                                               ; preds = %88
  store i32 1, ptr %12, align 4
  br label %125

97:                                               ; preds = %88
  %98 = load i8, ptr %11, align 1, !tbaa !14
  %99 = sext i8 %98 to i32
  %100 = icmp eq i32 %99, 27
  br i1 %100, label %101, label %102

101:                                              ; preds = %97
  store i8 125, ptr %11, align 1, !tbaa !14
  br label %102

102:                                              ; preds = %101, %97
  %103 = load i8, ptr %11, align 1, !tbaa !14
  %104 = sext i8 %103 to i32
  %105 = icmp sge i32 %104, 97
  br i1 %105, label %106, label %115

106:                                              ; preds = %102
  %107 = load i8, ptr %11, align 1, !tbaa !14
  %108 = sext i8 %107 to i32
  %109 = icmp sle i32 %108, 122
  br i1 %109, label %110, label %115

110:                                              ; preds = %106
  %111 = load i8, ptr %11, align 1, !tbaa !14
  %112 = sext i8 %111 to i32
  %113 = and i32 %112, -33
  %114 = trunc i32 %113 to i8
  store i8 %114, ptr %11, align 1, !tbaa !14
  br label %115

115:                                              ; preds = %110, %106, %102
  %116 = load i8, ptr %11, align 1, !tbaa !14
  %117 = sext i8 %116 to i32
  %118 = or i32 %117, 128
  %119 = trunc i32 %118 to i8
  store i8 %119, ptr %11, align 1, !tbaa !14
  %120 = load i32, ptr %8, align 4, !tbaa !5
  %121 = call i64 @write(i32 noundef %120, ptr noundef %11, i64 noundef 1)
  br label %122

122:                                              ; preds = %115
  br label %123

123:                                              ; preds = %122, %74
  br label %23, !llvm.loop !15

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

125:                                              ; preds = %124, %96, %87, %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
  %126 = load i32, ptr %12, align 4
  switch i32 %126, label %128 [
    i32 0, label %127
    i32 1, label %127
  ]

127:                                              ; preds = %125, %125
  ret void

128:                                              ; preds = %125
  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
  %.not17 = icmp eq i32 %2, -1
  br i1 %.not17, 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, %53
  %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
  %.not14 = icmp eq i16 %20, 0
  br i1 %.not14, 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
  %.not15 = icmp eq i16 %25, 0
  br i1 %.not15, label %36, 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 = load i8, ptr %6, align 1, !tbaa !13
  %32 = and i8 %31, 127
  store i8 %32, ptr %6, align 1, !tbaa !13
  %33 = icmp ult i8 %32, 96
  br i1 %33, label %34, label %36

34:                                               ; preds = %30
  %35 = call i64 @write(i32 noundef %1, ptr noundef nonnull %6, i64 noundef 1) #5
  br label %36

36:                                               ; preds = %34, %30, %23
  %37 = load i16, ptr %11, align 2, !tbaa !12
  %38 = and i16 %37, 1
  %.not16 = icmp eq i16 %38, 0
  br i1 %.not16, label %53, label %39

39:                                               ; preds = %36
  %40 = call i64 @read(i32 noundef %0, ptr noundef nonnull %6, i64 noundef 1) #5
  %41 = trunc i64 %40 to i32
  %42 = icmp slt i32 %41, 1
  br i1 %42, label %.loopexit, label %43

43:                                               ; preds = %39
  %44 = load i8, ptr %6, align 1, !tbaa !13
  %45 = and i8 %44, 127
  %46 = icmp eq i8 %45, 29
  br i1 %46, label %.loopexit, label %47

47:                                               ; preds = %43
  %48 = icmp eq i8 %45, 27
  %spec.store.select = select i1 %48, i8 125, i8 %45
  %49 = add nsw i8 %spec.store.select, -97
  %or.cond = icmp ult i8 %49, 26
  %50 = and i8 %spec.store.select, 95
  %spec.select = select i1 %or.cond, i8 %50, i8 %spec.store.select
  %51 = or disjoint i8 %spec.select, -128
  store i8 %51, ptr %6, align 1, !tbaa !13
  %52 = call i64 @write(i32 noundef %3, ptr noundef nonnull %6, i64 noundef 1) #5
  br label %53

53:                                               ; preds = %47, %36
  %54 = load i32, ptr %5, align 16, !tbaa !5
  %.not = icmp eq i32 %54, -1
  br i1 %.not, label %.loopexit, label %12, !llvm.loop !14

.loopexit:                                        ; preds = %16, %26, %39, %43, %53, %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 = !{!8, !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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