; LLVM IR from pandax381/microps :: ether (ether_poll_helper)

; 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.net_device = type { ptr, ptr, i32, [16 x i8], i16, i16, i16, i16, i16, [16 x i8], %union.anon, ptr, ptr }
%union.anon = type { [16 x i8] }
%struct.ether_hdr = type { [6 x i8], [6 x i8], i16 }

@ETHER_ADDR_BROADCAST = external dso_local constant [6 x i8], align 1
@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [59 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [33 x i8], align 1
@__func__.ether_poll_helper = external hidden unnamed_addr constant [18 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [24 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 i32 @lprintf(ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
declare hidden ptr @ether_type_ntoa(i16 noundef zeroext) #2

; Function Attrs: nounwind uwtable
declare hidden void @ether_dump(ptr noundef, i64 noundef) #2

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

17:                                               ; preds = %2
  %18 = load ptr, ptr @stderr, align 8, !tbaa !5
  %19 = call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %18, i32 noundef 69, ptr noundef @.str.1, i32 noundef 116, ptr noundef @__func__.ether_poll_helper, ptr noundef @.str.3)
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %64

20:                                               ; preds = %2
  %21 = getelementptr inbounds [1514 x i8], ptr %6, i64 0, i64 0
  store ptr %21, ptr %8, align 8, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.net_device, ptr %22, i32 0, i32 9
  %24 = getelementptr inbounds [16 x i8], ptr %23, i64 0, i64 0
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.ether_hdr, ptr %25, i32 0, i32 0
  %27 = getelementptr inbounds [6 x i8], ptr %26, i64 0, i64 0
  %28 = call i32 @memcmp(ptr noundef %24, ptr noundef %27, i64 noundef 6) #5
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %38

30:                                               ; preds = %20
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ether_hdr, ptr %31, i32 0, i32 0
  %33 = getelementptr inbounds [6 x i8], ptr %32, i64 0, i64 0
  %34 = call i32 @memcmp(ptr noundef @ETHER_ADDR_BROADCAST, ptr noundef %33, i64 noundef 6) #5
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %30
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %64

37:                                               ; preds = %30
  br label %38

38:                                               ; preds = %37, %20
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.ether_hdr, ptr %39, i32 0, i32 2
  %41 = load i16, ptr %40, align 2, !tbaa !11
  %42 = call zeroext i16 @ntoh16(i16 noundef zeroext %41)
  store i16 %42, ptr %9, align 2, !tbaa !14
  %43 = load ptr, ptr @stderr, align 8, !tbaa !5
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.net_device, ptr %44, i32 0, i32 3
  %46 = getelementptr inbounds [16 x i8], ptr %45, i64 0, i64 0
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ether_hdr, ptr %47, i32 0, i32 2
  %49 = load i16, ptr %48, align 2, !tbaa !11
  %50 = call ptr @ether_type_ntoa(i16 noundef zeroext %49)
  %51 = load i16, ptr %9, align 2, !tbaa !14
  %52 = zext i16 %51 to i32
  %53 = load i64, ptr %7, align 8, !tbaa !9
  %54 = call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %43, i32 noundef 68, ptr noundef @.str.1, i32 noundef 127, ptr noundef @__func__.ether_poll_helper, ptr noundef @.str.2, ptr noundef %46, ptr noundef %50, i32 noundef %52, i64 noundef %53)
  %55 = getelementptr inbounds [1514 x i8], ptr %6, i64 0, i64 0
  %56 = load i64, ptr %7, align 8, !tbaa !9
  call void @ether_dump(ptr noundef %55, i64 noundef %56)
  %57 = load i16, ptr %9, align 2, !tbaa !14
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.ether_hdr, ptr %58, i64 1
  %60 = load i64, ptr %7, align 8, !tbaa !9
  %61 = sub i64 %60, 14
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = call i32 @net_input_handler(i16 noundef zeroext %57, ptr noundef %59, i64 noundef %61, ptr noundef %62)
  store i32 %63, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %64

64:                                               ; preds = %38, %36, %17
  call void @llvm.lifetime.end.p0(i64 2, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 1514, ptr %6) #4
  %65 = load i32, ptr %3, align 4
  ret i32 %65
}

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #3

declare zeroext i16 @ntoh16(i16 noundef zeroext) #1

declare i32 @net_input_handler(i16 noundef zeroext, 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 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 willreturn memory(read) "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 }
attributes #5 = { nounwind willreturn memory(read) }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !13, i64 12}
!12 = !{!"ether_hdr", !7, i64 0, !7, i64 6, !13, i64 12}
!13 = !{!"short", !7, i64 0}
!14 = !{!13, !13, 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"

@ETHER_ADDR_BROADCAST = external dso_local constant [6 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [59 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [33 x i8], align 1
@__func__.ether_poll_helper = external hidden unnamed_addr constant [18 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [24 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 i32 @lprintf(ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden ptr @ether_type_ntoa(i16 noundef zeroext) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @ether_dump(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @ether_poll_helper(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #2 {
  %3 = alloca [1514 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 1514, ptr nonnull %3) #4
  %4 = call i64 %1(ptr noundef %0, ptr noundef nonnull %3, i64 noundef 1514) #4
  %5 = icmp slt i64 %4, 14
  br i1 %5, label %6, label %9

6:                                                ; preds = %2
  %7 = load ptr, ptr @stderr, align 8, !tbaa !5
  %8 = call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %7, i32 noundef 69, ptr noundef nonnull @.str.1, i32 noundef 116, ptr noundef nonnull @__func__.ether_poll_helper, ptr noundef nonnull @.str.3) #4
  br label %25

9:                                                ; preds = %2
  %10 = getelementptr inbounds i8, ptr %0, i64 46
  %bcmp = call i32 @bcmp(ptr noundef nonnull dereferenceable(6) %10, ptr noundef nonnull dereferenceable(6) %3, i64 6)
  %.not = icmp eq i32 %bcmp, 0
  br i1 %.not, label %12, label %11

11:                                               ; preds = %9
  %bcmp17 = call i32 @bcmp(ptr noundef nonnull dereferenceable(6) @ETHER_ADDR_BROADCAST, ptr noundef nonnull dereferenceable(6) %3, i64 6)
  %.not18 = icmp eq i32 %bcmp17, 0
  br i1 %.not18, label %12, label %25

12:                                               ; preds = %11, %9
  %13 = getelementptr inbounds i8, ptr %3, i64 12
  %14 = load i16, ptr %13, align 4, !tbaa !9
  %15 = call zeroext i16 @ntoh16(i16 noundef zeroext %14) #4
  %16 = load ptr, ptr @stderr, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %0, i64 20
  %18 = load i16, ptr %13, align 4, !tbaa !9
  %19 = call ptr @ether_type_ntoa(i16 noundef zeroext %18)
  %20 = zext i16 %15 to i32
  %21 = call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %16, i32 noundef 68, ptr noundef nonnull @.str.1, i32 noundef 127, ptr noundef nonnull @__func__.ether_poll_helper, ptr noundef nonnull @.str.2, ptr noundef nonnull %17, ptr noundef %19, i32 noundef %20, i64 noundef %4) #4
  call void @ether_dump(ptr noundef nonnull %3, i64 noundef %4)
  %22 = getelementptr inbounds i8, ptr %3, i64 14
  %23 = add nsw i64 %4, -14
  %24 = call i32 @net_input_handler(i16 noundef zeroext %15, ptr noundef nonnull %22, i64 noundef %23, ptr noundef %0) #4
  br label %25

25:                                               ; preds = %11, %12, %6
  %.0 = phi i32 [ -1, %6 ], [ %24, %12 ], [ -1, %11 ]
  call void @llvm.lifetime.end.p0(i64 1514, ptr nonnull %3) #4
  ret i32 %.0
}

declare zeroext i16 @ntoh16(i16 noundef zeroext) local_unnamed_addr #1

declare i32 @net_input_handler(i16 noundef zeroext, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #3

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 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 = { nofree nounwind willreturn memory(argmem: read) }
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, !11, i64 12}
!10 = !{!"ether_hdr", !7, i64 0, !7, i64 6, !11, i64 12}
!11 = !{!"short", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass