; LLVM IR from dennisss/tansa :: src/server/osc.ll (Z10osc_threadPv)

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

@.str.5 = external hidden unnamed_addr constant [29 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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z10osc_threadPv(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca [1 x %struct.pollfd], align 4
  %7 = alloca i32, align 4
  %8 = alloca %struct.sockaddr_in, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %11, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %12 = call noalias ptr @malloc(i64 noundef 512) #5
  store ptr %12, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 1, ptr %7, align 4, !tbaa !9
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %class.OSC, ptr %13, i32 0, i32 1
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = getelementptr inbounds [1 x %struct.pollfd], ptr %6, i64 0, i64 0
  %17 = getelementptr inbounds %struct.pollfd, ptr %16, i32 0, i32 0
  store i32 %15, ptr %17, align 4, !tbaa !18
  %18 = getelementptr inbounds [1 x %struct.pollfd], ptr %6, i64 0, i64 0
  %19 = getelementptr inbounds %struct.pollfd, ptr %18, i32 0, i32 1
  store i16 1, ptr %19, align 4, !tbaa !20
  %20 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  br label %21

21:                                               ; preds = %60, %1
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %class.OSC, ptr %22, i32 0, i32 0
  %24 = load i8, ptr %23, align 8, !tbaa !21, !range !22, !noundef !23
  %25 = trunc i8 %24 to i1
  br i1 %25, label %26, label %61

26:                                               ; preds = %21
  %27 = getelementptr inbounds [1 x %struct.pollfd], ptr %6, i64 0, i64 0
  %28 = load i32, ptr %7, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = call i32 @poll(ptr noundef %27, i64 noundef %29, i32 noundef 500)
  store i32 %30, ptr %4, align 4, !tbaa !9
  %31 = load i32, ptr %4, align 4, !tbaa !9
  %32 = icmp slt i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %26
  br label %60

34:                                               ; preds = %26
  %35 = load i32, ptr %4, align 4, !tbaa !9
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %34
  br label %59

38:                                               ; preds = %34
  %39 = getelementptr inbounds [1 x %struct.pollfd], ptr %6, i64 0, i64 0
  %40 = getelementptr inbounds %struct.pollfd, ptr %39, i32 0, i32 2
  %41 = load i16, ptr %40, align 2, !tbaa !24
  %42 = sext i16 %41 to i32
  %43 = and i32 %42, 1
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %58

45:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 16, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %class.OSC, ptr %46, i32 0, i32 1
  %48 = load i32, ptr %47, align 4, !tbaa !11
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = call i64 @recvfrom(i32 noundef %48, ptr noundef %49, i64 noundef 512, i32 noundef 0, ptr noundef %8, ptr noundef %9)
  %51 = trunc i64 %50 to i32
  store i32 %51, ptr %10, align 4, !tbaa !9
  %52 = load i32, ptr %10, align 4, !tbaa !9
  %53 = icmp sgt i32 %52, 0
  br i1 %53, label %54, label %57

54:                                               ; preds = %45
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN3OSC15process_messageEPc(ptr noundef nonnull align 8 dereferenceable(56) %55, ptr noundef %56)
  br label %57

57:                                               ; preds = %54, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #4
  br label %58

58:                                               ; preds = %57, %38
  br label %59

59:                                               ; preds = %58, %37
  br label %60

60:                                               ; preds = %59, %33
  br label %21, !llvm.loop !25

61:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret ptr null
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3OSC15process_messageEPc(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef) #1 align 2

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

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

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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 = { "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 }
attributes #5 = { nounwind allocsize(0) }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"_ZTS3OSC", !13, i64 0, !10, i64 4, !14, i64 8, !15, i64 16, !15, i64 32, !6, i64 48}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"_ZTS11sockaddr_in", !16, i64 0, !16, i64 2, !17, i64 4, !7, i64 8}
!16 = !{!"short", !7, i64 0}
!17 = !{!"_ZTS7in_addr", !10, i64 0}
!18 = !{!19, !10, i64 0}
!19 = !{!"_ZTS6pollfd", !10, i64 0, !16, i64 4, !16, i64 6}
!20 = !{!19, !16, i64 4}
!21 = !{!12, !13, i64 0}
!22 = !{i8 0, i8 2}
!23 = !{}
!24 = !{!19, !16, i64 6}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}


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

@.str.5 = external hidden unnamed_addr constant [29 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: mustprogress uwtable
define dso_local noalias noundef ptr @_Z10osc_threadPv(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca [1 x %struct.pollfd], align 4
  %3 = alloca %struct.sockaddr_in, align 4
  %4 = alloca i32, align 4
  %5 = tail call noalias dereferenceable_or_null(512) ptr @malloc(i64 noundef 512) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #6
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %7, ptr %2, align 4, !tbaa !16
  %8 = getelementptr inbounds i8, ptr %2, i64 4
  store i16 1, ptr %8, align 4, !tbaa !18
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  %10 = load i8, ptr %0, align 8, !tbaa !19, !range !20, !noundef !21
  %11 = trunc nuw i8 %10 to i1
  br i1 %11, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %12 = getelementptr inbounds i8, ptr %2, i64 6
  br label %13

13:                                               ; preds = %.lr.ph, %25
  %14 = call i32 @poll(ptr noundef nonnull %2, i64 noundef 1, i32 noundef 500)
  %or.cond = icmp slt i32 %14, 1
  br i1 %or.cond, label %25, label %15

15:                                               ; preds = %13
  %16 = load i16, ptr %12, align 2, !tbaa !22
  %17 = and i16 %16, 1
  %.not = icmp eq i16 %17, 0
  br i1 %.not, label %25, label %18

18:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #6
  store i32 16, ptr %4, align 4, !tbaa !23
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = call i64 @recvfrom(i32 noundef %19, ptr noundef %5, i64 noundef 512, i32 noundef 0, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %21 = trunc i64 %20 to i32
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %18
  call void @_ZN3OSC15process_messageEPc(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef %5)
  br label %24

24:                                               ; preds = %23, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #6
  br label %25

25:                                               ; preds = %24, %15, %13
  %26 = load i8, ptr %0, align 8, !tbaa !19, !range !20, !noundef !21
  %27 = trunc nuw i8 %26 to i1
  br i1 %27, label %13, label %._crit_edge, !llvm.loop !24

._crit_edge:                                      ; preds = %25, %1
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #6
  ret ptr null
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3OSC15process_messageEPc(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef) local_unnamed_addr #1 align 2

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

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

declare i32 @poll(ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #4

declare i64 @recvfrom(i32 noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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 #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 = { nounwind allocsize(0) }
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, !10, i64 4}
!6 = !{!"_ZTS3OSC", !7, i64 0, !10, i64 4, !11, i64 8, !12, i64 16, !12, i64 32, !15, i64 48}
!7 = !{!"bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"_ZTS11sockaddr_in", !13, i64 0, !13, i64 2, !14, i64 4, !8, i64 8}
!13 = !{!"short", !8, i64 0}
!14 = !{!"_ZTS7in_addr", !10, i64 0}
!15 = !{!"any pointer", !8, i64 0}
!16 = !{!17, !10, i64 0}
!17 = !{!"_ZTS6pollfd", !10, i64 0, !13, i64 4, !13, i64 6}
!18 = !{!17, !13, i64 4}
!19 = !{!6, !7, i64 0}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!17, !13, i64 6}
!23 = !{!10, !10, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass