; LLVM IR from thomasfla/Linux-ESPNOW :: Lab/EspNowPacket (EspNowPacket)

; 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.sockaddr_ll = type { i16, i16, i32, i16, i8, i8, [8 x i8] }
%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 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [88 x i8], align 1
@__PRETTY_FUNCTION__.create_raw_socket = external hidden unnamed_addr constant [30 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1
@gu8a_dest_mac = external hidden global [6 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @create_raw_socket(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca %struct.sockaddr_ll, align 4
  %4 = alloca %struct.ifreq, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 20, ptr %3) #6
  call void @llvm.lifetime.start.p0(i64 40, ptr %4) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  call void @llvm.memset.p0.i64(ptr align 4 %3, i8 0, i64 20, i1 false)
  call void @llvm.memset.p0.i64(ptr align 8 %4, i8 0, i64 40, i1 false)
  call void @llvm.memset.p0.i64(ptr align 4 %3, i8 0, i64 20, i1 false)
  %8 = call zeroext i16 @__bswap_16(i16 noundef zeroext 3)
  %9 = zext i16 %8 to i32
  %10 = call i32 @socket(i32 noundef 17, i32 noundef 3, i32 noundef %9) #6
  store i32 %10, ptr %5, align 4, !tbaa !9
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = icmp ne i32 %11, -1
  br i1 %12, label %13, label %14

13:                                               ; preds = %1
  br label %15

14:                                               ; preds = %1
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 56, ptr noundef @__PRETTY_FUNCTION__.create_raw_socket) #7
  unreachable

15:                                               ; preds = %13
  %16 = getelementptr inbounds %struct.ifreq, ptr %4, i32 0, i32 0
  %17 = getelementptr inbounds [16 x i8], ptr %16, i64 0, i64 0
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = call ptr @strncpy(ptr noundef %17, ptr noundef %18, i64 noundef 16) #6
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = call i32 (i32, i64, ...) @ioctl(i32 noundef %20, i64 noundef 35123, ptr noundef %4) #6
  store i32 %21, ptr %6, align 4, !tbaa !9
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = icmp ne i32 %22, -1
  br i1 %23, label %24, label %25

24:                                               ; preds = %15
  br label %26

25:                                               ; preds = %15
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 60, ptr noundef @__PRETTY_FUNCTION__.create_raw_socket) #7
  unreachable

