; LLVM IR from DroneBridge/DroneBridge :: common (shared_memory)

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

@.str.8 = external hidden unnamed_addr constant [17 x i8], align 1
@stderr = external global ptr, align 8
@.str.9 = external hidden unnamed_addr constant [67 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [5 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

declare i32 @shm_open(ptr noundef, i32 noundef, i32 noundef) #1

declare void @perror(ptr noundef) #1

declare i32 @usleep(i32 noundef) #1

; Function Attrs: nounwind
declare i32 @ftruncate(i32 noundef, i64 noundef) #2

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

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

; 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 ptr @db_uav_status_memory_open() #4 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #6
  br label %3

3:                                                ; preds = %21, %0
  %4 = call i32 @shm_open(ptr noundef @.str.8, i32 noundef 578, i32 noundef 384)
  store i32 %4, ptr %1, align 4, !tbaa !5
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = icmp slt i32 %5, 0
  br i1 %6, label %7, label %20

7:                                                ; preds = %3
  br label %8

8:                                                ; preds = %7
  %9 = load ptr, ptr @stderr, align 8, !tbaa !9
  %10 = call ptr @__errno_location() #7
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = call ptr @strerror(i32 noundef %11) #6
  %13 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %9, ptr noundef @.str.9, ptr noundef %12) #6
  %14 = call ptr @__errno_location() #7
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = call ptr @strerror(i32 noundef %15) #6
  call void (i32, ptr, ...) @syslog(i32 noundef 3, ptr noundef @.str.9, ptr noundef %16)
  br label %17

17:                                               ; preds = %8
  br label %18

18:                                               ; preds = %17
  %19 = call i32 @usleep(i32 noundef 100000)
  br label %20

20:                                               ; preds = %18, %3
  br label %21

21:                                               ; preds = %20
  %22 = load i32, ptr %1, align 4, !tbaa !5
  %23 = icmp slt i32 %22, 0
  br i1 %23, label %3, label %24, !llvm.loop !11

24:                                               ; preds = %21
  %25 = load i32, ptr %1, align 4, !tbaa !5
  %26 = call i32 @ftruncate(i32 noundef %25, i64 noundef 300) #6
  %27 = icmp eq i32 %26, -1
  br i1 %27, label %28, label %29

28:                                               ; preds = %24
  call void @perror(ptr noundef @.str.10)
  call void @exit(i32 noundef 1) #8
  unreachable

29:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #6
  %30 = load i32, ptr %1, align 4, !tbaa !5
  %31 = call ptr @mmap(ptr noundef null, i64 noundef 300, i32 noundef 3, i32 noundef 1, i32 noundef %30, i64 noundef 0) #6
  store ptr %31, ptr %2, align 8, !tbaa !9
  %32 = load ptr, ptr %2, align 8, !tbaa !9
  %33 = icmp eq ptr %32, inttoptr (i64 -1 to ptr)
  br i1 %33, label %34, label %35

34:                                               ; preds = %29
  call void @perror(ptr noundef @.str.11)
  call void @exit(i32 noundef 1) #8
  unreachable

35:                                               ; preds = %29
  %36 = load ptr, ptr %2, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #6
  ret ptr %36
}

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

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

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #5

declare void @syslog(i32 noundef, ptr noundef, ...) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #4 = { 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 #5 = { nounwind willreturn memory(none) "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 = { nounwind willreturn memory(none) }
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 = !{!"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"}


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

@.str.8 = external hidden unnamed_addr constant [17 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.9 = external hidden unnamed_addr constant [67 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [5 x i8], align 1

declare i32 @shm_open(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

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

declare i32 @usleep(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind
declare i32 @ftruncate(i32 noundef, i64 noundef) local_unnamed_addr #2

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @db_uav_status_memory_open() local_unnamed_addr #4 {
  %1 = tail call i32 @shm_open(ptr noundef nonnull @.str.8, i32 noundef 578, i32 noundef 384) #6
  %2 = icmp slt i32 %1, 0
  br i1 %2, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %0
  %3 = tail call ptr @__errno_location() #7
  br label %4

4:                                                ; preds = %.lr.ph, %4
  %5 = load ptr, ptr @stderr, align 8, !tbaa !5
  %6 = load i32, ptr %3, align 4, !tbaa !9
  %7 = tail call ptr @strerror(i32 noundef %6) #6
  %8 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str.9, ptr noundef %7) #8
  %9 = load i32, ptr %3, align 4, !tbaa !9
  %10 = tail call ptr @strerror(i32 noundef %9) #6
  tail call void (i32, ptr, ...) @syslog(i32 noundef 3, ptr noundef nonnull @.str.9, ptr noundef %10) #6
  %11 = tail call i32 @usleep(i32 noundef 100000) #6
  %12 = tail call i32 @shm_open(ptr noundef nonnull @.str.8, i32 noundef 578, i32 noundef 384) #6
  %13 = icmp slt i32 %12, 0
  br i1 %13, label %4, label %.critedge, !llvm.loop !11

.critedge:                                        ; preds = %4, %0
  %.lcssa = phi i32 [ %1, %0 ], [ %12, %4 ]
  %14 = tail call i32 @ftruncate(i32 noundef %.lcssa, i64 noundef 300) #6
  %15 = icmp eq i32 %14, -1
  br i1 %15, label %16, label %17

16:                                               ; preds = %.critedge
  tail call void @perror(ptr noundef nonnull @.str.10) #9
  tail call void @exit(i32 noundef 1) #10
  unreachable

17:                                               ; preds = %.critedge
  %18 = tail call ptr @mmap(ptr noundef null, i64 noundef 300, i32 noundef 3, i32 noundef 1, i32 noundef %.lcssa, i64 noundef 0) #6
  %19 = icmp eq ptr %18, inttoptr (i64 -1 to ptr)
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  tail call void @perror(ptr noundef nonnull @.str.11) #9
  tail call void @exit(i32 noundef 1) #10
  unreachable

21:                                               ; preds = %17
  ret ptr %18
}

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

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

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #5

declare void @syslog(i32 noundef, ptr noundef, ...) local_unnamed_addr #0

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 = { 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 #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 = { 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 #4 = { 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 #5 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 = { nounwind willreturn memory(none) }
attributes #8 = { cold nounwind }
attributes #9 = { cold }
attributes #10 = { 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass