; LLVM IR from mbheinen/bpa-ipf-tsp :: ipc (ipc_inet)

; 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.hostent = type { ptr, ptr, i32, i32, ptr }

@.str = external hidden unnamed_addr constant [52 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [57 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [41 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @connect_to_socket(ptr noundef %0, i32 noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %struct.sockaddr_in, align 4
  %11 = alloca %struct.hostent, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca [128 x i8], align 16
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #7
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #7
  call void @llvm.lifetime.start.p0(i64 32, ptr %11) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #7
  call void @llvm.lifetime.start.p0(i64 128, ptr %14) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #7
  store i32 127, ptr %15, align 4, !tbaa !9
  %17 = getelementptr inbounds [128 x i8], ptr %14, i64 0, i64 0
  store ptr %17, ptr %13, align 8, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %25

20:                                               ; preds = %3
  %21 = load ptr, ptr %13, align 8, !tbaa !5
  %22 = load i32, ptr %15, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = call i32 @gethostname(ptr noundef %21, i64 noundef %23) #7
  br label %38

25:                                               ; preds = %3
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load i8, ptr %26, align 1, !tbaa !11
  %28 = sext i8 %27 to i32
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %35

30:                                               ; preds = %25
  %31 = load ptr, ptr %13, align 8, !tbaa !5
  %32 = load i32, ptr %15, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = call i32 @gethostname(ptr noundef %31, i64 noundef %33) #7
  br label %37

35:                                               ; preds = %25
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %36, ptr %13, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %35, %30
  br label %38

38:                                               ; preds = %37, %20
  %39 = call i32 @socket(i32 noundef 2, i32 noundef 1, i32 noundef 0) #7
  store i32 %39, ptr %8, align 4, !tbaa !9
  %40 = icmp eq i32 %39, -1
  br i1 %40, label %41, label %43

41:                                               ; preds = %38
  %42 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  call void @perror(ptr noundef @.str.1)
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %16, align 4
  br label %89

43:                                               ; preds = %38
  %44 = load ptr, ptr %13, align 8, !tbaa !5
  %45 = call ptr @gethostbyname(ptr noundef %44)
  store ptr %45, ptr %12, align 8, !tbaa !5
  %46 = icmp eq ptr %45, null
  br i1 %46, label %47, label %53

47:                                               ; preds = %43
  call void @perror(ptr noundef @.str.2)
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = call i32 @close(i32 noundef %48)
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %52

51:                                               ; preds = %47
  call void @perror(ptr noundef @.str.3)
  br label %52

52:                                               ; preds = %51, %47
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %16, align 4
  br label %89

53:                                               ; preds = %43
  %54 = load ptr, ptr %12, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %11, ptr align 8 %54, i64 32, i1 false)
  call void @llvm.memset.p0.i64(ptr align 4 %10, i8 0, i64 16, i1 false)
  %55 = getelementptr inbounds %struct.hostent, ptr %11, i32 0, i32 2
  %56 = load i32, ptr %55, align 8, !tbaa !12
  %57 = trunc i32 %56 to i16
  %58 = getelementptr inbounds %struct.sockaddr_in, ptr %10, i32 0, i32 0
  store i16 %57, ptr %58, align 4, !tbaa !14
  %59 = load i32, ptr %6, align 4, !tbaa !9
  %60 = trunc i32 %59 to i16
  %61 = call zeroext i16 @__bswap_16(i16 noundef zeroext %60)
  %62 = getelementptr inbounds %struct.sockaddr_in, ptr %10, i32 0, i32 1
  store i16 %61, ptr %62, align 2, !tbaa !18
  %63 = getelementptr inbounds %struct.sockaddr_in, ptr %10, i32 0, i32 2
  %64 = getelementptr inbounds %struct.hostent, ptr %11, i32 0, i32 4
  %65 = load ptr, ptr %64, align 8, !tbaa !19
  %66 = getelementptr inbounds ptr, ptr %65, i64 0
  %67 = load ptr, ptr %66, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %63, ptr align 4 %67, i64 4, i1 false), !tbaa.struct !20
  %68 = load i32, ptr %8, align 4, !tbaa !9
  %69 = call i32 @connect(i32 noundef %68, ptr noundef %10, i32 noundef 16)
  store i32 %69, ptr %9, align 4, !tbaa !9
  %70 = icmp slt i32 %69, 0
  br i1 %70, label %71, label %83

71:                                               ; preds = %53
  %72 = load i32, ptr %9, align 4, !tbaa !9
  %73 = getelementptr inbounds %struct.sockaddr_in, ptr %10, i32 0, i32 1
  %74 = load i16, ptr %73, align 2, !tbaa !18
  %75 = call zeroext i16 @__bswap_16(i16 noundef zeroext %74)
  %76 = zext i16 %75 to i32
  %77 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %72, i32 noundef %76)
  call void @perror(ptr noundef @.str.5)
  %78 = load i32, ptr %8, align 4, !tbaa !9
  %79 = call i32 @close(i32 noundef %78)
  %80 = icmp ne i32 %79, 0
  br i1 %80, label %81, label %82

81:                                               ; preds = %71
  call void @perror(ptr noundef @.str.3)
  br label %82

82:                                               ; preds = %81, %71
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %16, align 4
  br label %89

83:                                               ; preds = %53
  %84 = load i32, ptr %9, align 4, !tbaa !9
  %85 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, i32 noundef %84)
  %86 = load i32, ptr %8, align 4, !tbaa !9
  %87 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %86, ptr %87, align 4, !tbaa !9
  %88 = load i32, ptr %8, align 4, !tbaa !9
  call void @ipc_inet_socket_setup(i32 noundef %88)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %16, align 4
  br label %89

