; LLVM IR from dmr-goncalves/HumanAwareRobotNavigation :: src/husky/husky_base/src/horizon_legacy/linux_serial.ll (Z11SetupSerialPv)

; 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 }

; 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: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z11SetupSerialPv(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca %struct.termios, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 60, ptr %3) #3
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = load i32, ptr %4, align 4, !tbaa !9
  %6 = call i32 @tcgetattr(i32 noundef %5, ptr noundef %3) #3
  %7 = getelementptr inbounds %struct.termios, ptr %3, i32 0, i32 2
  store i32 0, ptr %7, align 4, !tbaa !11
  %8 = getelementptr inbounds %struct.termios, ptr %3, i32 0, i32 2
  %9 = load i32, ptr %8, align 4, !tbaa !11
  %10 = or i32 %9, 48
  store i32 %10, ptr %8, align 4, !tbaa !11
  %11 = getelementptr inbounds %struct.termios, ptr %3, i32 0, i32 2
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = or i32 %12, 2176
  store i32 %13, ptr %11, align 4, !tbaa !11
  %14 = call i32 @cfsetispeed(ptr noundef %3, i32 noundef 4098) #3
  %15 = call i32 @cfsetospeed(ptr noundef %3, i32 noundef 4098) #3
  %16 = getelementptr inbounds %struct.termios, ptr %3, i32 0, i32 0
  store i32 0, ptr %16, align 4, !tbaa !13
  %17 = getelementptr inbounds %struct.termios, ptr %3, i32 0, i32 1
  store i32 0, ptr %17, align 4, !tbaa !14
  %18 = getelementptr inbounds %struct.termios, ptr %3, i32 0, i32 3
  store i32 0, ptr %18, align 4, !tbaa !15
  %19 = getelementptr inbounds %struct.termios, ptr %3, i32 0, i32 5
  %20 = getelementptr inbounds [32 x i8], ptr %19, i64 0, i64 6
  store i8 0, ptr %20, align 1, !tbaa !16
  %21 = getelementptr inbounds %struct.termios, ptr %3, i32 0, i32 5
  %22 = getelementptr inbounds [32 x i8], ptr %21, i64 0, i64 5
  store i8 1, ptr %22, align 1, !tbaa !16
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = call i32 @tcsetattr(i32 noundef %24, i32 noundef 2, ptr noundef %3) #3
  call void @llvm.lifetime.end.p0(i64 60, ptr %3) #3
  ret i32 0
}

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

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

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"_ZTS7termios", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !7, i64 16, !7, i64 17, !10, i64 52, !10, i64 56}
!13 = !{!12, !10, i64 0}
!14 = !{!12, !10, i64 4}
!15 = !{!12, !10, i64 12}
!16 = !{!7, !7, i64 0}


; 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 }

; 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: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z11SetupSerialPv(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = alloca %struct.termios, align 4
  call void @llvm.lifetime.start.p0(i64 60, ptr nonnull %2) #3
  %3 = load i32, ptr %0, align 4, !tbaa !5
  %4 = call i32 @tcgetattr(i32 noundef %3, ptr noundef nonnull %2) #3
  %5 = getelementptr inbounds i8, ptr %2, i64 8
  store i32 2224, ptr %5, align 4, !tbaa !9
  %6 = call i32 @cfsetispeed(ptr noundef nonnull %2, i32 noundef 4098) #3
  %7 = call i32 @cfsetospeed(ptr noundef nonnull %2, i32 noundef 4098) #3
  store i32 0, ptr %2, align 4, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %2, i64 4
  store i32 0, ptr %8, align 4, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %2, i64 12
  store i32 0, ptr %9, align 4, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %2, i64 23
  store i8 0, ptr %10, align 1, !tbaa !14
  %11 = getelementptr inbounds i8, ptr %2, i64 22
  store i8 1, ptr %11, align 2, !tbaa !14
  %12 = load i32, ptr %0, align 4, !tbaa !5
  %13 = call i32 @tcsetattr(i32 noundef %12, i32 noundef 2, ptr noundef nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 60, ptr nonnull %2) #3
  ret i32 0
}

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

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

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

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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 #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++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"_ZTS7termios", !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}
!13 = !{!10, !6, i64 12}
!14 = !{!7, !7, i64 0}


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