; 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] }

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

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

; Function Attrs: nounwind
declare i32 @sem_post(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @CloseLinuxTCPClient(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.ProcessingUnitStructure, ptr %4, i32 0, i32 0
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %6, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.ProcessingUnitStructureTCP, ptr %7, i32 0, i32 11
  store i8 1, ptr %8, align 8, !tbaa !11
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.ProcessingUnitStructureTCP, ptr %9, i32 0, i32 8
  %11 = call i32 @sem_post(ptr noundef %10) #4
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.ProcessingUnitStructureTCP, ptr %12, i32 0, i32 7
  %14 = call i32 @sem_post(ptr noundef %13) #4
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ProcessingUnitStructureTCP, ptr %15, i32 0, i32 3
  %17 = load i8, ptr %16, align 8, !tbaa !19, !range !20, !noundef !21
  %18 = trunc i8 %17 to i1
  br i1 %18, label %19, label %26

19:                                               ; preds = %1
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.ProcessingUnitStructureTCP, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !22
  %23 = call i32 @close(i32 noundef %22)
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.ProcessingUnitStructureTCP, ptr %24, i32 0, i32 3
  store i8 0, ptr %25, align 8, !tbaa !19
  br label %26

26:                                               ; preds = %19, %1
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.ProcessingUnitStructureTCP, ptr %27, i32 0, i32 6
  %29 = load i64, ptr %28, align 8, !tbaa !23
  %30 = call i32 @pthread_join(i64 noundef %29, ptr noundef null)
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ProcessingUnitStructureTCP, ptr %31, i32 0, i32 7
  %33 = call i32 @sem_destroy(ptr noundef %32) #4
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ProcessingUnitStructureTCP, ptr %34, i32 0, i32 8
  %36 = call i32 @sem_destroy(ptr noundef %35) #4
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %37) #4
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  call void @free(ptr noundef %38) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

declare i32 @close(i32 noundef) #3

declare i32 @pthread_join(i64 noundef, ptr noundef) #3

; Function Attrs: nounwind
declare i32 @sem_destroy(ptr noundef) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 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 #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 = { 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, !6, i64 0}
!10 = !{!"ProcessingUnitStructure", !6, i64 0}
!11 = !{!12, !17, i64 120}
!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, !17, i64 24}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!12, !13, i64 0}
!23 = !{!12, !18, i64 32}


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

; Function Attrs: nounwind
declare i32 @sem_post(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @CloseLinuxTCPClient(ptr nocapture noundef %0) local_unnamed_addr #1 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 120
  store i8 1, ptr %3, align 8, !tbaa !10
  %4 = getelementptr inbounds i8, ptr %2, i64 72
  %5 = tail call i32 @sem_post(ptr noundef nonnull %4) #4
  %6 = getelementptr inbounds i8, ptr %2, i64 40
  %7 = tail call i32 @sem_post(ptr noundef nonnull %6) #4
  %8 = getelementptr inbounds i8, ptr %2, i64 24
  %9 = load i8, ptr %8, align 8, !tbaa !18, !range !19, !noundef !20
  %10 = trunc nuw i8 %9 to i1
  br i1 %10, label %11, label %14

11:                                               ; preds = %1
  %12 = load i32, ptr %2, align 8, !tbaa !21
  %13 = tail call i32 @close(i32 noundef %12) #4
  store i8 0, ptr %8, align 8, !tbaa !18
  br label %14

14:                                               ; preds = %11, %1
  %15 = getelementptr inbounds i8, ptr %2, i64 32
  %16 = load i64, ptr %15, align 8, !tbaa !22
  %17 = tail call i32 @pthread_join(i64 noundef %16, ptr noundef null) #4
  %18 = tail call i32 @sem_destroy(ptr noundef nonnull %6) #4
  %19 = tail call i32 @sem_destroy(ptr noundef nonnull %4) #4
  tail call void @free(ptr noundef nonnull %0) #4
  tail call void @free(ptr noundef nonnull %2) #4
  ret void
}

declare i32 @close(i32 noundef) local_unnamed_addr #2

declare i32 @pthread_join(i64 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare i32 @sem_destroy(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

attributes #0 = { 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 #1 = { 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 #2 = { "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 nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #4 = { 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, !7, i64 0}
!6 = !{!"ProcessingUnitStructure", !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !16, i64 120}
!11 = !{!"ProcessingUnitStructureTCP", !12, i64 0, !13, i64 4, !12, i64 20, !16, i64 24, !16, i64 25, !16, i64 26, !17, i64 32, !8, i64 40, !8, i64 72, !7, i64 104, !17, i64 112, !16, i64 120}
!12 = !{!"int", !8, i64 0}
!13 = !{!"sockaddr_in", !14, i64 0, !14, i64 2, !15, i64 4, !8, i64 8}
!14 = !{!"short", !8, i64 0}
!15 = !{!"in_addr", !12, i64 0}
!16 = !{!"_Bool", !8, i64 0}
!17 = !{!"long", !8, i64 0}
!18 = !{!11, !16, i64 24}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!11, !12, i64 0}
!22 = !{!11, !17, i64 32}


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