; LLVM IR from InductiveComputerScience/infracore :: drivers/pu-linux-tcp (pu-linux-tcp-client)

; 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.ProcessingUnitStructure = type { ptr }
%struct.ProcessingUnitStructureTCP = type { i32, %struct.sockaddr_in, i32, i8, i8, i8, i64, %union.sem_t, %union.sem_t, ptr, i64, i8 }
%struct.sockaddr_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }
%union.sem_t = type { i64, [24 x i8] }

@.str = external hidden unnamed_addr constant [31 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [24 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @CreateLinuxTCPClient(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #8
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #8
  %10 = call noalias ptr @malloc(i64 noundef 8) #9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %10, ptr %11, align 8, !tbaa !5
  %12 = call noalias ptr @malloc(i64 noundef 128) #9
  store ptr %12, ptr %7, align 8, !tbaa !5
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ProcessingUnitStructure, ptr %15, i32 0, i32 0
  store ptr %13, ptr %16, align 8, !tbaa !11
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.ProcessingUnitStructureTCP, ptr %17, i32 0, i32 7
  %19 = call i32 @sem_init(ptr noundef %18, i32 noundef 0, i32 noundef 0) #8
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.ProcessingUnitStructureTCP, ptr %20, i32 0, i32 8
  %22 = call i32 @sem_init(ptr noundef %21, i32 noundef 0, i32 noundef 0) #8
  %23 = call i32 @socket(i32 noundef 2, i32 noundef 1, i32 noundef 0) #8
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.ProcessingUnitStructureTCP, ptr %24, i32 0, i32 0
  store i32 %23, ptr %25, align 8, !tbaa !13
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.ProcessingUnitStructureTCP, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 8, !tbaa !13
  %29 = icmp ne i32 %28, -1
  br i1 %29, label %30, label %71

30:                                               ; preds = %3
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ProcessingUnitStructureTCP, ptr %31, i32 0, i32 1
  call void @llvm.memset.p0.i64(ptr align 4 %32, i8 0, i64 16, i1 false)
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.ProcessingUnitStructureTCP, ptr %33, i32 0, i32 1
  %35 = getelementptr inbounds %struct.sockaddr_in, ptr %34, i32 0, i32 0
  store i16 2, ptr %35, align 4, !tbaa !20
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = call i32 @inet_addr(ptr noundef %36) #8
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ProcessingUnitStructureTCP, ptr %38, i32 0, i32 1
  %40 = getelementptr inbounds %struct.sockaddr_in, ptr %39, i32 0, i32 2
  %41 = getelementptr inbounds %struct.in_addr, ptr %40, i32 0, i32 0
  store i32 %37, ptr %41, align 4, !tbaa !21
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = trunc i32 %42 to i16
  %44 = call zeroext i16 @__bswap_16(i16 noundef zeroext %43)
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.ProcessingUnitStructureTCP, ptr %45, i32 0, i32 1
  %47 = getelementptr inbounds %struct.sockaddr_in, ptr %46, i32 0, i32 1
  store i16 %44, ptr %47, align 2, !tbaa !22
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.ProcessingUnitStructureTCP, ptr %48, i32 0, i32 2
  store i32 16, ptr %49, align 4, !tbaa !23
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.ProcessingUnitStructureTCP, ptr %50, i32 0, i32 3
  store i8 0, ptr %51, align 8, !tbaa !24
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.ProcessingUnitStructureTCP, ptr %52, i32 0, i32 4
  store i8 0, ptr %53, align 1, !tbaa !25
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.ProcessingUnitStructureTCP, ptr %54, i32 0, i32 5
  store i8 0, ptr %55, align 2, !tbaa !26
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.ProcessingUnitStructureTCP, ptr %56, i32 0, i32 6
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = call i32 @pthread_create(ptr noundef %57, ptr noundef null, ptr noundef @ClientThread, ptr noundef %58) #8
  store i32 %59, ptr %9, align 4, !tbaa !9
  %60 = load i32, ptr %9, align 4, !tbaa !9
  %61 = icmp eq i32 %60, 0
  br i1 %61, label %62, label %63

62:                                               ; preds = %30
  store i8 1, ptr %8, align 1, !tbaa !27
  br label %70

63:                                               ; preds = %30
  %64 = call ptr @__errno_location() #10
  %65 = load i32, ptr %64, align 4, !tbaa !9
  %66 = call ptr @__errno_location() #10
  %67 = load i32, ptr %66, align 4, !tbaa !9
  %68 = call ptr @strerror(i32 noundef %67) #8
  %69 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %65, ptr noundef %68)
  store i8 0, ptr %8, align 1, !tbaa !27
  br label %70

70:                                               ; preds = %63, %62
  br label %78

71:                                               ; preds = %3
  store i8 0, ptr %8, align 1, !tbaa !27
  %72 = call ptr @__errno_location() #10
  %73 = load i32, ptr %72, align 4, !tbaa !9
  %74 = call ptr @__errno_location() #10
  %75 = load i32, ptr %74, align 4, !tbaa !9
  %76 = call ptr @strerror(i32 noundef %75) #8
  %77 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %73, ptr noundef %76)
  br label %78

78:                                               ; preds = %71, %70
  %79 = load i8, ptr %8, align 1, !tbaa !27, !range !28, !noundef !29
  %80 = trunc i8 %79 to i1
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #8
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #8
  ret i1 %80
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @ClientThread(ptr noundef) #0

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

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

; Function Attrs: nounwind
declare ptr @strerror(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 allocsize(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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { "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 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 #8 = { nounwind }
attributes #9 = { nounwind allocsize(0) }
attributes #10 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"ProcessingUnitStructure", !6, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"ProcessingUnitStructureTCP", !10, i64 0, !15, i64 4, !10, i64 20, !18, i64 24, !18, i64 25, !18, i64 26, !19, i64 32, !7, i64 40, !7, i64 72, !6, i64 104, !19, i64 112, !18, i64 120}
!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 = !{!"_Bool", !7, i64 0}
!19 = !{!"long", !7, i64 0}
!20 = !{!14, !16, i64 4}
!21 = !{!14, !10, i64 8}
!22 = !{!14, !16, i64 6}
!23 = !{!14, !10, i64 20}
!24 = !{!14, !18, i64 24}
!25 = !{!14, !18, i64 25}
!26 = !{!14, !18, i64 26}
!27 = !{!18, !18, i64 0}
!28 = !{i8 0, i8 2}
!29 = !{}


; 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 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [24 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @CreateLinuxTCPClient(ptr nocapture noundef writeonly %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = tail call noalias dereferenceable_or_null(8) ptr @malloc(i64 noundef 8) #7
  store ptr %4, ptr %0, align 8, !tbaa !5
  %5 = tail call noalias dereferenceable_or_null(128) ptr @malloc(i64 noundef 128) #7
  store ptr %5, ptr %4, align 8, !tbaa !9
  %6 = getelementptr inbounds i8, ptr %5, i64 40
  %7 = tail call i32 @sem_init(ptr noundef nonnull %6, i32 noundef 0, i32 noundef 0) #8
  %8 = getelementptr inbounds i8, ptr %5, i64 72
  %9 = tail call i32 @sem_init(ptr noundef nonnull %8, i32 noundef 0, i32 noundef 0) #8
  %10 = tail call i32 @socket(i32 noundef 2, i32 noundef 1, i32 noundef 0) #8
  store i32 %10, ptr %5, align 8, !tbaa !11
  %.not = icmp eq i32 %10, -1
  br i1 %.not, label %.sink.split, label %11

11:                                               ; preds = %3
  %12 = getelementptr inbounds i8, ptr %5, i64 4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %12, i8 0, i64 16, i1 false)
  store i16 2, ptr %12, align 4, !tbaa !19
  %13 = tail call i32 @inet_addr(ptr noundef %1) #8
  %14 = getelementptr inbounds i8, ptr %5, i64 8
  store i32 %13, ptr %14, align 4, !tbaa !20
  %15 = trunc i32 %2 to i16
  %16 = tail call zeroext i16 @__bswap_16(i16 noundef zeroext %15)
  %17 = getelementptr inbounds i8, ptr %5, i64 6
  store i16 %16, ptr %17, align 2, !tbaa !21
  %18 = getelementptr inbounds i8, ptr %5, i64 20
  store i32 16, ptr %18, align 4, !tbaa !22
  %19 = getelementptr inbounds i8, ptr %5, i64 24
  store i8 0, ptr %19, align 8, !tbaa !23
  %20 = getelementptr inbounds i8, ptr %5, i64 25
  store i8 0, ptr %20, align 1, !tbaa !24
  %21 = getelementptr inbounds i8, ptr %5, i64 26
  store i8 0, ptr %21, align 2, !tbaa !25
  %22 = getelementptr inbounds i8, ptr %5, i64 32
  %23 = tail call i32 @pthread_create(ptr noundef nonnull %22, ptr noundef null, ptr noundef nonnull @ClientThread, ptr noundef nonnull %5) #8
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %29, label %.sink.split

.sink.split:                                      ; preds = %3, %11
  %.str.sink = phi ptr [ @.str, %11 ], [ @.str.1, %3 ]
  %25 = tail call ptr @__errno_location() #9
  %26 = load i32, ptr %25, align 4, !tbaa !26
  %27 = tail call ptr @strerror(i32 noundef %26) #8
  %28 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.sink, i32 noundef %26, ptr noundef %27)
  br label %29

29:                                               ; preds = %.sink.split, %11
  %.0 = phi i1 [ true, %11 ], [ false, %.sink.split ]
  ret i1 %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @ClientThread(ptr noundef) #0

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

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

; Function Attrs: nounwind
declare ptr @strerror(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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress 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 = { 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 #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 allocsize(0) }
attributes #8 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"ProcessingUnitStructure", !6, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"ProcessingUnitStructureTCP", !13, i64 0, !14, i64 4, !13, i64 20, !17, i64 24, !17, i64 25, !17, i64 26, !18, i64 32, !7, i64 40, !7, i64 72, !6, i64 104, !18, i64 112, !17, i64 120}
!13 = !{!"int", !7, i64 0}
!14 = !{!"sockaddr_in", !15, i64 0, !15, i64 2, !16, i64 4, !7, i64 8}
!15 = !{!"short", !7, i64 0}
!16 = !{!"in_addr", !13, i64 0}
!17 = !{!"_Bool", !7, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{!12, !15, i64 4}
!20 = !{!12, !13, i64 8}
!21 = !{!12, !15, i64 6}
!22 = !{!12, !13, i64 20}
!23 = !{!12, !17, i64 24}
!24 = !{!12, !17, i64 25}
!25 = !{!12, !17, i64 26}
!26 = !{!13, !13, i64 0}


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