26:                                               ; preds = %24
  %27 = getelementptr inbounds %struct.sockaddr_ll, ptr %3, i32 0, i32 0
  store i16 17, ptr %27, align 4, !tbaa !11
  %28 = call zeroext i16 @__bswap_16(i16 noundef zeroext 3)
  %29 = getelementptr inbounds %struct.sockaddr_ll, ptr %3, i32 0, i32 1
  store i16 %28, ptr %29, align 2, !tbaa !14
  %30 = getelementptr inbounds %struct.ifreq, ptr %4, i32 0, i32 1
  %31 = load i32, ptr %30, align 8, !tbaa !15
  %32 = getelementptr inbounds %struct.sockaddr_ll, ptr %3, i32 0, i32 2
  store i32 %31, ptr %32, align 4, !tbaa !16
  %33 = getelementptr inbounds %struct.sockaddr_ll, ptr %3, i32 0, i32 3
  store i16 1, ptr %33, align 4, !tbaa !17
  %34 = getelementptr inbounds %struct.sockaddr_ll, ptr %3, i32 0, i32 4
  store i8 3, ptr %34, align 2, !tbaa !18
  %35 = getelementptr inbounds %struct.sockaddr_ll, ptr %3, i32 0, i32 5
  store i8 6, ptr %35, align 1, !tbaa !19
  %36 = load i8, ptr @gu8a_dest_mac, align 1, !tbaa !15
  %37 = getelementptr inbounds %struct.sockaddr_ll, ptr %3, i32 0, i32 6
  %38 = getelementptr inbounds [8 x i8], ptr %37, i64 0, i64 0
  store i8 %36, ptr %38, align 4, !tbaa !15
  %39 = load i8, ptr getelementptr inbounds ([6 x i8], ptr @gu8a_dest_mac, i64 0, i64 1), align 1, !tbaa !15
  %40 = getelementptr inbounds %struct.sockaddr_ll, ptr %3, i32 0, i32 6
  %41 = getelementptr inbounds [8 x i8], ptr %40, i64 0, i64 1
  store i8 %39, ptr %41, align 1, !tbaa !15
  %42 = load i8, ptr getelementptr inbounds ([6 x i8], ptr @gu8a_dest_mac, i64 0, i64 2), align 1, !tbaa !15
  %43 = getelementptr inbounds %struct.sockaddr_ll, ptr %3, i32 0, i32 6
  %44 = getelementptr inbounds [8 x i8], ptr %43, i64 0, i64 2
  store i8 %42, ptr %44, align 2, !tbaa !15
  %45 = load i8, ptr getelementptr inbounds ([6 x i8], ptr @gu8a_dest_mac, i64 0, i64 3), align 1, !tbaa !15
  %46 = getelementptr inbounds %struct.sockaddr_ll, ptr %3, i32 0, i32 6
  %47 = getelementptr inbounds [8 x i8], ptr %46, i64 0, i64 3
  store i8 %45, ptr %47, align 1, !tbaa !15
  %48 = load i8, ptr getelementptr inbounds ([6 x i8], ptr @gu8a_dest_mac, i64 0, i64 4), align 1, !tbaa !15
  %49 = getelementptr inbounds %struct.sockaddr_ll, ptr %3, i32 0, i32 6
  %50 = getelementptr inbounds [8 x i8], ptr %49, i64 0, i64 4
  store i8 %48, ptr %50, align 4, !tbaa !15
  %51 = load i8, ptr getelementptr inbounds ([6 x i8], ptr @gu8a_dest_mac, i64 0, i64 5), align 1, !tbaa !15
  %52 = getelementptr inbounds %struct.sockaddr_ll, ptr %3, i32 0, i32 6
  %53 = getelementptr inbounds [8 x i8], ptr %52, i64 0, i64 5
  store i8 %51, ptr %53, align 1, !tbaa !15
  %54 = getelementptr inbounds %struct.sockaddr_ll, ptr %3, i32 0, i32 6
  %55 = getelementptr inbounds [8 x i8], ptr %54, i64 0, i64 6
  store i8 0, ptr %55, align 2, !tbaa !15
  %56 = getelementptr inbounds %struct.sockaddr_ll, ptr %3, i32 0, i32 6
  %57 = getelementptr inbounds [8 x i8], ptr %56, i64 0, i64 7
  store i8 0, ptr %57, align 1, !tbaa !15
  %58 = load i32, ptr %5, align 4, !tbaa !9
  %59 = call i32 @bind(i32 noundef %58, ptr noundef %3, i32 noundef 20) #6
  store i32 %59, ptr %7, align 4, !tbaa !9
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = icmp ne i32 %60, -1
  br i1 %61, label %62, label %63

62:                                               ; preds = %26
  br label %64

63:                                               ; preds = %26
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 81, ptr noundef @__PRETTY_FUNCTION__.create_raw_socket) #7
  unreachable

64:                                               ; preds = %62
  %65 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 40, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 20, ptr %3) #6
  ret i32 %65
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i16 @__bswap_16(i16 noundef zeroext) #4

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #5

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #3

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

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 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 = { noreturn 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 #6 = { nounwind }
attributes #7 = { noreturn 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, !13, i64 0}
!12 = !{!"sockaddr_ll", !13, i64 0, !13, i64 2, !10, i64 4, !13, i64 8, !7, i64 10, !7, i64 11, !7, i64 12}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !13, i64 2}
!15 = !{!7, !7, i64 0}
!16 = !{!12, !10, i64 4}
!17 = !{!12, !13, i64 8}
!18 = !{!12, !7, i64 10}
!19 = !{!12, !7, i64 11}


; 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.sockaddr_ll = type { i16, i16, i32, i16, i8, i8, [8 x i8] }
%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 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [88 x i8], align 1
@__PRETTY_FUNCTION__.create_raw_socket = external hidden unnamed_addr constant [30 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1
@gu8a_dest_mac = external hidden local_unnamed_addr global [6 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, -1) i32 @create_raw_socket(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = alloca %struct.sockaddr_ll, align 4
  %3 = alloca %struct.ifreq, align 8
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %2) #7
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %3) #7
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(20) %2, i8 0, i64 20, i1 false)
  %4 = getelementptr inbounds i8, ptr %3, i64 16
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) %4, i8 0, i64 24, i1 false)
  %5 = tail call zeroext i16 @__bswap_16(i16 noundef zeroext 3)
  %6 = zext i16 %5 to i32
  %7 = tail call i32 @socket(i32 noundef 17, i32 noundef 3, i32 noundef %6) #7
  %.not = icmp eq i32 %7, -1
  br i1 %.not, label %8, label %9

