; LLVM IR from pandax381/microps :: ether (ether_transmit_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.ether_hdr = type { [6 x i8], [6 x i8], i16 }
%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] }

@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [59 x i8], align 1
@__func__.ether_transmit_helper = external hidden unnamed_addr constant [22 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [33 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 uwtable
define dso_local i32 @ether_transmit_helper(ptr noundef %0, i16 noundef zeroext %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, ptr noundef %5) #1 {
  %7 = alloca ptr, align 8
  %8 = alloca i16, align 2
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca [1514 x i8], align 16
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i16 %1, ptr %8, align 2, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i64 %3, ptr %10, align 8, !tbaa !11
  store ptr %4, ptr %11, align 8, !tbaa !5
  store ptr %5, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1514, ptr %13) #5
  call void @llvm.memset.p0.i64(ptr align 16 %13, i8 0, i64 1514, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  store i64 0, ptr %16, align 8, !tbaa !11
  %17 = getelementptr inbounds [1514 x i8], ptr %13, i64 0, i64 0
  store ptr %17, ptr %14, align 8, !tbaa !5
  %18 = load ptr, ptr %14, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.ether_hdr, ptr %18, i32 0, i32 0
  %20 = getelementptr inbounds [6 x i8], ptr %19, i64 0, i64 0
  %21 = load ptr, ptr %11, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %20, ptr align 1 %21, i64 6, i1 false)
  %22 = load ptr, ptr %14, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.ether_hdr, ptr %22, i32 0, i32 1
  %24 = getelementptr inbounds [6 x i8], ptr %23, i64 0, i64 0
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.net_device, ptr %25, i32 0, i32 9
  %27 = getelementptr inbounds [16 x i8], ptr %26, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %24, ptr align 2 %27, i64 6, i1 false)
  %28 = load i16, ptr %8, align 2, !tbaa !9
  %29 = call zeroext i16 @hton16(i16 noundef zeroext %28)
  %30 = load ptr, ptr %14, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ether_hdr, ptr %30, i32 0, i32 2
  store i16 %29, ptr %31, align 2, !tbaa !13
  %32 = load ptr, ptr %14, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.ether_hdr, ptr %32, i64 1
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = load i64, ptr %10, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %33, ptr align 1 %34, i64 %35, i1 false)
  %36 = load i64, ptr %10, align 8, !tbaa !11
  %37 = icmp ult i64 %36, 46
  br i1 %37, label %38, label %41

38:                                               ; preds = %6
  %39 = load i64, ptr %10, align 8, !tbaa !11
  %40 = sub i64 46, %39
  store i64 %40, ptr %16, align 8, !tbaa !11
  br label %41

41:                                               ; preds = %38, %6
  %42 = load i64, ptr %10, align 8, !tbaa !11
  %43 = add i64 14, %42
  %44 = load i64, ptr %16, align 8, !tbaa !11
  %45 = add i64 %43, %44
  store i64 %45, ptr %15, align 8, !tbaa !11
  %46 = load ptr, ptr @stderr, align 8, !tbaa !5
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.net_device, ptr %47, i32 0, i32 3
  %49 = getelementptr inbounds [16 x i8], ptr %48, i64 0, i64 0
  %50 = load ptr, ptr %14, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.ether_hdr, ptr %50, i32 0, i32 2
  %52 = load i16, ptr %51, align 2, !tbaa !13
  %53 = call ptr @ether_type_ntoa(i16 noundef zeroext %52)
  %54 = load i16, ptr %8, align 2, !tbaa !9
  %55 = zext i16 %54 to i32
  %56 = load i64, ptr %15, align 8, !tbaa !11
  %57 = call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %46, i32 noundef 68, ptr noundef @.str.1, i32 noundef 101, ptr noundef @__func__.ether_transmit_helper, ptr noundef @.str.2, ptr noundef %49, ptr noundef %53, i32 noundef %55, i64 noundef %56)
  %58 = getelementptr inbounds [1514 x i8], ptr %13, i64 0, i64 0
  %59 = load i64, ptr %15, align 8, !tbaa !11
  call void @ether_dump(ptr noundef %58, i64 noundef %59)
  %60 = load ptr, ptr %12, align 8, !tbaa !5
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds [1514 x i8], ptr %13, i64 0, i64 0
  %63 = load i64, ptr %15, align 8, !tbaa !11
  %64 = call i64 %60(ptr noundef %61, ptr noundef %62, i64 noundef %63)
  %65 = load i64, ptr %15, align 8, !tbaa !11
  %66 = icmp eq i64 %64, %65
  %67 = zext i1 %66 to i64
  %68 = select i1 %66, i32 0, i32 -1
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 1514, ptr %13) #5
  ret i32 %68
}

; 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: 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) #3

declare zeroext i16 @hton16(i16 noundef zeroext) #4

declare i32 @lprintf(ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) #4

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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, !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 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !10, i64 12}
!14 = !{!"ether_hdr", !7, i64 0, !7, i64 6, !10, i64 12}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [59 x i8], align 1
@__func__.ether_transmit_helper = external hidden unnamed_addr constant [22 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [33 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 uwtable
define dso_local range(i32 -1, 1) i32 @ether_transmit_helper(ptr noundef %0, i16 noundef zeroext %1, ptr nocapture noundef readonly %2, i64 noundef %3, ptr nocapture noundef readonly %4, ptr nocapture noundef readonly %5) local_unnamed_addr #1 {
  %7 = alloca [1514 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 1514, ptr nonnull %7) #6
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(6) %7, ptr noundef nonnull align 1 dereferenceable(6) %4, i64 6, i1 false)
  %8 = getelementptr inbounds i8, ptr %7, i64 6
  %9 = getelementptr inbounds i8, ptr %0, i64 46
  %10 = getelementptr inbounds i8, ptr %7, i64 14
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 2 dereferenceable(1500) %10, i8 0, i64 1500, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 2 dereferenceable(6) %8, ptr noundef nonnull align 2 dereferenceable(6) %9, i64 6, i1 false)
  %11 = tail call zeroext i16 @hton16(i16 noundef zeroext %1) #6
  %12 = getelementptr inbounds i8, ptr %7, i64 12
  store i16 %11, ptr %12, align 4, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %7, i64 14
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 2 %13, ptr align 1 %2, i64 %3, i1 false)
  %spec.select = tail call i64 @llvm.usub.sat.i64(i64 46, i64 %3)
  %14 = add i64 %3, 14
  %15 = add i64 %14, %spec.select
  %16 = load ptr, ptr @stderr, align 8, !tbaa !10
  %17 = getelementptr inbounds i8, ptr %0, i64 20
  %18 = tail call ptr @ether_type_ntoa(i16 noundef zeroext %11)
  %19 = zext i16 %1 to i32
  %20 = tail call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %16, i32 noundef 68, ptr noundef nonnull @.str.1, i32 noundef 101, ptr noundef nonnull @__func__.ether_transmit_helper, ptr noundef nonnull @.str.2, ptr noundef nonnull %17, ptr noundef %18, i32 noundef %19, i64 noundef %15) #6
  call void @ether_dump(ptr noundef nonnull %7, i64 noundef %15)
  %21 = call i64 %5(ptr noundef %0, ptr noundef nonnull %7, i64 noundef %15) #6
  %22 = icmp ne i64 %21, %15
  %23 = sext i1 %22 to i32
  call void @llvm.lifetime.end.p0(i64 1514, ptr nonnull %7) #6
  ret i32 %23
}

; 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: mustprogress 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) #3

declare zeroext i16 @hton16(i16 noundef zeroext) local_unnamed_addr #4

declare i32 @lprintf(ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #4

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.usub.sat.i64(i64, i64) #5

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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 nosync nounwind speculatable willreturn memory(none) }
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, !9, i64 12}
!6 = !{!"ether_hdr", !7, i64 0, !7, i64 6, !9, i64 12}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"short", !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}


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