; LLVM IR from s-matyukevich/raspberry-pi-os :: exercises/lesson01/2/gcrisis/uart-boot/downloader (raspiloader)

; 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.fd_set = type { [16 x i64] }
%struct.termios = type { i32, i32, i32, i32, i8, [32 x i8], i32, i32 }

@.str.11 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [18 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @do_exit(i32 noundef, i32 noundef) #0

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @open_serial(ptr noundef) #0

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

declare i32 @printf(ptr noundef, ...) #3

; Function Attrs: nounwind
declare i32 @tcgetattr(i32 noundef, ptr noundef) #4

declare void @perror(ptr noundef) #3

; Function Attrs: nounwind
declare i32 @tcsetattr(i32 noundef, i32 noundef, ptr noundef) #4

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

; Function Attrs: nounwind uwtable
declare dso_local void @send_kernel(i32 noundef, ptr noundef) #0

declare i64 @write(i32 noundef, ptr noundef, i64 noundef) #3

declare i32 @tcdrain(i32 noundef) #3

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca [65536 x i8], align 16
  %8 = alloca %struct.fd_set, align 8
  %9 = alloca %struct.fd_set, align 8
  %10 = alloca %struct.fd_set, align 8
  %11 = alloca ptr, align 8
  %12 = alloca [65536 x i8], align 16
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca %struct.termios, align 4
  %17 = alloca %struct.termios, align 4
  %18 = alloca i32, align 4
  %19 = alloca ptr, align 8
  %20 = alloca i32, align 4
  %21 = alloca i64, align 8
  %22 = alloca i64, align 8
  %23 = alloca [65536 x i8], align 16
  %24 = alloca i64, align 8
  %25 = alloca i64, align 8
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #8
  call void @llvm.lifetime.start.p0(i64 65536, ptr %7) #8
  call void @llvm.lifetime.start.p0(i64 128, ptr %8) #8
  call void @llvm.lifetime.start.p0(i64 128, ptr %9) #8
  call void @llvm.lifetime.start.p0(i64 128, ptr %10) #8
  %26 = call i32 (ptr, ...) @printf(ptr noundef @.str.11)
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = icmp ne i32 %27, 3
  br i1 %28, label %29, label %38

29:                                               ; preds = %2
  %30 = load ptr, ptr %5, align 8, !tbaa !9
  %31 = getelementptr inbounds ptr, ptr %30, i64 0
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  %33 = call i32 (ptr, ...) @printf(ptr noundef @.str.12, ptr noundef %32)
  %34 = load ptr, ptr %5, align 8, !tbaa !9
  %35 = getelementptr inbounds ptr, ptr %34, i64 0
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %37 = call i32 (ptr, ...) @printf(ptr noundef @.str.13, ptr noundef %36)
  call void @exit(i32 noundef 1) #9
  unreachable

38:                                               ; preds = %2
  %39 = load ptr, ptr %5, align 8, !tbaa !9
  %40 = getelementptr inbounds ptr, ptr %39, i64 1
  %41 = load ptr, ptr %40, align 8, !tbaa !9
  %42 = call i32 @open_serial(ptr noundef %41)
  store i32 %42, ptr %6, align 4, !tbaa !5
  %43 = load i32, ptr %6, align 4, !tbaa !5
  %44 = icmp eq i32 %43, -1
  br i1 %44, label %45, label %50

45:                                               ; preds = %38
  %46 = load ptr, ptr %5, align 8, !tbaa !9
  %47 = getelementptr inbounds ptr, ptr %46, i64 1
  %48 = load ptr, ptr %47, align 8, !tbaa !9
  call void @perror(ptr noundef %48)
  %49 = load i32, ptr %6, align 4, !tbaa !5
  call void @do_exit(i32 noundef %49, i32 noundef 1)
  br label %50

50:                                               ; preds = %45, %38
  %51 = call i32 (ptr, ...) @printf(ptr noundef @.str.14)
  br label %52

52:                                               ; preds = %50
  br label %53

53:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #8
  store ptr @.str.15, ptr %11, align 8, !tbaa !9
  br label %54

54:                                               ; preds = %90, %53
  br label %55

55:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 65536, ptr %12) #8
  call void @llvm.memset.p0.i64(ptr align 16 %12, i8 0, i64 65536, i1 false)
  %56 = load i32, ptr %6, align 4, !tbaa !5
  %57 = load ptr, ptr %11, align 8, !tbaa !9
  %58 = call i64 @write(i32 noundef %56, ptr noundef %57, i64 noundef 5)
  %59 = load i32, ptr %6, align 4, !tbaa !5
  %60 = call i32 @tcdrain(i32 noundef %59)
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #8
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %61

61:                                               ; preds = %78, %55
  %62 = load i32, ptr %13, align 4, !tbaa !5
  %63 = icmp slt i32 %62, 5
  br i1 %63, label %65, label %64

64:                                               ; preds = %61
  store i32 6, ptr %14, align 4
  br label %81

65:                                               ; preds = %61
  %66 = call i32 @usleep(i32 noundef 1000)
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #8
  %67 = load i32, ptr %6, align 4, !tbaa !5
  %68 = getelementptr inbounds [65536 x i8], ptr %12, i64 0, i64 0
  %69 = call i64 @read(i32 noundef %67, ptr noundef %68, i64 noundef 65536)
  %70 = trunc i64 %69 to i32
  store i32 %70, ptr %15, align 4, !tbaa !5
  %71 = load i32, ptr %15, align 4, !tbaa !5
  %72 = icmp sgt i32 %71, 0
  br i1 %72, label %73, label %74

73:                                               ; preds = %65
  store i32 6, ptr %14, align 4
  br label %75

74:                                               ; preds = %65
  store i32 0, ptr %14, align 4
  br label %75

75:                                               ; preds = %74, %73
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #8
  %76 = load i32, ptr %14, align 4
  switch i32 %76, label %81 [
    i32 0, label %77
  ]

77:                                               ; preds = %75
  br label %78

78:                                               ; preds = %77
  %79 = load i32, ptr %13, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %13, align 4, !tbaa !5
  br label %61, !llvm.loop !11

81:                                               ; preds = %75, %64
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #8
  br label %82

82:                                               ; preds = %81
  %83 = getelementptr inbounds [65536 x i8], ptr %12, i64 0, i64 0
  %84 = call i32 @strcmp(ptr noundef %83, ptr noundef @.str.16) #10
  %85 = icmp ne i32 %84, 0
  br i1 %85, label %87, label %86

86:                                               ; preds = %82
  store i32 5, ptr %14, align 4
  br label %88

87:                                               ; preds = %82
  store i32 0, ptr %14, align 4
  br label %88

88:                                               ; preds = %87, %86
  call void @llvm.lifetime.end.p0(i64 65536, ptr %12) #8
  %89 = load i32, ptr %14, align 4
  switch i32 %89, label %177 [
    i32 0, label %90
    i32 5, label %91
  ]

90:                                               ; preds = %88
  br label %54

91:                                               ; preds = %88
  %92 = call i32 (ptr, ...) @printf(ptr noundef @.str.17)
  %93 = load i32, ptr %6, align 4, !tbaa !5
  %94 = load ptr, ptr %5, align 8, !tbaa !9
  %95 = getelementptr inbounds ptr, ptr %94, i64 2
  %96 = load ptr, ptr %95, align 8, !tbaa !9
  call void @send_kernel(i32 noundef %93, ptr noundef %96)
  store i32 3, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #8
  br label %97

97:                                               ; preds = %91
  call void @llvm.lifetime.start.p0(i64 60, ptr %16) #8
  call void @llvm.lifetime.start.p0(i64 60, ptr %17) #8
  %98 = call i32 @tcgetattr(i32 noundef 0, ptr noundef %16) #8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %17, ptr align 4 %16, i64 60, i1 false), !tbaa.struct !13
  %99 = getelementptr inbounds %struct.termios, ptr %17, i32 0, i32 3
  %100 = load i32, ptr %99, align 4, !tbaa !15
  %101 = and i32 %100, -11
  store i32 %101, ptr %99, align 4, !tbaa !15
  %102 = call i32 @tcsetattr(i32 noundef 0, i32 noundef 0, ptr noundef %17) #8
  br label %103

103:                                              ; preds = %176, %97
  br label %104

104:                                              ; preds = %103
  br label %105

105:                                              ; preds = %104
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #8
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #8
  store ptr %8, ptr %19, align 8, !tbaa !9
  store i32 0, ptr %18, align 4, !tbaa !5
  br label %106

106:                                              ; preds = %116, %105
  %107 = load i32, ptr %18, align 4, !tbaa !5
  %108 = zext i32 %107 to i64
  %109 = icmp ult i64 %108, 16
  br i1 %109, label %110, label %119