89:                                               ; preds = %83, %82, %52, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #7
  call void @llvm.lifetime.end.p0(i64 128, ptr %14) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #7
  call void @llvm.lifetime.end.p0(i64 32, ptr %11) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  %90 = load i32, ptr %4, align 4
  ret i32 %90
}

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

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

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

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

declare void @perror(ptr noundef) #3

declare ptr @gethostbyname(ptr noundef) #3

declare i32 @close(i32 noundef) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

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

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

declare i32 @connect(i32 noundef, ptr noundef, i32 noundef) #3

declare void @ipc_inet_socket_setup(i32 noundef) #3

; 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 = { 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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { 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 #7 = { 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 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 16}
!13 = !{!"hostent", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !6, i64 24}
!14 = !{!15, !16, i64 0}
!15 = !{!"sockaddr_in", !16, i64 0, !16, i64 2, !17, i64 4, !7, i64 8}
!16 = !{!"short", !7, i64 0}
!17 = !{!"in_addr", !10, i64 0}
!18 = !{!15, !16, i64 2}
!19 = !{!13, !6, i64 24}
!20 = !{i64 0, i64 4, !9}


; 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 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [57 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [41 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @connect_to_socket(ptr noundef %0, i32 noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = alloca %struct.sockaddr_in, align 4
  %5 = alloca [128 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #6
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %5) #6
  %6 = icmp eq ptr %0, null
  br i1 %6, label %.sink.split, label %7

7:                                                ; preds = %3
  %8 = load i8, ptr %0, align 1, !tbaa !5
  %9 = icmp eq i8 %8, 0
  br i1 %9, label %.sink.split, label %11

.sink.split:                                      ; preds = %7, %3
  %10 = call i32 @gethostname(ptr noundef nonnull %5, i64 noundef 127) #6
  br label %11

11:                                               ; preds = %.sink.split, %7
  %.019 = phi ptr [ %0, %7 ], [ %5, %.sink.split ]
  %12 = call i32 @socket(i32 noundef 2, i32 noundef 1, i32 noundef 0) #6
  %13 = icmp eq i32 %12, -1
  br i1 %13, label %14, label %16

14:                                               ; preds = %11
  %15 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  call void @perror(ptr noundef nonnull @.str.1) #7
  br label %42

16:                                               ; preds = %11
  %17 = call ptr @gethostbyname(ptr noundef nonnull %.019) #6
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %22

19:                                               ; preds = %16
  call void @perror(ptr noundef nonnull @.str.2) #7
  %20 = call i32 @close(i32 noundef %12) #6
  %.not24 = icmp eq i32 %20, 0
  br i1 %.not24, label %42, label %21

21:                                               ; preds = %19
  call void @perror(ptr noundef nonnull @.str.3) #7
  br label %42

22:                                               ; preds = %16
  %.sroa.3.0..0.4.sroa_idx = getelementptr inbounds i8, ptr %17, i64 16
  %.sroa.3.0.copyload = load i32, ptr %.sroa.3.0..0.4.sroa_idx, align 8
  %.sroa.45.0..0.4.sroa_idx = getelementptr inbounds i8, ptr %17, i64 24
  %.sroa.45.0.copyload = load ptr, ptr %.sroa.45.0..0.4.sroa_idx, align 8
  %23 = getelementptr inbounds i8, ptr %4, i64 8
  store i64 0, ptr %23, align 4
  %24 = trunc i32 %.sroa.3.0.copyload to i16
  store i16 %24, ptr %4, align 4, !tbaa !8
  %25 = trunc i32 %1 to i16
  %26 = call zeroext i16 @__bswap_16(i16 noundef zeroext %25)
  %27 = getelementptr inbounds i8, ptr %4, i64 2
  store i16 %26, ptr %27, align 2, !tbaa !13
  %28 = getelementptr inbounds i8, ptr %4, i64 4
  %29 = load ptr, ptr %.sroa.45.0.copyload, align 8, !tbaa !14
  %30 = load i32, ptr %29, align 4, !tbaa !16
  store i32 %30, ptr %28, align 4, !tbaa !16
  %31 = call i32 @connect(i32 noundef %12, ptr noundef nonnull %4, i32 noundef 16) #6
  %32 = icmp slt i32 %31, 0
  br i1 %32, label %33, label %40

33:                                               ; preds = %22
  %34 = load i16, ptr %27, align 2, !tbaa !13
  %35 = call zeroext i16 @__bswap_16(i16 noundef zeroext %34)
  %36 = zext i16 %35 to i32
  %37 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %31, i32 noundef %36)
  call void @perror(ptr noundef nonnull @.str.5) #7
  %38 = call i32 @close(i32 noundef %12) #6
  %.not = icmp eq i32 %38, 0
  br i1 %.not, label %42, label %39

39:                                               ; preds = %33
  call void @perror(ptr noundef nonnull @.str.3) #7
  br label %42

40:                                               ; preds = %22
  %41 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, i32 noundef %31)
  store i32 %12, ptr %2, align 4, !tbaa !16
  call void @ipc_inet_socket_setup(i32 noundef %12) #6
  br label %42

42:                                               ; preds = %33, %39, %19, %21, %40, %14
  %.0 = phi i32 [ -1, %14 ], [ 0, %40 ], [ -1, %21 ], [ -1, %19 ], [ -1, %39 ], [ -1, %33 ]
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %5) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #6
  ret i32 %.0
}

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

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

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

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

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

declare ptr @gethostbyname(ptr noundef) local_unnamed_addr #4

declare i32 @close(i32 noundef) local_unnamed_addr #4

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

declare i32 @connect(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #4

declare void @ipc_inet_socket_setup(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) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 0}
!9 = !{!"sockaddr_in", !10, i64 0, !10, i64 2, !11, i64 4, !6, i64 8}
!10 = !{!"short", !6, i64 0}
!11 = !{!"in_addr", !12, i64 0}
!12 = !{!"int", !6, i64 0}
!13 = !{!9, !10, i64 2}
!14 = !{!15, !15, i64 0}
!15 = !{!"any pointer", !6, i64 0}
!16 = !{!12, !12, i64 0}


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