8:                                                ; preds = %1
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 56, ptr noundef nonnull @__PRETTY_FUNCTION__.create_raw_socket) #8
  unreachable

9:                                                ; preds = %1
  %10 = call ptr @strncpy(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) %0, i64 noundef 16) #7
  %11 = call i32 (i32, i64, ...) @ioctl(i32 noundef %7, i64 noundef 35123, ptr noundef nonnull %3) #7
  %.not6 = icmp eq i32 %11, -1
  br i1 %.not6, label %12, label %13

12:                                               ; preds = %9
  call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 60, ptr noundef nonnull @__PRETTY_FUNCTION__.create_raw_socket) #8
  unreachable

13:                                               ; preds = %9
  store i16 17, ptr %2, align 4, !tbaa !5
  %14 = call zeroext i16 @__bswap_16(i16 noundef zeroext 3)
  %15 = getelementptr inbounds i8, ptr %2, i64 2
  store i16 %14, ptr %15, align 2, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %3, i64 16
  %17 = load i32, ptr %16, align 8, !tbaa !12
  %18 = getelementptr inbounds i8, ptr %2, i64 4
  store i32 %17, ptr %18, align 4, !tbaa !13
  %19 = getelementptr inbounds i8, ptr %2, i64 8
  store i16 1, ptr %19, align 4, !tbaa !14
  %20 = getelementptr inbounds i8, ptr %2, i64 10
  store i8 3, ptr %20, align 2, !tbaa !15
  %21 = getelementptr inbounds i8, ptr %2, i64 11
  store i8 6, ptr %21, align 1, !tbaa !16
  %22 = getelementptr inbounds i8, ptr %2, i64 12
  %23 = load <4 x i8>, ptr @gu8a_dest_mac, align 1, !tbaa !12
  store <4 x i8> %23, ptr %22, align 4, !tbaa !12
  %24 = load i8, ptr getelementptr inbounds (i8, ptr @gu8a_dest_mac, i64 4), align 1, !tbaa !12
  %25 = getelementptr inbounds i8, ptr %2, i64 16
  store i8 %24, ptr %25, align 4, !tbaa !12
  %26 = load i8, ptr getelementptr inbounds (i8, ptr @gu8a_dest_mac, i64 5), align 1, !tbaa !12
  %27 = getelementptr inbounds i8, ptr %2, i64 17
  store i8 %26, ptr %27, align 1, !tbaa !12
  %28 = getelementptr inbounds i8, ptr %2, i64 18
  store i8 0, ptr %28, align 2, !tbaa !12
  %29 = getelementptr inbounds i8, ptr %2, i64 19
  store i8 0, ptr %29, align 1, !tbaa !12
  %30 = call i32 @bind(i32 noundef %7, ptr noundef nonnull %2, i32 noundef 20) #7
  %.not7 = icmp eq i32 %30, -1
  br i1 %.not7, label %31, label %32

31:                                               ; preds = %13
  call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 81, ptr noundef nonnull @__PRETTY_FUNCTION__.create_raw_socket) #8
  unreachable

32:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %3) #7
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %2) #7
  ret i32 %7
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i16 @__bswap_16(i16 noundef zeroext) local_unnamed_addr #4

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #5

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

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

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

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 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 = { noreturn 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 #6 = { 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 #7 = { nounwind }
attributes #8 = { noreturn 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 = !{!"sockaddr_ll", !7, i64 0, !7, i64 2, !10, i64 4, !7, i64 8, !8, i64 10, !8, i64 11, !8, i64 12}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 2}
!12 = !{!8, !8, i64 0}
!13 = !{!6, !10, i64 4}
!14 = !{!6, !7, i64 8}
!15 = !{!6, !8, i64 10}
!16 = !{!6, !8, i64 11}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass