; LLVM IR from AbdulrahmanXSO25/mkdb_cclient :: mkdb (tcp_server_init)

; 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.sockaddr_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }
%struct.tcp_server_t = type { i32, i32, i32, ptr, ptr }

@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [7 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 void @perror(ptr noundef) #1

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i16 @__bswap_16(i16 noundef zeroext) #4

declare i32 @close(i32 noundef) #1

; 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 i32 @tcp_server_init(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #5 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca %struct.sockaddr_in, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %18

15:                                               ; preds = %4
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %19, label %18

18:                                               ; preds = %15, %4
  store i32 -1, ptr %5, align 4
  br label %82

19:                                               ; preds = %15
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.tcp_server_t, ptr %21, i32 0, i32 1
  store i32 %20, ptr %22, align 4, !tbaa !11
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.tcp_server_t, ptr %24, i32 0, i32 3
  store ptr %23, ptr %25, align 8, !tbaa !13
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.tcp_server_t, ptr %27, i32 0, i32 4
  store ptr %26, ptr %28, align 8, !tbaa !14
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.tcp_server_t, ptr %29, i32 0, i32 2
  store volatile i32 0, ptr %30, align 8, !tbaa !15
  %31 = call i32 @socket(i32 noundef 2, i32 noundef 1, i32 noundef 0) #6
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.tcp_server_t, ptr %32, i32 0, i32 0
  store i32 %31, ptr %33, align 8, !tbaa !16
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.tcp_server_t, ptr %34, i32 0, i32 0
  %36 = load i32, ptr %35, align 8, !tbaa !16
  %37 = icmp slt i32 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %19
  call void @perror(ptr noundef @.str.1)
  store i32 -1, ptr %5, align 4
  br label %82

39:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  store i32 1, ptr %10, align 4, !tbaa !9
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.tcp_server_t, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %41, align 8, !tbaa !16
  %43 = call i32 @setsockopt(i32 noundef %42, i32 noundef 1, i32 noundef 2, ptr noundef %10, i32 noundef 4) #6
  %44 = icmp slt i32 %43, 0
  br i1 %44, label %45, label %50

45:                                               ; preds = %39
  call void @perror(ptr noundef @.str.9)
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.tcp_server_t, ptr %46, i32 0, i32 0
  %48 = load i32, ptr %47, align 8, !tbaa !16
  %49 = call i32 @close(i32 noundef %48)
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %81

50:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #6
  call void @llvm.memset.p0.i64(ptr align 4 %12, i8 0, i64 16, i1 false)
  %51 = getelementptr inbounds %struct.sockaddr_in, ptr %12, i32 0, i32 0
  store i16 2, ptr %51, align 4, !tbaa !17
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = trunc i32 %52 to i16
  %54 = call zeroext i16 @__bswap_16(i16 noundef zeroext %53)
  %55 = getelementptr inbounds %struct.sockaddr_in, ptr %12, i32 0, i32 1
  store i16 %54, ptr %55, align 2, !tbaa !21
  %56 = getelementptr inbounds %struct.sockaddr_in, ptr %12, i32 0, i32 2
  %57 = getelementptr inbounds %struct.in_addr, ptr %56, i32 0, i32 0
  store i32 0, ptr %57, align 4, !tbaa !22
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.tcp_server_t, ptr %58, i32 0, i32 0
  %60 = load i32, ptr %59, align 8, !tbaa !16
  %61 = call i32 @bind(i32 noundef %60, ptr noundef %12, i32 noundef 16) #6
  %62 = icmp slt i32 %61, 0
  br i1 %62, label %63, label %68

63:                                               ; preds = %50
  call void @perror(ptr noundef @.str.10)
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.tcp_server_t, ptr %64, i32 0, i32 0
  %66 = load i32, ptr %65, align 8, !tbaa !16
  %67 = call i32 @close(i32 noundef %66)
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %80

68:                                               ; preds = %50
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.tcp_server_t, ptr %69, i32 0, i32 0
  %71 = load i32, ptr %70, align 8, !tbaa !16
  %72 = call i32 @listen(i32 noundef %71, i32 noundef 10) #6
  %73 = icmp slt i32 %72, 0
  br i1 %73, label %74, label %79

74:                                               ; preds = %68
  call void @perror(ptr noundef @.str.11)
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.tcp_server_t, ptr %75, i32 0, i32 0
  %77 = load i32, ptr %76, align 8, !tbaa !16
  %78 = call i32 @close(i32 noundef %77)
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %80

79:                                               ; preds = %68
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %80

80:                                               ; preds = %79, %74, %63
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #6
  br label %81

81:                                               ; preds = %80, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  br label %82

82:                                               ; preds = %81, %38, %18
  %83 = load i32, ptr %5, align 4
  ret i32 %83
}

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

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

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

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { inlinehint 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 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 #6 = { 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 = !{!12, !10, i64 4}
!12 = !{!"tcp_server_t", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !6, i64 24}
!13 = !{!12, !6, i64 16}
!14 = !{!12, !6, i64 24}
!15 = !{!12, !10, i64 8}
!16 = !{!12, !10, i64 0}
!17 = !{!18, !19, i64 0}
!18 = !{!"sockaddr_in", !19, i64 0, !19, i64 2, !20, i64 4, !7, i64 8}
!19 = !{!"short", !7, i64 0}
!20 = !{!"in_addr", !10, i64 0}
!21 = !{!18, !19, i64 2}
!22 = !{!18, !10, 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.sockaddr_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }

@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [7 x i8], align 1

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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i16 @__bswap_16(i16 noundef zeroext) local_unnamed_addr #3

declare i32 @close(i32 noundef) local_unnamed_addr #4

; Function Attrs: mustprogress 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 range(i32 -1, 1) i32 @tcp_server_init(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #5 {
  %5 = alloca i32, align 4
  %6 = alloca %struct.sockaddr_in, align 4
  %7 = icmp ne ptr %0, null
  %8 = icmp ne ptr %2, null
  %or.cond = and i1 %7, %8
  br i1 %or.cond, label %9, label %40

9:                                                ; preds = %4
  %10 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %1, ptr %10, align 4, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %2, ptr %11, align 8, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %3, ptr %12, align 8, !tbaa !12
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  store volatile i32 0, ptr %13, align 8, !tbaa !13
  %14 = tail call i32 @socket(i32 noundef 2, i32 noundef 1, i32 noundef 0) #6
  store i32 %14, ptr %0, align 8, !tbaa !14
  %15 = icmp slt i32 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %9
  tail call void @perror(ptr noundef nonnull @.str.1) #7
  br label %40

17:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #6
  store i32 1, ptr %5, align 4, !tbaa !15
  %18 = call i32 @setsockopt(i32 noundef %14, i32 noundef 1, i32 noundef 2, ptr noundef nonnull %5, i32 noundef 4) #6
  %19 = icmp slt i32 %18, 0
  br i1 %19, label %20, label %23

20:                                               ; preds = %17
  call void @perror(ptr noundef nonnull @.str.9) #7
  %21 = load i32, ptr %0, align 8, !tbaa !14
  %22 = call i32 @close(i32 noundef %21) #6
  br label %39

23:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #6
  %24 = getelementptr inbounds i8, ptr %6, i64 8
  store i64 0, ptr %24, align 4
  store i16 2, ptr %6, align 4, !tbaa !16
  %25 = trunc i32 %1 to i16
  %26 = call zeroext i16 @__bswap_16(i16 noundef zeroext %25)
  %27 = getelementptr inbounds i8, ptr %6, i64 2
  store i16 %26, ptr %27, align 2, !tbaa !20
  %28 = getelementptr inbounds i8, ptr %6, i64 4
  store i32 0, ptr %28, align 4, !tbaa !21
  %29 = load i32, ptr %0, align 8, !tbaa !14
  %30 = call i32 @bind(i32 noundef %29, ptr noundef nonnull %6, i32 noundef 16) #6
  %31 = icmp slt i32 %30, 0
  br i1 %31, label %.sink.split, label %32

32:                                               ; preds = %23
  %33 = load i32, ptr %0, align 8, !tbaa !14
  %34 = call i32 @listen(i32 noundef %33, i32 noundef 10) #6
  %35 = icmp slt i32 %34, 0
  br i1 %35, label %.sink.split, label %38

.sink.split:                                      ; preds = %32, %23
  %.str.11.sink = phi ptr [ @.str.10, %23 ], [ @.str.11, %32 ]
  call void @perror(ptr noundef nonnull %.str.11.sink) #7
  %36 = load i32, ptr %0, align 8, !tbaa !14
  %37 = call i32 @close(i32 noundef %36) #6
  br label %38

38:                                               ; preds = %.sink.split, %32
  %.0 = phi i32 [ 0, %32 ], [ -1, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #6
  br label %39

39:                                               ; preds = %38, %20
  %.1 = phi i32 [ -1, %20 ], [ %.0, %38 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #6
  br label %40

40:                                               ; preds = %4, %39, %16
  %.2 = phi i32 [ -1, %16 ], [ %.1, %39 ], [ -1, %4 ]
  ret i32 %.2
}

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

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

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 #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 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 #6 = { nounwind }
attributes #7 = { cold }

!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 4}
!6 = !{!"tcp_server_t", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!6, !10, i64 24}
!13 = !{!6, !7, i64 8}
!14 = !{!6, !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !18, i64 0}
!17 = !{!"sockaddr_in", !18, i64 0, !18, i64 2, !19, i64 4, !8, i64 8}
!18 = !{!"short", !8, i64 0}
!19 = !{!"in_addr", !7, i64 0}
!20 = !{!17, !18, i64 2}
!21 = !{!17, !7, i64 4}


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