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

; 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.db_unix_tcp_socket = type { i32, %struct.sockaddr_un }
%struct.sockaddr_un = type { i16, [108 x i8] }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [41 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [50 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @db_create_unix_tcpserver_sock(ptr dead_on_unwind noalias writable sret(%struct.db_unix_tcp_socket) align 4 %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca %struct.sockaddr_un, align 2
  %5 = alloca i32, align 4
  store ptr %1, ptr %3, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 4 %0, i8 0, i64 116, i1 false)
  %6 = getelementptr inbounds %struct.db_unix_tcp_socket, ptr %0, i32 0, i32 0
  store i32 -1, ptr %6, align 4
  call void @llvm.lifetime.start.p0(i64 110, ptr %4) #6
  call void @llvm.memset.p0.i64(ptr align 2 %4, i8 0, i64 110, i1 false)
  %7 = call i32 @socket(i32 noundef 1, i32 noundef 1, i32 noundef 0) #6
  %8 = getelementptr inbounds %struct.db_unix_tcp_socket, ptr %0, i32 0, i32 0
  store i32 %7, ptr %8, align 4, !tbaa !9
  %9 = icmp eq i32 %7, -1
  br i1 %9, label %10, label %16

10:                                               ; preds = %2
  br label %11

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

14:                                               ; preds = %11
  br label %15

15:                                               ; preds = %14
  store i32 1, ptr %5, align 4
  br label %49

16:                                               ; preds = %2
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = call i32 @unlink(ptr noundef %17) #6
  %19 = getelementptr inbounds %struct.db_unix_tcp_socket, ptr %0, i32 0, i32 1
  %20 = getelementptr inbounds %struct.sockaddr_un, ptr %19, i32 0, i32 0
  store i16 1, ptr %20, align 4, !tbaa !14
  %21 = getelementptr inbounds %struct.db_unix_tcp_socket, ptr %0, i32 0, i32 1
  %22 = getelementptr inbounds %struct.sockaddr_un, ptr %21, i32 0, i32 1
  %23 = getelementptr inbounds [108 x i8], ptr %22, i64 0, i64 0
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = call ptr @strcpy(ptr noundef %23, ptr noundef %24) #6
  %26 = getelementptr inbounds %struct.db_unix_tcp_socket, ptr %0, i32 0, i32 0
  %27 = load i32, ptr %26, align 4, !tbaa !9
  %28 = getelementptr inbounds %struct.db_unix_tcp_socket, ptr %0, i32 0, i32 1
  %29 = call i32 @bind(i32 noundef %27, ptr noundef %28, i32 noundef 110) #6
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %45

31:                                               ; preds = %16
  br label %32

32:                                               ; preds = %31
  %33 = load ptr, ptr @stderr, align 8, !tbaa !5
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = call ptr @__errno_location() #7
  %36 = load i32, ptr %35, align 4, !tbaa !15
  %37 = call ptr @strerror(i32 noundef %36) #6
  %38 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef @.str.1, ptr noundef %34, ptr noundef %37) #6
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = call ptr @__errno_location() #7
  %41 = load i32, ptr %40, align 4, !tbaa !15
  %42 = call ptr @strerror(i32 noundef %41) #6
  call void (i32, ptr, ...) @syslog(i32 noundef 3, ptr noundef @.str.1, ptr noundef %39, ptr noundef %42)
  br label %43

43:                                               ; preds = %32
  br label %44

44:                                               ; preds = %43
  store i32 1, ptr %5, align 4
  br label %49

45:                                               ; preds = %16
  %46 = getelementptr inbounds %struct.db_unix_tcp_socket, ptr %0, i32 0, i32 0
  %47 = load i32, ptr %46, align 4, !tbaa !9
  %48 = call i32 @listen(i32 noundef %47, i32 noundef 5) #6
  store i32 1, ptr %5, align 4
  br label %49

49:                                               ; preds = %45, %44, %15
  call void @llvm.lifetime.end.p0(i64 110, ptr %4) #6
  ret void
}

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

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

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

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

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

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

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

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

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

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

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

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

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 nounwind willreturn memory(argmem: write) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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) }

!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, !11, i64 0}
!10 = !{!"", !11, i64 0, !12, i64 4}
!11 = !{!"int", !7, i64 0}
!12 = !{!"sockaddr_un", !13, i64 0, !7, i64 2}
!13 = !{!"short", !7, i64 0}
!14 = !{!10, !13, i64 4}
!15 = !{!11, !11, 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.db_unix_tcp_socket = type { i32, %struct.sockaddr_un }
%struct.sockaddr_un = type { i16, [108 x i8] }

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [41 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [50 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @db_create_unix_tcpserver_sock(ptr dead_on_unwind noalias writable sret(%struct.db_unix_tcp_socket) align 4 %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(116) %3, i8 0, i64 112, i1 false)
  %4 = tail call i32 @socket(i32 noundef 1, i32 noundef 1, i32 noundef 0) #7
  store i32 %4, ptr %0, align 4, !tbaa !5
  %5 = icmp eq i32 %4, -1
  br i1 %5, label %6, label %9

6:                                                ; preds = %2
  %7 = load ptr, ptr @stderr, align 8, !tbaa !12
  %8 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef nonnull @.str) #8
  tail call void (i32, ptr, ...) @syslog(i32 noundef 3, ptr noundef nonnull @.str) #7
  br label %26

9:                                                ; preds = %2
  %10 = tail call i32 @unlink(ptr noundef %1) #7
  %11 = getelementptr inbounds i8, ptr %0, i64 4
  store i16 1, ptr %11, align 4, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %0, i64 6
  %13 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %12, ptr noundef nonnull dereferenceable(1) %1) #7
  %14 = tail call i32 @bind(i32 noundef %4, ptr noundef nonnull %11, i32 noundef 110) #7
  %.not = icmp eq i32 %14, 0
  br i1 %.not, label %23, label %15

15:                                               ; preds = %9
  %16 = load ptr, ptr @stderr, align 8, !tbaa !12
  %17 = tail call ptr @__errno_location() #9
  %18 = load i32, ptr %17, align 4, !tbaa !15
  %19 = tail call ptr @strerror(i32 noundef %18) #7
  %20 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str.1, ptr noundef %1, ptr noundef %19) #8
  %21 = load i32, ptr %17, align 4, !tbaa !15
  %22 = tail call ptr @strerror(i32 noundef %21) #7
  tail call void (i32, ptr, ...) @syslog(i32 noundef 3, ptr noundef nonnull @.str.1, ptr noundef %1, ptr noundef %22) #7
  br label %26

23:                                               ; preds = %9
  %24 = load i32, ptr %0, align 4, !tbaa !5
  %25 = tail call i32 @listen(i32 noundef %24, i32 noundef 5) #7
  br label %26

26:                                               ; preds = %23, %15, %6
  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: nounwind
declare i32 @socket(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

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

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #5

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

; 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 #6

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

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 = { 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 = { 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 = { "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 nounwind willreturn memory(argmem: readwrite) "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 = { 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 #7 = { nounwind }
attributes #8 = { cold nounwind }
attributes #9 = { nounwind willreturn memory(none) }

!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 0}
!6 = !{!"", !7, i64 0, !10, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"sockaddr_un", !11, i64 0, !8, i64 2}
!11 = !{!"short", !8, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!6, !11, i64 4}
!15 = !{!7, !7, i64 0}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass