; 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.ifconf = type { i32, %union.anon.1 }
%union.anon.1 = type { ptr }
%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] }

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

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

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

declare i32 @close(i32 noundef) #2

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

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

17:                                               ; preds = %2
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %107

18:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 1024, ptr %9) #4
  %19 = getelementptr inbounds %struct.ifconf, ptr %8, i32 0, i32 0
  store i32 1024, ptr %19, align 8, !tbaa !11
  %20 = getelementptr inbounds [1024 x i8], ptr %9, i64 0, i64 0
  %21 = getelementptr inbounds %struct.ifconf, ptr %8, i32 0, i32 1
  store ptr %20, ptr %21, align 8, !tbaa !13
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = call i32 (i32, i64, ...) @ioctl(i32 noundef %22, i64 noundef 35090, ptr noundef %8) #4
  %24 = icmp eq i32 %23, -1
  br i1 %24, label %25, label %28

25:                                               ; preds = %18
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = call i32 @close(i32 noundef %26)
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %106

28:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %29 = getelementptr inbounds %struct.ifconf, ptr %8, i32 0, i32 1
  %30 = load ptr, ptr %29, align 8, !tbaa !13
  store ptr %30, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ifconf, ptr %8, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %34 = sext i32 %33 to i64
  %35 = udiv i64 %34, 40
  %36 = getelementptr inbounds %struct.ifreq, ptr %31, i64 %35
  store ptr %36, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 40, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %99, %28
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = load ptr, ptr %11, align 8, !tbaa !5
  %40 = icmp ne ptr %38, %39
  br i1 %40, label %41, label %102

41:                                               ; preds = %37
  %42 = getelementptr inbounds %struct.ifreq, ptr %12, i32 0, i32 0
  %43 = getelementptr inbounds [16 x i8], ptr %42, i64 0, i64 0
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.ifreq, ptr %44, i32 0, i32 0
  %46 = getelementptr inbounds [16 x i8], ptr %45, i64 0, i64 0
  %47 = call ptr @strcpy(ptr noundef %43, ptr noundef %46) #4
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = call i32 (i32, i64, ...) @ioctl(i32 noundef %48, i64 noundef 35091, ptr noundef %12) #4
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %52

51:                                               ; preds = %41
  br label %102

52:                                               ; preds = %41
  %53 = getelementptr inbounds %struct.ifreq, ptr %12, i32 0, i32 1
  %54 = load i16, ptr %53, align 8, !tbaa !13
  %55 = sext i16 %54 to i32
  %56 = and i32 %55, 8
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %98, label %58

58:                                               ; preds = %52
  %59 = load i32, ptr %6, align 4, !tbaa !9
  %60 = call i32 (i32, i64, ...) @ioctl(i32 noundef %59, i64 noundef 35111, ptr noundef %12) #4
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %98, label %62

62:                                               ; preds = %58
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = load i32, ptr %5, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds %struct.ifreq, ptr %12, i32 0, i32 1
  %67 = getelementptr inbounds %struct.sockaddr, ptr %66, i32 0, i32 1
  %68 = getelementptr inbounds [14 x i8], ptr %67, i64 0, i64 0
  %69 = load i8, ptr %68, align 2, !tbaa !13
  %70 = sext i8 %69 to i32
  %71 = getelementptr inbounds %struct.ifreq, ptr %12, i32 0, i32 1
  %72 = getelementptr inbounds %struct.sockaddr, ptr %71, i32 0, i32 1
  %73 = getelementptr inbounds [14 x i8], ptr %72, i64 0, i64 1
  %74 = load i8, ptr %73, align 1, !tbaa !13
  %75 = sext i8 %74 to i32
  %76 = getelementptr inbounds %struct.ifreq, ptr %12, i32 0, i32 1
  %77 = getelementptr inbounds %struct.sockaddr, ptr %76, i32 0, i32 1
  %78 = getelementptr inbounds [14 x i8], ptr %77, i64 0, i64 2
  %79 = load i8, ptr %78, align 2, !tbaa !13
  %80 = sext i8 %79 to i32
  %81 = getelementptr inbounds %struct.ifreq, ptr %12, i32 0, i32 1
  %82 = getelementptr inbounds %struct.sockaddr, ptr %81, i32 0, i32 1
  %83 = getelementptr inbounds [14 x i8], ptr %82, i64 0, i64 3
  %84 = load i8, ptr %83, align 1, !tbaa !13
  %85 = sext i8 %84 to i32
  %86 = getelementptr inbounds %struct.ifreq, ptr %12, i32 0, i32 1
  %87 = getelementptr inbounds %struct.sockaddr, ptr %86, i32 0, i32 1
  %88 = getelementptr inbounds [14 x i8], ptr %87, i64 0, i64 4
  %89 = load i8, ptr %88, align 2, !tbaa !13
  %90 = sext i8 %89 to i32
  %91 = getelementptr inbounds %struct.ifreq, ptr %12, i32 0, i32 1
  %92 = getelementptr inbounds %struct.sockaddr, ptr %91, i32 0, i32 1
  %93 = getelementptr inbounds [14 x i8], ptr %92, i64 0, i64 5
  %94 = load i8, ptr %93, align 1, !tbaa !13
  %95 = sext i8 %94 to i32
  %96 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef %63, i64 noundef %65, ptr noundef @.str.6, i32 noundef %70, i32 noundef %75, i32 noundef %80, i32 noundef %85, i32 noundef %90, i32 noundef %95)
  %97 = trunc i64 %96 to i32
  store i32 %97, ptr %13, align 4, !tbaa !9
  br label %102

98:                                               ; preds = %58, %52
  br label %99

99:                                               ; preds = %98
  %100 = load ptr, ptr %10, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.ifreq, ptr %100, i32 1
  store ptr %101, ptr %10, align 8, !tbaa !5
  br label %37, !llvm.loop !14

102:                                              ; preds = %62, %51, %37
  %103 = load i32, ptr %6, align 4, !tbaa !9
  %104 = call i32 @close(i32 noundef %103)
  %105 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %105, ptr %3, align 4
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %106

106:                                              ; preds = %102, %25
  call void @llvm.lifetime.end.p0(i64 1024, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #4
  br label %107

107:                                              ; preds = %106, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %108 = load i32, ptr %3, align 4
  ret i32 %108
}

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"ifconf", !10, i64 0, !7, i64 8}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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.ifconf = type { i32, %union.anon.1 }
%union.anon.1 = type { ptr }
%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.6 = external hidden unnamed_addr constant [30 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

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

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

declare i32 @close(i32 noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @XAddr_GetMAC(ptr noundef %0, i32 noundef %1) local_unnamed_addr #3 {
  %3 = alloca %struct.ifconf, align 8
  %4 = alloca [1024 x i8], align 16
  %5 = alloca %struct.ifreq, align 8
  %6 = tail call i32 @socket(i32 noundef 2, i32 noundef 2, i32 noundef 0) #5
  %7 = icmp slt i32 %6, 0
  br i1 %7, label %55, label %8

8:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %4) #5
  store i32 1024, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %4, ptr %9, align 8, !tbaa !10
  %10 = call i32 (i32, i64, ...) @ioctl(i32 noundef %6, i64 noundef 35090, ptr noundef nonnull %3) #5
  %11 = icmp eq i32 %10, -1
  br i1 %11, label %12, label %14

12:                                               ; preds = %8
  %13 = call i32 @close(i32 noundef %6) #5
  br label %54

14:                                               ; preds = %8
  %15 = load ptr, ptr %9, align 8, !tbaa !10
  %16 = load i32, ptr %3, align 8, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = udiv i64 %17, 40
  %19 = getelementptr inbounds %struct.ifreq, ptr %15, i64 %18
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %5) #5
  %.not20 = icmp ult i32 %16, 40
  br i1 %.not20, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %14
  %20 = getelementptr inbounds i8, ptr %5, i64 16
  br label %21

21:                                               ; preds = %.lr.ph, %51
  %.01521 = phi ptr [ %15, %.lr.ph ], [ %52, %51 ]
  %22 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %5, ptr noundef nonnull dereferenceable(1) %.01521) #5
  %23 = call i32 (i32, i64, ...) @ioctl(i32 noundef %6, i64 noundef 35091, ptr noundef nonnull %5) #5
  %.not17 = icmp eq i32 %23, 0
  br i1 %.not17, label %24, label %.loopexit

24:                                               ; preds = %21
  %25 = load i16, ptr %20, align 8, !tbaa !10
  %26 = and i16 %25, 8
  %.not18 = icmp eq i16 %26, 0
  br i1 %.not18, label %27, label %51

27:                                               ; preds = %24
  %28 = call i32 (i32, i64, ...) @ioctl(i32 noundef %6, i64 noundef 35111, ptr noundef nonnull %5) #5
  %.not19 = icmp eq i32 %28, 0
  br i1 %.not19, label %29, label %51

29:                                               ; preds = %27
  %30 = sext i32 %1 to i64
  %31 = getelementptr inbounds i8, ptr %5, i64 18
  %32 = load i8, ptr %31, align 2, !tbaa !10
  %33 = sext i8 %32 to i32
  %34 = getelementptr inbounds i8, ptr %5, i64 19
  %35 = load i8, ptr %34, align 1, !tbaa !10
  %36 = sext i8 %35 to i32
  %37 = getelementptr inbounds i8, ptr %5, i64 20
  %38 = load i8, ptr %37, align 4, !tbaa !10
  %39 = sext i8 %38 to i32
  %40 = getelementptr inbounds i8, ptr %5, i64 21
  %41 = load i8, ptr %40, align 1, !tbaa !10
  %42 = sext i8 %41 to i32
  %43 = getelementptr inbounds i8, ptr %5, i64 22
  %44 = load i8, ptr %43, align 2, !tbaa !10
  %45 = sext i8 %44 to i32
  %46 = getelementptr inbounds i8, ptr %5, i64 23
  %47 = load i8, ptr %46, align 1, !tbaa !10
  %48 = sext i8 %47 to i32
  %49 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef %0, i64 noundef %30, ptr noundef nonnull @.str.6, i32 noundef %33, i32 noundef %36, i32 noundef %39, i32 noundef %42, i32 noundef %45, i32 noundef %48) #5
  %50 = trunc i64 %49 to i32
  br label %.loopexit

51:                                               ; preds = %24, %27
  %52 = getelementptr inbounds i8, ptr %.01521, i64 40
  %.not = icmp eq ptr %52, %19
  br i1 %.not, label %.loopexit, label %21, !llvm.loop !11

.loopexit:                                        ; preds = %51, %21, %14, %29
  %.0 = phi i32 [ %50, %29 ], [ 0, %14 ], [ 0, %21 ], [ 0, %51 ]
  %53 = call i32 @close(i32 noundef %6) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %5) #5
  br label %54

54:                                               ; preds = %.loopexit, %12
  %.014 = phi i32 [ -1, %12 ], [ %.0, %.loopexit ]
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #5
  br label %55

55:                                               ; preds = %2, %54
  %.1 = phi i32 [ %.014, %54 ], [ -1, %2 ]
  ret i32 %.1
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #4

attributes #0 = { mustprogress 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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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, !7, i64 0}
!6 = !{!"ifconf", !7, i64 0, !8, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!8, !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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