; LLVM IR from dmalyuta/FlyARocket_GNC :: pressure_funcs (pressure_sensor_SPI_connect)

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

@ERROR_MESSAGE = external dso_local global [200 x i8], align 16
@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [59 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [59 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @pressure_sensor_SPI_connect(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2, i8 noundef zeroext %3, i64 noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %9 = alloca i8, align 1
  %10 = alloca i64, align 8
  %11 = alloca i8, align 1
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i8 %2, ptr %8, align 1, !tbaa !9
  store i8 %3, ptr %9, align 1, !tbaa !9
  store i64 %4, ptr %10, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #6
  store i8 0, ptr %11, align 1, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 16 @ERROR_MESSAGE, i8 0, i64 200, i1 false)
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = call i32 (ptr, i32, ...) @open(ptr noundef %12, i32 noundef 2)
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %13, ptr %14, align 4, !tbaa !12
  %15 = icmp ult i32 %13, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %5
  call void @perror(ptr noundef @.str)
  store i8 1, ptr %11, align 1, !tbaa !9
  br label %17

17:                                               ; preds = %16, %5
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = load i32, ptr %18, align 4, !tbaa !12
  %20 = call i32 (i32, i64, ...) @ioctl(i32 noundef %19, i64 noundef 1073834753, ptr noundef %8) #6
  %21 = icmp eq i32 %20, -1
  br i1 %21, label %22, label %23

22:                                               ; preds = %17
  call void @perror(ptr noundef @.str.1)
  store i8 1, ptr %11, align 1, !tbaa !9
  br label %23

23:                                               ; preds = %22, %17
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = load i32, ptr %24, align 4, !tbaa !12
  %26 = call i32 (i32, i64, ...) @ioctl(i32 noundef %25, i64 noundef 2147576577, ptr noundef %8) #6
  %27 = icmp eq i32 %26, -1
  br i1 %27, label %28, label %29

28:                                               ; preds = %23
  call void @perror(ptr noundef @.str.2)
  store i8 1, ptr %11, align 1, !tbaa !9
  br label %29

29:                                               ; preds = %28, %23
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = load i32, ptr %30, align 4, !tbaa !12
  %32 = call i32 (i32, i64, ...) @ioctl(i32 noundef %31, i64 noundef 1073834755, ptr noundef %9) #6
  %33 = icmp eq i32 %32, -1
  br i1 %33, label %34, label %35

34:                                               ; preds = %29
  call void @perror(ptr noundef @.str.3)
  store i8 1, ptr %11, align 1, !tbaa !9
  br label %35

35:                                               ; preds = %34, %29
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load i32, ptr %36, align 4, !tbaa !12
  %38 = call i32 (i32, i64, ...) @ioctl(i32 noundef %37, i64 noundef 2147576579, ptr noundef %9) #6
  %39 = icmp eq i32 %38, -1
  br i1 %39, label %40, label %41

40:                                               ; preds = %35
  call void @perror(ptr noundef @.str.4)
  store i8 1, ptr %11, align 1, !tbaa !9
  br label %41

41:                                               ; preds = %40, %35
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = load i32, ptr %42, align 4, !tbaa !12
  %44 = call i32 (i32, i64, ...) @ioctl(i32 noundef %43, i64 noundef 1074031364, ptr noundef %10) #6
  %45 = icmp eq i32 %44, -1
  br i1 %45, label %46, label %47

46:                                               ; preds = %41
  call void @perror(ptr noundef @.str.5)
  store i8 1, ptr %11, align 1, !tbaa !9
  br label %47

47:                                               ; preds = %46, %41
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = load i32, ptr %48, align 4, !tbaa !12
  %50 = call i32 (i32, i64, ...) @ioctl(i32 noundef %49, i64 noundef 2147773188, ptr noundef %10) #6
  %51 = icmp eq i32 %50, -1
  br i1 %51, label %52, label %53

52:                                               ; preds = %47
  call void @perror(ptr noundef @.str.6)
  store i8 1, ptr %11, align 1, !tbaa !9
  br label %53

53:                                               ; preds = %52, %47
  %54 = load i8, ptr %11, align 1, !tbaa !9
  %55 = icmp ne i8 %54, 0
  br i1 %55, label %56, label %57

56:                                               ; preds = %53
  call void @exit(i32 noundef -2) #7
  unreachable

57:                                               ; preds = %53
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #6
  ret void
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

declare void @perror(ptr noundef) #3

; Function Attrs: nounwind
declare i32 @ioctl(i32 noundef, i64 noundef, ...) #4

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { 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 #6 = { nounwind }
attributes #7 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !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"

@ERROR_MESSAGE = external dso_local local_unnamed_addr global [200 x i8], align 16
@.str.1 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [59 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [59 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @pressure_sensor_SPI_connect(ptr nocapture noundef readonly %0, ptr nocapture noundef %1, i8 noundef zeroext %2, i8 noundef zeroext %3, i64 noundef %4) local_unnamed_addr #0 {
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  %8 = alloca i64, align 8
  store i8 %2, ptr %6, align 1, !tbaa !5
  store i8 %3, ptr %7, align 1, !tbaa !5
  store i64 %4, ptr %8, align 8, !tbaa !8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(200) @ERROR_MESSAGE, i8 0, i64 200, i1 false)
  %9 = tail call i32 (ptr, i32, ...) @open(ptr noundef %0, i32 noundef 2) #6
  store i32 %9, ptr %1, align 4, !tbaa !10
  %10 = call i32 (i32, i64, ...) @ioctl(i32 noundef %9, i64 noundef 1073834753, ptr noundef nonnull %6) #6
  %11 = icmp eq i32 %10, -1
  br i1 %11, label %12, label %13

12:                                               ; preds = %5
  call void @perror(ptr noundef nonnull @.str.1) #7
  br label %13

13:                                               ; preds = %12, %5
  %.1 = phi i8 [ 1, %12 ], [ 0, %5 ]
  %14 = load i32, ptr %1, align 4, !tbaa !10
  %15 = call i32 (i32, i64, ...) @ioctl(i32 noundef %14, i64 noundef 2147576577, ptr noundef nonnull %6) #6
  %16 = icmp eq i32 %15, -1
  br i1 %16, label %17, label %18

17:                                               ; preds = %13
  call void @perror(ptr noundef nonnull @.str.2) #7
  br label %18

18:                                               ; preds = %17, %13
  %.2 = phi i8 [ 1, %17 ], [ %.1, %13 ]
  %19 = load i32, ptr %1, align 4, !tbaa !10
  %20 = call i32 (i32, i64, ...) @ioctl(i32 noundef %19, i64 noundef 1073834755, ptr noundef nonnull %7) #6
  %21 = icmp eq i32 %20, -1
  br i1 %21, label %22, label %23

22:                                               ; preds = %18
  call void @perror(ptr noundef nonnull @.str.3) #7
  br label %23

23:                                               ; preds = %22, %18
  %.3 = phi i8 [ 1, %22 ], [ %.2, %18 ]
  %24 = load i32, ptr %1, align 4, !tbaa !10
  %25 = call i32 (i32, i64, ...) @ioctl(i32 noundef %24, i64 noundef 2147576579, ptr noundef nonnull %7) #6
  %26 = icmp eq i32 %25, -1
  br i1 %26, label %27, label %28

27:                                               ; preds = %23
  call void @perror(ptr noundef nonnull @.str.4) #7
  br label %28

28:                                               ; preds = %27, %23
  %.4 = phi i8 [ 1, %27 ], [ %.3, %23 ]
  %29 = load i32, ptr %1, align 4, !tbaa !10
  %30 = call i32 (i32, i64, ...) @ioctl(i32 noundef %29, i64 noundef 1074031364, ptr noundef nonnull %8) #6
  %31 = icmp eq i32 %30, -1
  br i1 %31, label %32, label %33

32:                                               ; preds = %28
  call void @perror(ptr noundef nonnull @.str.5) #7
  br label %33

33:                                               ; preds = %32, %28
  %.5 = phi i8 [ 1, %32 ], [ %.4, %28 ]
  %34 = load i32, ptr %1, align 4, !tbaa !10
  %35 = call i32 (i32, i64, ...) @ioctl(i32 noundef %34, i64 noundef 2147773188, ptr noundef nonnull %8) #6
  %36 = icmp eq i32 %35, -1
  br i1 %36, label %.thread, label %37

.thread:                                          ; preds = %33
  call void @perror(ptr noundef nonnull @.str.6) #7
  br label %38

37:                                               ; preds = %33
  %.not = icmp eq i8 %.5, 0
  br i1 %.not, label %39, label %38

38:                                               ; preds = %.thread, %37
  call void @exit(i32 noundef -2) #8
  unreachable

39:                                               ; preds = %37
  ret void
}

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

; Function Attrs: nofree
declare noundef i32 @open(ptr nocapture noundef readonly, i32 noundef, ...) local_unnamed_addr #2

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

; Function Attrs: nounwind
declare i32 @ioctl(i32 noundef, i64 noundef, ...) local_unnamed_addr #4

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

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #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 = { 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 #6 = { nounwind }
attributes #7 = { cold }
attributes #8 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"long", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass