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

; 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.ProcessingUnitServerStructure = type { ptr }
%struct.ProcessingUnitServerStructureTCP = type { i32, i32, %struct.sockaddr_in, %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

declare i32 @close(i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @CloseLinuxTCPServer(ptr noundef %0) #3 {
  %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.ProcessingUnitServerStructure, 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.ProcessingUnitServerStructureTCP, ptr %7, i32 0, i32 13
  store i8 1, ptr %8, align 8, !tbaa !11
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.ProcessingUnitServerStructureTCP, ptr %9, i32 0, i32 10
  %11 = call i32 @sem_post(ptr noundef %10) #4
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.ProcessingUnitServerStructureTCP, ptr %12, i32 0, i32 9
  %14 = call i32 @sem_post(ptr noundef %13) #4
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ProcessingUnitServerStructureTCP, ptr %15, i32 0, i32 5
  %17 = load i8, ptr %16, align 4, !tbaa !19, !range !20, !noundef !21
  %18 = trunc i8 %17 to i1
  br i1 %18, label %19, label %24

19:                                               ; preds = %1
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.ProcessingUnitServerStructureTCP, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !22
  %23 = call i32 @shutdown(i32 noundef %22, i32 noundef 2) #4
  br label %24

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

; Function Attrs: nounwind
declare i32 @shutdown(i32 noundef, i32 noundef) #1

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

; 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 = { "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 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 = { 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 = !{!"ProcessingUnitServerStructure", !6, i64 0}
!11 = !{!12, !17, i64 136}
!12 = !{!"ProcessingUnitServerStructureTCP", !13, i64 0, !13, i64 4, !14, i64 8, !14, i64 24, !13, i64 40, !17, i64 44, !17, i64 45, !17, i64 46, !18, i64 48, !7, i64 56, !7, i64 88, !6, i64 120, !18, i64 128, !17, i64 136}
!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 44}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!12, !13, i64 4}
!23 = !{!12, !13, i64 0}
!24 = !{!12, !18, i64 48}


; 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

declare i32 @close(i32 noundef) local_unnamed_addr #1

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

11:                                               ; preds = %1
  %12 = getelementptr inbounds i8, ptr %2, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !21
  %14 = tail call i32 @shutdown(i32 noundef %13, i32 noundef 2) #4
  br label %15

15:                                               ; preds = %11, %1
  %16 = load i32, ptr %2, align 8, !tbaa !22
  %17 = tail call i32 @close(i32 noundef %16) #4
  %18 = getelementptr inbounds i8, ptr %2, i64 48
  %19 = load i64, ptr %18, align 8, !tbaa !23
  %20 = tail call i32 @pthread_join(i64 noundef %19, ptr noundef null) #4
  %21 = tail call i32 @sem_destroy(ptr noundef nonnull %6) #4
  %22 = 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
}

; Function Attrs: nounwind
declare i32 @shutdown(i32 noundef, i32 noundef) local_unnamed_addr #0

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

; 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 = { "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 = { 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 = !{!"ProcessingUnitServerStructure", !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !16, i64 136}
!11 = !{!"ProcessingUnitServerStructureTCP", !12, i64 0, !12, i64 4, !13, i64 8, !13, i64 24, !12, i64 40, !16, i64 44, !16, i64 45, !16, i64 46, !17, i64 48, !8, i64 56, !8, i64 88, !7, i64 120, !17, i64 128, !16, i64 136}
!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 44}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!11, !12, i64 4}
!22 = !{!11, !12, i64 0}
!23 = !{!11, !17, i64 48}


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