110:                                              ; preds = %106
  %111 = load ptr, ptr %19, align 8, !tbaa !9
  %112 = getelementptr inbounds %struct.fd_set, ptr %111, i32 0, i32 0
  %113 = load i32, ptr %18, align 4, !tbaa !5
  %114 = zext i32 %113 to i64
  %115 = getelementptr inbounds [16 x i64], ptr %112, i64 0, i64 %114
  store i64 0, ptr %115, align 8, !tbaa !17
  br label %116

116:                                              ; preds = %110
  %117 = load i32, ptr %18, align 4, !tbaa !5
  %118 = add i32 %117, 1
  store i32 %118, ptr %18, align 4, !tbaa !5
  br label %106, !llvm.loop !19

119:                                              ; preds = %106
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #8
  br label %120

120:                                              ; preds = %119
  br label %121

121:                                              ; preds = %120
  %122 = getelementptr inbounds %struct.fd_set, ptr %8, i32 0, i32 0
  %123 = getelementptr inbounds [16 x i64], ptr %122, i64 0, i64 0
  %124 = load i64, ptr %123, align 8, !tbaa !17
  %125 = or i64 %124, 1
  store i64 %125, ptr %123, align 8, !tbaa !17
  %126 = load i32, ptr %6, align 4, !tbaa !5
  %127 = srem i32 %126, 64
  %128 = zext i32 %127 to i64
  %129 = shl i64 1, %128
  %130 = getelementptr inbounds %struct.fd_set, ptr %8, i32 0, i32 0
  %131 = load i32, ptr %6, align 4, !tbaa !5
  %132 = sdiv i32 %131, 64
  %133 = sext i32 %132 to i64
  %134 = getelementptr inbounds [16 x i64], ptr %130, i64 0, i64 %133
  %135 = load i64, ptr %134, align 8, !tbaa !17
  %136 = or i64 %135, %129
  store i64 %136, ptr %134, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #8
  %137 = load i32, ptr %6, align 4, !tbaa !5
  %138 = add nsw i32 %137, 1
  %139 = call i32 @select(i32 noundef %138, ptr noundef %8, ptr noundef %9, ptr noundef %10, ptr noundef null)
  store i32 %139, ptr %20, align 4, !tbaa !5
  %140 = load i32, ptr %20, align 4, !tbaa !5
  %141 = icmp ne i32 %140, 0
  br i1 %141, label %142, label %176

142:                                              ; preds = %121
  %143 = getelementptr inbounds %struct.fd_set, ptr %8, i32 0, i32 0
  %144 = getelementptr inbounds [16 x i64], ptr %143, i64 0, i64 0
  %145 = load i64, ptr %144, align 8, !tbaa !17
  %146 = and i64 %145, 1
  %147 = icmp ne i64 %146, 0
  br i1 %147, label %148, label %155

148:                                              ; preds = %142
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #8
  %149 = getelementptr inbounds [65536 x i8], ptr %7, i64 0, i64 0
  %150 = call i64 @read(i32 noundef 0, ptr noundef %149, i64 noundef 65536)
  store i64 %150, ptr %21, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #8
  %151 = load i32, ptr %6, align 4, !tbaa !5
  %152 = getelementptr inbounds [65536 x i8], ptr %7, i64 0, i64 0
  %153 = load i64, ptr %21, align 8, !tbaa !17
  %154 = call i64 @write(i32 noundef %151, ptr noundef %152, i64 noundef %153)
  store i64 %154, ptr %22, align 8, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #8
  br label %155

155:                                              ; preds = %148, %142
  %156 = getelementptr inbounds %struct.fd_set, ptr %8, i32 0, i32 0
  %157 = load i32, ptr %6, align 4, !tbaa !5
  %158 = sdiv i32 %157, 64
  %159 = sext i32 %158 to i64
  %160 = getelementptr inbounds [16 x i64], ptr %156, i64 0, i64 %159
  %161 = load i64, ptr %160, align 8, !tbaa !17
  %162 = load i32, ptr %6, align 4, !tbaa !5
  %163 = srem i32 %162, 64
  %164 = zext i32 %163 to i64
  %165 = shl i64 1, %164
  %166 = and i64 %161, %165
  %167 = icmp ne i64 %166, 0
  br i1 %167, label %168, label %175

168:                                              ; preds = %155
  call void @llvm.lifetime.start.p0(i64 65536, ptr %23) #8
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #8
  %169 = load i32, ptr %6, align 4, !tbaa !5
  %170 = getelementptr inbounds [65536 x i8], ptr %23, i64 0, i64 0
  %171 = call i64 @read(i32 noundef %169, ptr noundef %170, i64 noundef 65536)
  store i64 %171, ptr %24, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %25) #8
  %172 = getelementptr inbounds [65536 x i8], ptr %23, i64 0, i64 0
  %173 = load i64, ptr %24, align 8, !tbaa !17
  %174 = call i64 @write(i32 noundef 1, ptr noundef %172, i64 noundef %173)
  store i64 %174, ptr %25, align 8, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 8, ptr %25) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #8
  call void @llvm.lifetime.end.p0(i64 65536, ptr %23) #8
  br label %175

175:                                              ; preds = %168, %155
  br label %176

176:                                              ; preds = %175, %121
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #8
  br label %103

177:                                              ; preds = %88
  unreachable
}

declare i32 @usleep(i32 noundef) #3

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #6

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #7

declare i32 @select(i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #3

attributes #0 = { 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 #1 = { noreturn 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nounwind willreturn memory(read) "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 #7 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #8 = { nounwind }
attributes #9 = { noreturn nounwind }
attributes #10 = { nounwind willreturn memory(read) }

!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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5, i64 12, i64 4, !5, i64 16, i64 1, !14, i64 17, i64 32, !14, i64 52, i64 4, !5, i64 56, i64 4, !5}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !6, i64 12}
!16 = !{!"termios", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !7, i64 16, !7, i64 17, !6, i64 52, !6, i64 56}
!17 = !{!18, !18, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = distinct !{!19, !12}


; 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.fd_set = type { [16 x i64] }
%struct.termios = type { i32, i32, i32, i32, i8, [32 x i8], i32, i32 }

@.str.11 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [18 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @do_exit(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @open_serial(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nounwind
declare i32 @tcgetattr(i32 noundef, ptr noundef) local_unnamed_addr #4

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

; Function Attrs: nounwind
declare i32 @tcsetattr(i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #4

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

; Function Attrs: nounwind uwtable
declare dso_local void @send_kernel(i32 noundef, ptr noundef) local_unnamed_addr #0

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

declare i32 @tcdrain(i32 noundef) local_unnamed_addr #6

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

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

; Function Attrs: noreturn nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #8 {
  %3 = alloca [65536 x i8], align 16
  %4 = alloca %struct.fd_set, align 8
  %5 = alloca %struct.fd_set, align 8
  %6 = alloca %struct.fd_set, align 8
  %7 = alloca [65536 x i8], align 16
  %8 = alloca %struct.termios, align 4
  %9 = alloca %struct.termios, align 4
  %10 = alloca [65536 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 65536, ptr nonnull %3) #11
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %4) #11
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %5) #11
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %6) #11
  %11 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11)
  %.not = icmp eq i32 %0, 3
  br i1 %.not, label %17, label %12

12:                                               ; preds = %2
  %13 = load ptr, ptr %1, align 8, !tbaa !5
  %14 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.12, ptr noundef %13)
  %15 = load ptr, ptr %1, align 8, !tbaa !5
  %16 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.13, ptr noundef %15)
  tail call void @exit(i32 noundef 1) #12
  unreachable

17:                                               ; preds = %2
  %18 = getelementptr inbounds i8, ptr %1, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %20 = tail call i32 @open_serial(ptr noundef %19)
  %21 = icmp eq i32 %20, -1
  br i1 %21, label %22, label %24

22:                                               ; preds = %17
  %23 = load ptr, ptr %18, align 8, !tbaa !5
  tail call void @perror(ptr noundef %23) #13
  tail call void @do_exit(i32 noundef -1, i32 noundef 1)
  br label %24

24:                                               ; preds = %22, %17
  %25 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.14)
  br label %26

26:                                               ; preds = %36, %24
  call void @llvm.lifetime.start.p0(i64 65536, ptr nonnull %7) #11
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(65536) %7, i8 0, i64 65536, i1 false)
  %27 = tail call i64 @write(i32 noundef %20, ptr noundef nonnull @.str.15, i64 noundef 5) #11
  %28 = tail call i32 @tcdrain(i32 noundef %20) #11
  br label %29

29:                                               ; preds = %29, %26
  %.039 = phi i32 [ 0, %26 ], [ %34, %29 ]
  %30 = tail call i32 @usleep(i32 noundef 1000) #11
  %31 = call i64 @read(i32 noundef %20, ptr noundef nonnull %7, i64 noundef 65536) #11
  %32 = trunc i64 %31 to i32
  %33 = icmp slt i32 %32, 1
  %34 = add nuw nsw i32 %.039, 1
  %35 = icmp ult i32 %.039, 4
  %or.cond = select i1 %33, i1 %35, i1 false
  br i1 %or.cond, label %29, label %36, !llvm.loop !9

