; LLVM IR from kala13x/libxutils :: src/net (addr)

; 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.ifreq = type { %union.anon, %union.anon.0 }
%union.anon = type { [16 x i8] }
%union.anon.0 = type { %struct.ifmap }
%struct.ifmap = type { i64, i64, i16, i8, i8, i8 }
%struct.sockaddr = type { i16, [14 x i8] }
%struct.sockaddr_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }

@.str.5 = external hidden unnamed_addr constant [3 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare i64 @xstrncpy(ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind
declare i32 @socket(i32 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @XAddr_GetIFCIP(ptr noundef %0, ptr noundef %1, i32 noundef %2) #3 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %struct.ifreq, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %12 = call i32 @socket(i32 noundef 2, i32 noundef 2, i32 noundef 0) #4
  store i32 %12, ptr %8, align 4, !tbaa !9
  %13 = load i32, ptr %8, align 4, !tbaa !9
  %14 = icmp slt i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %3
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %50

16:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 40, ptr %10) #4
  %17 = getelementptr inbounds %struct.ifreq, ptr %10, i32 0, i32 1
  %18 = getelementptr inbounds %struct.sockaddr, ptr %17, i32 0, i32 0
  store i16 2, ptr %18, align 8, !tbaa !11
  %19 = getelementptr inbounds %struct.ifreq, ptr %10, i32 0, i32 0
  %20 = getelementptr inbounds [16 x i8], ptr %19, i64 0, i64 0
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = call i64 @xstrncpy(ptr noundef %20, i64 noundef 16, ptr noundef %21)
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = call i32 (i32, i64, ...) @ioctl(i32 noundef %23, i64 noundef 35093, ptr noundef %10) #4
  %25 = icmp slt i32 %24, 0
  br i1 %25, label %26, label %29

26:                                               ; preds = %16
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = call i32 @close(i32 noundef %27)
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %49

29:                                               ; preds = %16
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = call i32 @close(i32 noundef %30)
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %32 = getelementptr inbounds %struct.ifreq, ptr %10, i32 0, i32 1
  %33 = getelementptr inbounds %struct.sockaddr_in, ptr %32, i32 0, i32 2
  %34 = getelementptr inbounds %struct.in_addr, ptr %33, i32 0, i32 0
  %35 = load i32, ptr %34, align 4
  %36 = call ptr @inet_ntoa(i32 %35) #4
  store ptr %36, ptr %11, align 8, !tbaa !5
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %45

39:                                               ; preds = %29
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load i32, ptr %7, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = load ptr, ptr %11, align 8, !tbaa !5
  %44 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef %40, i64 noundef %42, ptr noundef @.str.5, ptr noundef %43)
  br label %46

45:                                               ; preds = %29
  br label %46

46:                                               ; preds = %45, %39
  %47 = phi i64 [ %44, %39 ], [ -1, %45 ]
  %48 = trunc i64 %47 to i32
  store i32 %48, ptr %4, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %49

49:                                               ; preds = %46, %26
  call void @llvm.lifetime.end.p0(i64 40, ptr %10) #4
  br label %50

50:                                               ; preds = %49, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %51 = load i32, ptr %4, align 4
  ret i32 %51
}

; Function Attrs: nounwind
declare i32 @ioctl(i32 noundef, i64 noundef, ...) #2

declare i32 @close(i32 noundef) #1

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

declare i64 @xstrncpyf(ptr noundef, i64 noundef, ptr noundef, ...) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 "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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}


; 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.ifreq = type { %union.anon, %union.anon.0 }
%union.anon = type { [16 x i8] }
%union.anon.0 = type { %struct.ifmap }
%struct.ifmap = type { i64, i64, i16, i8, i8, i8 }

@.str.5 = external hidden unnamed_addr constant [3 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare i64 @xstrncpy(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @socket(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @XAddr_GetIFCIP(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #3 {
  %4 = alloca %struct.ifreq, align 8
  %5 = tail call i32 @socket(i32 noundef 2, i32 noundef 2, i32 noundef 0) #4
  %6 = icmp slt i32 %5, 0
  br i1 %6, label %22, label %7

7:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %4) #4
  %8 = getelementptr inbounds i8, ptr %4, i64 16
  store i16 2, ptr %8, align 8, !tbaa !5
  %9 = call i64 @xstrncpy(ptr noundef nonnull %4, i64 noundef 16, ptr noundef %0) #4
  %10 = call i32 (i32, i64, ...) @ioctl(i32 noundef %5, i64 noundef 35093, ptr noundef nonnull %4) #4
  %11 = icmp slt i32 %10, 0
  %12 = call i32 @close(i32 noundef %5) #4
  br i1 %11, label %21, label %13

13:                                               ; preds = %7
  %14 = getelementptr inbounds i8, ptr %4, i64 20
  %15 = load i32, ptr %14, align 4
  %16 = call ptr @inet_ntoa(i32 %15) #4
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %21, label %17

17:                                               ; preds = %13
  %18 = sext i32 %2 to i64
  %19 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %1, i64 noundef %18, ptr noundef nonnull @.str.5, ptr noundef %16) #4
  %20 = trunc i64 %19 to i32
  br label %21

21:                                               ; preds = %7, %17, %13
  %.0 = phi i32 [ %20, %17 ], [ -1, %13 ], [ -1, %7 ]
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %4) #4
  br label %22

22:                                               ; preds = %3, %21
  %.1 = phi i32 [ %.0, %21 ], [ -1, %3 ]
  ret i32 %.1
}

; Function Attrs: nounwind
declare i32 @ioctl(i32 noundef, i64 noundef, ...) local_unnamed_addr #2

declare i32 @close(i32 noundef) local_unnamed_addr #1

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

declare i64 @xstrncpyf(ptr noundef, i64 noundef, ptr noundef, ...) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass