; LLVM IR from turi-code/SFrame :: oss_src/network/net_util.ll (ZN8graphlab26get_interface_ip_in_subnetEjjRj)

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

%class.anon = type { ptr }
%class.anon.1 = type { ptr }
%struct.ifaddrs = type { ptr, ptr, i32, ptr, ptr, %union.anon.0, ptr }
%union.anon.0 = 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 }

; 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: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN8graphlab26get_interface_ip_in_subnetEjjRj(i32 noundef %0, i32 noundef %1, ptr noundef nonnull align 4 dereferenceable(4) %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca %class.anon, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca %class.anon.1, align 8
  %17 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #6
  store i8 0, ptr %7, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  store ptr null, ptr %8, align 8, !tbaa !9
  %18 = call i32 @getifaddrs(ptr noundef %8) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %19 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %19, ptr %9, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %21 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %21, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  store i64 0, ptr %11, align 8, !tbaa !13
  %22 = load ptr, ptr %10, align 8, !tbaa !9
  %23 = icmp ne ptr %22, null
  %24 = xor i1 %23, true
  %25 = zext i1 %24 to i64
  %26 = call i64 @llvm.expect.i64(i64 %25, i64 0)
  %27 = icmp ne i64 %26, 0
  br i1 %27, label %28, label %30

28:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  %29 = getelementptr inbounds %class.anon, ptr %12, i32 0, i32 0
  store ptr %10, ptr %29, align 8, !tbaa !9
  call void @"_ZZN8graphlab26get_interface_ip_in_subnetEjjRjENK3$_0clEv"(ptr noundef nonnull align 8 dereferenceable(8) %12)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  br label %30

30:                                               ; preds = %28, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  br label %33

33:                                               ; preds = %87, %32
  %34 = load ptr, ptr %8, align 8, !tbaa !9
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %91

36:                                               ; preds = %33
  %37 = load ptr, ptr %8, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.ifaddrs, ptr %37, i32 0, i32 3
  %39 = load ptr, ptr %38, align 8, !tbaa !15
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %87

41:                                               ; preds = %36
  %42 = load ptr, ptr %8, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct.ifaddrs, ptr %42, i32 0, i32 3
  %44 = load ptr, ptr %43, align 8, !tbaa !15
  %45 = getelementptr inbounds %struct.sockaddr, ptr %44, i32 0, i32 0
  %46 = load i16, ptr %45, align 2, !tbaa !17
  %47 = zext i16 %46 to i32
  %48 = icmp eq i32 %47, 2
  br i1 %48, label %49, label %87

49:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #6
  store ptr null, ptr %13, align 8, !tbaa !9
  %50 = load ptr, ptr %8, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.ifaddrs, ptr %50, i32 0, i32 3
  %52 = load ptr, ptr %51, align 8, !tbaa !15
  %53 = getelementptr inbounds %struct.sockaddr_in, ptr %52, i32 0, i32 2
  store ptr %53, ptr %13, align 8, !tbaa !9
  br label %54

54:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #6
  %55 = load ptr, ptr %13, align 8, !tbaa !9
  store ptr %55, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #6
  store i64 0, ptr %15, align 8, !tbaa !13
  %56 = load ptr, ptr %14, align 8, !tbaa !9
  %57 = icmp ne ptr %56, null
  %58 = xor i1 %57, true
  %59 = zext i1 %58 to i64
  %60 = call i64 @llvm.expect.i64(i64 %59, i64 0)
  %61 = icmp ne i64 %60, 0
  br i1 %61, label %62, label %64

62:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #6
  %63 = getelementptr inbounds %class.anon.1, ptr %16, i32 0, i32 0
  store ptr %14, ptr %63, align 8, !tbaa !9
  call void @"_ZZN8graphlab26get_interface_ip_in_subnetEjjRjENK3$_1clEv"(ptr noundef nonnull align 8 dereferenceable(8) %16)
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #6
  br label %64

64:                                               ; preds = %62, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  br label %65

65:                                               ; preds = %64
  br label %66

66:                                               ; preds = %65
  %67 = load ptr, ptr %13, align 8, !tbaa !9
  %68 = getelementptr inbounds i8, ptr %67, i64 0
  %69 = load i8, ptr %68, align 1, !tbaa !20
  %70 = sext i8 %69 to i32
  %71 = icmp ne i32 %70, 127
  br i1 %71, label %72, label %83

72:                                               ; preds = %66
  %73 = load ptr, ptr %6, align 8, !tbaa !9
  %74 = load ptr, ptr %13, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %73, ptr align 1 %74, i64 4, i1 false)
  %75 = load ptr, ptr %6, align 8, !tbaa !9
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = load i32, ptr %5, align 4, !tbaa !5
  %78 = and i32 %76, %77
  %79 = load i32, ptr %4, align 4, !tbaa !5
  %80 = icmp eq i32 %78, %79
  br i1 %80, label %81, label %82

81:                                               ; preds = %72
  store i8 1, ptr %7, align 1, !tbaa !11
  store i32 5, ptr %17, align 4
  br label %84

82:                                               ; preds = %72
  br label %83

83:                                               ; preds = %82, %66
  store i32 0, ptr %17, align 4
  br label %84

84:                                               ; preds = %83, %81
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  %85 = load i32, ptr %17, align 4
  switch i32 %85, label %95 [
    i32 0, label %86
    i32 5, label %91
  ]

86:                                               ; preds = %84
  br label %87

87:                                               ; preds = %86, %41, %36
  %88 = load ptr, ptr %8, align 8, !tbaa !9
  %89 = getelementptr inbounds %struct.ifaddrs, ptr %88, i32 0, i32 0
  %90 = load ptr, ptr %89, align 8, !tbaa !21
  store ptr %90, ptr %8, align 8, !tbaa !9
  br label %33, !llvm.loop !22

91:                                               ; preds = %84, %33
  %92 = load ptr, ptr %9, align 8, !tbaa !9
  call void @freeifaddrs(ptr noundef %92) #6
  %93 = load i8, ptr %7, align 1, !tbaa !11, !range !24, !noundef !25
  %94 = trunc i8 %93 to i1
  store i32 1, ptr %17, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #6
  ret i1 %94

95:                                               ; preds = %84
  unreachable
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #3

; Function Attrs: inlinehint mustprogress uwtable
declare hidden void @"_ZZN8graphlab26get_interface_ip_in_subnetEjjRjENK3$_0clEv"(ptr noundef nonnull align 8 dereferenceable(8)) #4 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare hidden void @"_ZZN8graphlab26get_interface_ip_in_subnetEjjRjENK3$_1clEv"(ptr noundef nonnull align 8 dereferenceable(8)) #4 align 2

; 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) #5

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

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


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

%class.anon = type { ptr }

; 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 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 @_ZN8graphlab26get_interface_ip_in_subnetEjjRj(i32 noundef %0, i32 noundef %1, ptr nocapture noundef nonnull writeonly align 4 dereferenceable(4) %2) local_unnamed_addr #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %class.anon, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  store ptr null, ptr %4, align 8, !tbaa !5
  %7 = call i32 @getifaddrs(ptr noundef nonnull %4) #4
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  store ptr %8, ptr %5, align 8, !tbaa !5
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %9, label %.thread23, !prof !9

.thread23:                                        ; preds = %3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  br label %.lr.ph.preheader

9:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  store ptr %5, ptr %6, align 8, !tbaa !5
  call void @"_ZZN8graphlab26get_interface_ip_in_subnetEjjRjENK3$_0clEv"(ptr noundef nonnull align 8 dereferenceable(8) %6)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  %.pr.pre = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  %.not1218.not = icmp eq ptr %.pr.pre, null
  br i1 %.not1218.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.thread23, %9
  %.ph = phi ptr [ %.pr.pre, %9 ], [ %8, %.thread23 ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.thread
  %10 = phi ptr [ %23, %.thread ], [ %.ph, %.lr.ph.preheader ]
  %11 = getelementptr inbounds i8, ptr %10, i64 24
  %12 = load ptr, ptr %11, align 8, !tbaa !10
  %.not13 = icmp eq ptr %12, null
  br i1 %.not13, label %.thread, label %13

13:                                               ; preds = %.lr.ph
  %14 = load i16, ptr %12, align 2, !tbaa !13
  %15 = icmp eq i16 %14, 2
  br i1 %15, label %16, label %.thread

16:                                               ; preds = %13
  %17 = getelementptr inbounds i8, ptr %12, i64 4
  %18 = load i8, ptr %17, align 1, !tbaa !16
  %.not14 = icmp eq i8 %18, 127
  br i1 %.not14, label %.thread, label %19

19:                                               ; preds = %16
  %20 = load i32, ptr %17, align 1
  store i32 %20, ptr %2, align 4
  %21 = and i32 %20, %1
  %22 = icmp eq i32 %21, %0
  br i1 %22, label %._crit_edge, label %.thread

.thread:                                          ; preds = %19, %16, %13, %.lr.ph
  %23 = load ptr, ptr %10, align 8, !tbaa !17
  store ptr %23, ptr %4, align 8, !tbaa !5
  %.not12.not = icmp eq ptr %23, null
  br i1 %.not12.not, label %._crit_edge, label %.lr.ph, !llvm.loop !18

._crit_edge:                                      ; preds = %.thread, %19, %9
  %.not12.lcssa = phi i1 [ false, %9 ], [ true, %19 ], [ false, %.thread ]
  call void @freeifaddrs(ptr noundef %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  ret i1 %.not12.lcssa
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare hidden void @"_ZZN8graphlab26get_interface_ip_in_subnetEjjRjENK3$_0clEv"(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3 align 2

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

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 = { 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 = { inlinehint 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 #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++ TBAA"}
!9 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!10 = !{!11, !6, i64 24}
!11 = !{!"_ZTS7ifaddrs", !6, i64 0, !6, i64 8, !12, i64 16, !6, i64 24, !6, i64 32, !7, i64 40, !6, i64 48}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"_ZTS8sockaddr", !15, i64 0, !7, i64 2}
!15 = !{!"short", !7, i64 0}
!16 = !{!7, !7, i64 0}
!17 = !{!11, !6, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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