36:                                               ; preds = %29
  %37 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %7, ptr noundef nonnull dereferenceable(1) @.str.16) #14
  %.not35 = icmp eq i32 %37, 0
  call void @llvm.lifetime.end.p0(i64 65536, ptr nonnull %7) #11
  br i1 %.not35, label %38, label %26

38:                                               ; preds = %36
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.17)
  %40 = getelementptr inbounds i8, ptr %1, i64 16
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  tail call void @send_kernel(i32 noundef %20, ptr noundef %41)
  call void @llvm.lifetime.start.p0(i64 60, ptr nonnull %8) #11
  call void @llvm.lifetime.start.p0(i64 60, ptr nonnull %9) #11
  %42 = call i32 @tcgetattr(i32 noundef 0, ptr noundef nonnull %8) #11
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(60) %9, ptr noundef nonnull align 4 dereferenceable(60) %8, i64 60, i1 false), !tbaa.struct !11
  %43 = getelementptr inbounds i8, ptr %9, i64 12
  %44 = load i32, ptr %43, align 4, !tbaa !15
  %45 = and i32 %44, -11
  store i32 %45, ptr %43, align 4, !tbaa !15
  %46 = call i32 @tcsetattr(i32 noundef 0, i32 noundef 0, ptr noundef nonnull %9) #11
  %47 = srem i32 %20, 64
  %48 = zext nneg i32 %47 to i64
  %49 = shl nuw i64 1, %48
  %50 = sdiv i32 %20, 64
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [16 x i64], ptr %4, i64 0, i64 %51
  %53 = add nsw i32 %20, 1
  %54 = getelementptr inbounds i8, ptr %4, i64 8
  br label %55

55:                                               ; preds = %.backedge, %38
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(128) %54, i8 0, i64 120, i1 false), !tbaa !17
  store i64 1, ptr %4, align 8, !tbaa !17
  %56 = load i64, ptr %52, align 8, !tbaa !17
  %57 = or i64 %56, %49
  store i64 %57, ptr %52, align 8, !tbaa !17
  %58 = call i32 @select(i32 noundef %53, ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef nonnull %6, ptr noundef null) #11
  %.not36 = icmp eq i32 %58, 0
  br i1 %.not36, label %.backedge, label %59

59:                                               ; preds = %55
  %60 = load i64, ptr %4, align 8, !tbaa !17
  %61 = and i64 %60, 1
  %.not37 = icmp eq i64 %61, 0
  br i1 %.not37, label %65, label %62

62:                                               ; preds = %59
  %63 = call i64 @read(i32 noundef 0, ptr noundef nonnull %3, i64 noundef 65536) #11
  %64 = call i64 @write(i32 noundef %20, ptr noundef nonnull %3, i64 noundef %63) #11
  br label %65

65:                                               ; preds = %62, %59
  %66 = load i64, ptr %52, align 8, !tbaa !17
  %67 = and i64 %66, %49
  %.not38 = icmp eq i64 %67, 0
  br i1 %.not38, label %.backedge, label %68

.backedge:                                        ; preds = %65, %68, %55
  br label %55

68:                                               ; preds = %65
  call void @llvm.lifetime.start.p0(i64 65536, ptr nonnull %10) #11
  %69 = call i64 @read(i32 noundef %20, ptr noundef nonnull %10, i64 noundef 65536) #11
  %70 = call i64 @write(i32 noundef 1, ptr noundef nonnull %10, i64 noundef %69) #11
  call void @llvm.lifetime.end.p0(i64 65536, ptr nonnull %10) #11
  br label %.backedge
}

declare i32 @usleep(i32 noundef) local_unnamed_addr #6

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #9

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #10

declare i32 @select(i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #6

attributes #0 = { 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 #1 = { noreturn 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #5 = { 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 #6 = { "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 #7 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #8 = { noreturn 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 #9 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 #10 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #11 = { nounwind }
attributes #12 = { noreturn nounwind }
attributes #13 = { cold }
attributes #14 = { nounwind willreturn memory(read) }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{i64 0, i64 4, !12, i64 4, i64 4, !12, i64 8, i64 4, !12, i64 12, i64 4, !12, i64 16, i64 1, !14, i64 17, i64 32, !14, i64 52, i64 4, !12, i64 56, i64 4, !12}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !13, i64 12}
!16 = !{!"termios", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !7, i64 16, !7, i64 17, !13, i64 52, !13, i64 56}
!17 = !{!18, !18, i64 0}
!18 = !{!"long", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopIdiomRecognizePass,LoopInstSimplifyPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass