; LLVM IR from giusenso/Ball-Balancing-PID-System :: serial (serial)

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

@.str.8 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [60 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @setSerialAttributes(i32 noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca %struct.termios, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 60, ptr %3) #5
  %4 = load i32, ptr %2, align 4, !tbaa !5
  %5 = call i32 @tcgetattr(i32 noundef %4, ptr noundef %3) #5
  %6 = call i32 @cfsetispeed(ptr noundef %3, i32 noundef 13) #5
  %7 = call i32 @cfsetospeed(ptr noundef %3, i32 noundef 13) #5
  %8 = getelementptr inbounds %struct.termios, ptr %3, i32 0, i32 2
  %9 = load i32, ptr %8, align 4, !tbaa !9
  %10 = and i32 %9, -257
  store i32 %10, ptr %8, align 4, !tbaa !9
  %11 = getelementptr inbounds %struct.termios, ptr %3, i32 0, i32 2
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = and i32 %12, -65
  store i32 %13, ptr %11, align 4, !tbaa !9
  %14 = getelementptr inbounds %struct.termios, ptr %3, i32 0, i32 2
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %16 = and i32 %15, -49
  store i32 %16, ptr %14, align 4, !tbaa !9
  %17 = getelementptr inbounds %struct.termios, ptr %3, i32 0, i32 2
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = or i32 %18, 48
  store i32 %19, ptr %17, align 4, !tbaa !9
  %20 = getelementptr inbounds %struct.termios, ptr %3, i32 0, i32 2
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = and i32 %21, 2147483647
  store i32 %22, ptr %20, align 4, !tbaa !9
  %23 = getelementptr inbounds %struct.termios, ptr %3, i32 0, i32 2
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = or i32 %24, 2176
  store i32 %25, ptr %23, align 4, !tbaa !9
  %26 = getelementptr inbounds %struct.termios, ptr %3, i32 0, i32 0
  %27 = load i32, ptr %26, align 4, !tbaa !11
  %28 = and i32 %27, -7169
  store i32 %28, ptr %26, align 4, !tbaa !11
  %29 = getelementptr inbounds %struct.termios, ptr %3, i32 0, i32 0
  %30 = load i32, ptr %29, align 4, !tbaa !11
  %31 = and i32 %30, -28
  store i32 %31, ptr %29, align 4, !tbaa !11
  %32 = getelementptr inbounds %struct.termios, ptr %3, i32 0, i32 1
  %33 = load i32, ptr %32, align 4, !tbaa !12
  %34 = and i32 %33, -2
  store i32 %34, ptr %32, align 4, !tbaa !12
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = call i32 @tcsetattr(i32 noundef %35, i32 noundef 0, ptr noundef %3) #5
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %40

38:                                               ; preds = %1
  %39 = call i32 (ptr, ...) @printf(ptr noundef @.str.8)
  call void @exit(i32 noundef 1) #6
  unreachable

40:                                               ; preds = %1
  %41 = call i32 (ptr, ...) @printf(ptr noundef @.str.9, i32 noundef 9600)
  br label %42

42:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 60, ptr %3) #5
  ret void
}

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

; Function Attrs: nounwind
declare i32 @cfsetispeed(ptr noundef, i32 noundef) #3

; Function Attrs: nounwind
declare i32 @cfsetospeed(ptr noundef, i32 noundef) #3

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

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

attributes #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 = { 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 #5 = { nounwind }
attributes #6 = { noreturn 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 8}
!10 = !{!"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}
!11 = !{!10, !6, i64 0}
!12 = !{!10, !6, i64 4}


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

@.str.8 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [60 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) 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) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @setSerialAttributes(i32 noundef %0) local_unnamed_addr #2 {
  %2 = alloca %struct.termios, align 8
  call void @llvm.lifetime.start.p0(i64 60, ptr nonnull %2) #5
  %3 = call i32 @tcgetattr(i32 noundef %0, ptr noundef nonnull %2) #5
  %4 = call i32 @cfsetispeed(ptr noundef nonnull %2, i32 noundef 13) #5
  %5 = call i32 @cfsetospeed(ptr noundef nonnull %2, i32 noundef 13) #5
  %6 = getelementptr inbounds i8, ptr %2, i64 8
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = and i32 %7, 2147481103
  %9 = or disjoint i32 %8, 2224
  store i32 %9, ptr %6, align 8, !tbaa !5
  %10 = load <2 x i32>, ptr %2, align 8, !tbaa !10
  %11 = and <2 x i32> %10, <i32 -7196, i32 -2>
  store <2 x i32> %11, ptr %2, align 8, !tbaa !10
  %12 = call i32 @tcsetattr(i32 noundef %0, i32 noundef 0, ptr noundef nonnull %2) #5
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %15, label %13

13:                                               ; preds = %1
  %14 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  call void @exit(i32 noundef 1) #6
  unreachable

15:                                               ; preds = %1
  %16 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9, i32 noundef 9600)
  call void @llvm.lifetime.end.p0(i64 60, ptr nonnull %2) #5
  ret void
}

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

; Function Attrs: nounwind
declare i32 @cfsetispeed(ptr noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: nounwind
declare i32 @cfsetospeed(ptr noundef, i32 noundef) local_unnamed_addr #3

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

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 = { 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 #5 = { nounwind }
attributes #6 = { noreturn 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 8}
!6 = !{!"termios", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !8, i64 16, !8, i64 17, !7, i64 52, !7, i64 56}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass