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

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

@.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 = %118, %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 %119

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

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

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

45:                                               ; preds = %38
  store i32 1, ptr %12, align 4
  br label %120

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

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

59:                                               ; preds = %53
  store i32 1, ptr %12, align 4
  br label %120

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

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

71:                                               ; preds = %68, %60
  br label %72

72:                                               ; preds = %71
  br label %73

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

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

86:                                               ; preds = %80
  store i32 1, ptr %12, align 4
  br label %120

87:                                               ; preds = %80
  %88 = load i8, ptr %11, align 1, !tbaa !14
  %89 = sext i8 %88 to i32
  %90 = icmp eq i32 %89, 29
  br i1 %90, label %91, label %92

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

92:                                               ; preds = %87
  %93 = load i8, ptr %11, align 1, !tbaa !14
  %94 = sext i8 %93 to i32
  %95 = icmp eq i32 %94, 27
  br i1 %95, label %96, label %97

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

97:                                               ; preds = %96, %92
  %98 = load i8, ptr %11, align 1, !tbaa !14
  %99 = sext i8 %98 to i32
  %100 = icmp sge i32 %99, 97
  br i1 %100, label %101, label %110

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

105:                                              ; preds = %101
  %106 = load i8, ptr %11, align 1, !tbaa !14
  %107 = sext i8 %106 to i32
  %108 = and i32 %107, -33
  %109 = trunc i32 %108 to i8
  store i8 %109, ptr %11, align 1, !tbaa !14
  br label %110

110:                                              ; preds = %105, %101, %97
  %111 = load i8, ptr %11, align 1, !tbaa !14
  %112 = sext i8 %111 to i32
  %113 = or i32 %112, 128
  %114 = trunc i32 %113 to i8
  store i8 %114, ptr %11, align 1, !tbaa !14
  %115 = load i32, ptr %8, align 4, !tbaa !5
  %116 = call i64 @write(i32 noundef %115, ptr noundef %11, i64 noundef 1)
  br label %117

117:                                              ; preds = %110
  br label %118

118:                                              ; preds = %117, %73
  br label %23, !llvm.loop !15

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

120:                                              ; preds = %119, %91, %86, %59, %45, %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
  %121 = load i32, ptr %12, align 4
  switch i32 %121, label %123 [
    i32 0, label %122
    i32 1, label %122
  ]

122:                                              ; preds = %120, %120
  ret void

123:                                              ; preds = %120
  unreachable
}

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

declare void @perror(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.pollfd = type { i32, i16, i16 }

@.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, %50
  %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 = zext i16 %19 to i32
  %21 = and i32 %20, 16
  %.not14 = icmp eq i32 %21, 0
  br i1 %.not14, label %22, label %.loopexit

22:                                               ; preds = %18
  %23 = and i32 %20, 1
  %.not15 = icmp eq i32 %23, 0
  br i1 %.not15, label %34, label %24

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

28:                                               ; preds = %24
  %29 = load i8, ptr %6, align 1, !tbaa !13
  %30 = and i8 %29, 127
  store i8 %30, ptr %6, align 1, !tbaa !13
  %31 = icmp ult i8 %30, 96
  br i1 %31, label %32, label %34

32:                                               ; preds = %28
  %33 = call i64 @write(i32 noundef %1, ptr noundef nonnull %6, i64 noundef 1) #5
  br label %34

34:                                               ; preds = %32, %28, %22
  %35 = load i16, ptr %11, align 2, !tbaa !12
  %36 = and i16 %35, 1
  %.not16 = icmp eq i16 %36, 0
  br i1 %.not16, label %50, label %37

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

41:                                               ; preds = %37
  %42 = load i8, ptr %6, align 1, !tbaa !13
  %43 = icmp eq i8 %42, 29
  br i1 %43, label %.loopexit, label %44

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

50:                                               ; preds = %44, %34
  %51 = load i32, ptr %5, align 16, !tbaa !5
  %.not = icmp eq i32 %51, -1
  br i1 %.not, label %.loopexit, label %12, !llvm.loop !14

.loopexit:                                        ; preds = %16, %18, %24, %37, %41, %50, %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

; 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: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass