; LLVM IR from dennisss/tansa :: src/mocap/optitrack (natnet_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.ifaddrs = type { ptr, ptr, i32, ptr, ptr, %union.anon, ptr }
%union.anon = type { ptr }
%struct.sockaddr = type { i16, [14 x i8] }
%struct.sockaddr_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }
%"struct.tansa::optitrack::interface" = type { %struct.sockaddr_in, %struct.sockaddr_in }

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; 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
define dso_local noundef zeroext i1 @_ZN5tansa9optitrack10find_ifaceEP11sockaddr_inPNS0_9interfaceE(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #5
  store i8 0, ptr %8, align 1, !tbaa !9
  %11 = call i32 @getifaddrs(ptr noundef %5) #5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %12, ptr %6, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %68, %2
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %72

16:                                               ; preds = %13
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.ifaddrs, ptr %17, i32 0, i32 3
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = getelementptr inbounds %struct.sockaddr, ptr %19, i32 0, i32 0
  %21 = load i16, ptr %20, align 2, !tbaa !14
  %22 = zext i16 %21 to i32
  %23 = icmp eq i32 %22, 2
  br i1 %23, label %24, label %67

24:                                               ; preds = %16
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.ifaddrs, ptr %25, i32 0, i32 3
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  store ptr %27, ptr %7, align 8, !tbaa !5
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.sockaddr_in, ptr %28, i32 0, i32 2
  %30 = getelementptr inbounds %struct.in_addr, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 4, !tbaa !17
  %32 = call noundef i32 @_ZL10__bswap_32j(i32 noundef 2130706433)
  %33 = icmp eq i32 %31, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %24
  br label %68

35:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.ifaddrs, ptr %36, i32 0, i32 4
  %38 = getelementptr inbounds %struct.sockaddr_in, ptr %37, i32 0, i32 2
  %39 = getelementptr inbounds %struct.in_addr, ptr %38, i32 0, i32 0
  %40 = load i32, ptr %39, align 4, !tbaa !17
  store i32 %40, ptr %9, align 4, !tbaa !20
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.sockaddr_in, ptr %41, i32 0, i32 2
  %43 = getelementptr inbounds %struct.in_addr, ptr %42, i32 0, i32 0
  %44 = load i32, ptr %43, align 4, !tbaa !17
  %45 = load i32, ptr %9, align 4, !tbaa !20
  %46 = and i32 %44, %45
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.sockaddr_in, ptr %47, i32 0, i32 2
  %49 = getelementptr inbounds %struct.in_addr, ptr %48, i32 0, i32 0
  %50 = load i32, ptr %49, align 4, !tbaa !17
  %51 = load i32, ptr %9, align 4, !tbaa !20
  %52 = and i32 %50, %51
  %53 = icmp eq i32 %46, %52
  br i1 %53, label %54, label %63

54:                                               ; preds = %35
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %"struct.tansa::optitrack::interface", ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %56, ptr align 4 %57, i64 16, i1 false)
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %"struct.tansa::optitrack::interface", ptr %58, i32 0, i32 1
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.ifaddrs, ptr %60, i32 0, i32 5
  %62 = load ptr, ptr %61, align 8, !tbaa !21
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %59, ptr align 2 %62, i64 16, i1 false)
  store i8 1, ptr %8, align 1, !tbaa !9
  store i32 2, ptr %10, align 4
  br label %64

63:                                               ; preds = %35
  store i32 0, ptr %10, align 4
  br label %64

64:                                               ; preds = %63, %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  %65 = load i32, ptr %10, align 4
  switch i32 %65, label %76 [
    i32 0, label %66
    i32 2, label %72
  ]

66:                                               ; preds = %64
  br label %67

67:                                               ; preds = %66, %16
  br label %68

68:                                               ; preds = %67, %34
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.ifaddrs, ptr %69, i32 0, i32 0
  %71 = load ptr, ptr %70, align 8, !tbaa !22
  store ptr %71, ptr %6, align 8, !tbaa !5
  br label %13, !llvm.loop !23

72:                                               ; preds = %64, %13
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  call void @freeifaddrs(ptr noundef %73) #5
  %74 = load i8, ptr %8, align 1, !tbaa !9, !range !25, !noundef !26
  %75 = trunc i8 %74 to i1
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret i1 %75

76:                                               ; preds = %64
  unreachable
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL10__bswap_32j(i32 noundef) #4

; Function Attrs: nounwind
declare void @freeifaddrs(ptr noundef) #3

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


; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress 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) #1

; 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 nounwind uwtable
define dso_local noundef zeroext i1 @_ZN5tansa9optitrack10find_ifaceEP11sockaddr_inPNS0_9interfaceE(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #2 {
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  %4 = call i32 @getifaddrs(ptr noundef nonnull %3) #5
  %.01523 = load ptr, ptr %3, align 8, !tbaa !5
  %.not24.not = icmp eq ptr %.01523, null
  br i1 %.not24.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  br label %6

6:                                                ; preds = %.lr.ph, %.thread
  %.01525 = phi ptr [ %.01523, %.lr.ph ], [ %.015, %.thread ]
  %7 = getelementptr inbounds i8, ptr %.01525, i64 24
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = load i16, ptr %8, align 2, !tbaa !12
  %10 = icmp eq i16 %9, 2
  br i1 %10, label %11, label %.thread

11:                                               ; preds = %6
  %12 = getelementptr inbounds i8, ptr %8, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !15
  %14 = call noundef i32 @_ZL10__bswap_32j(i32 noundef 2130706433)
  %15 = icmp eq i32 %13, %14
  br i1 %15, label %.thread, label %16

16:                                               ; preds = %11
  %17 = getelementptr inbounds i8, ptr %.01525, i64 36
  %18 = load i32, ptr %17, align 4, !tbaa !15
  %19 = load i32, ptr %12, align 4, !tbaa !15
  %20 = load i32, ptr %5, align 4, !tbaa !15
  %21 = xor i32 %20, %19
  %22 = and i32 %21, %18
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %24, label %.thread

24:                                               ; preds = %16
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %1, ptr noundef nonnull align 4 dereferenceable(16) %8, i64 16, i1 false)
  %25 = getelementptr inbounds i8, ptr %1, i64 16
  %26 = getelementptr inbounds i8, ptr %.01525, i64 40
  %27 = load ptr, ptr %26, align 8, !tbaa !18
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %25, ptr noundef nonnull align 2 dereferenceable(16) %27, i64 16, i1 false)
  br label %.loopexit

.thread:                                          ; preds = %16, %6, %11
  %.015 = load ptr, ptr %.01525, align 8, !tbaa !5
  %.not.not = icmp eq ptr %.015, null
  br i1 %.not.not, label %.loopexit, label %6, !llvm.loop !19

.loopexit:                                        ; preds = %.thread, %2, %24
  %.not21 = phi i1 [ true, %24 ], [ false, %2 ], [ false, %.thread ]
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  call void @freeifaddrs(ptr noundef %28) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  ret i1 %.not21
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL10__bswap_32j(i32 noundef) local_unnamed_addr #4

; Function Attrs: nounwind
declare void @freeifaddrs(ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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 = { 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 = { inlinehint mustprogress 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 = { 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++ TBAA"}
!9 = !{!10, !6, i64 24}
!10 = !{!"_ZTS7ifaddrs", !6, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !6, i64 32, !7, i64 40, !6, i64 48}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !14, i64 0}
!13 = !{!"_ZTS8sockaddr", !14, i64 0, !7, i64 2}
!14 = !{!"short", !7, i64 0}
!15 = !{!16, !11, i64 4}
!16 = !{!"_ZTS11sockaddr_in", !14, i64 0, !14, i64 2, !17, i64 4, !7, i64 8}
!17 = !{!"_ZTS7in_addr", !11, i64 0}
!18 = !{!7, !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass