; LLVM IR from pandax381/microps :: net (net_input_handler)

; 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_protocol = type { ptr, [16 x i8], i16, %struct.queue_head, ptr }
%struct.queue_head = type { ptr, ptr, i32 }
%struct.net_protocol_queue_entry = type { ptr, i64 }
%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 = external hidden unnamed_addr constant [57 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1
@protocols = external hidden global ptr, align 8
@__func__.net_input_handler = external hidden unnamed_addr constant [18 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [56 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: inlinehint nounwind uwtable
declare hidden ptr @memory_alloc(i64 noundef) #1

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

; 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 @net_input_handler(i16 noundef zeroext %0, ptr noundef %1, i64 noundef %2, ptr noundef %3) #3 {
  %5 = alloca i32, align 4
  %6 = alloca i16, align 2
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store i16 %0, ptr %6, align 2, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !9
  store i64 %2, ptr %8, align 8, !tbaa !11
  store ptr %3, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %13 = load ptr, ptr @protocols, align 8, !tbaa !9
  store ptr %13, ptr %10, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %71, %4
  %15 = load ptr, ptr %10, align 8, !tbaa !9
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %75

17:                                               ; preds = %14
  %18 = load ptr, ptr %10, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.net_protocol, ptr %18, i32 0, i32 2
  %20 = load i16, ptr %19, align 8, !tbaa !13
  %21 = zext i16 %20 to i32
  %22 = load i16, ptr %6, align 2, !tbaa !5
  %23 = zext i16 %22 to i32
  %24 = icmp eq i32 %21, %23
  br i1 %24, label %25, label %70

25:                                               ; preds = %17
  %26 = load i64, ptr %8, align 8, !tbaa !11
  %27 = add i64 16, %26
  %28 = call ptr @memory_alloc(i64 noundef %27)
  store ptr %28, ptr %11, align 8, !tbaa !9
  %29 = load ptr, ptr %11, align 8, !tbaa !9
  %30 = icmp ne ptr %29, null
  br i1 %30, label %34, label %31

31:                                               ; preds = %25
  %32 = load ptr, ptr @stderr, align 8, !tbaa !9
  %33 = call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %32, i32 noundef 69, ptr noundef @.str, i32 noundef 175, ptr noundef @__func__.net_input_handler, ptr noundef @.str.1)
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %76

34:                                               ; preds = %25
  %35 = load ptr, ptr %9, align 8, !tbaa !9
  %36 = load ptr, ptr %11, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.net_protocol_queue_entry, ptr %36, i32 0, i32 0
  store ptr %35, ptr %37, align 8, !tbaa !17
  %38 = load i64, ptr %8, align 8, !tbaa !11
  %39 = load ptr, ptr %11, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.net_protocol_queue_entry, ptr %39, i32 0, i32 1
  store i64 %38, ptr %40, align 8, !tbaa !19
  %41 = load ptr, ptr %11, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.net_protocol_queue_entry, ptr %41, i64 1
  %43 = load ptr, ptr %7, align 8, !tbaa !9
  %44 = load i64, ptr %8, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %42, ptr align 1 %43, i64 %44, i1 false)
  %45 = load ptr, ptr %10, align 8, !tbaa !9
  %46 = getelementptr inbounds %struct.net_protocol, ptr %45, i32 0, i32 3
  %47 = load ptr, ptr %11, align 8, !tbaa !9
  %48 = call ptr @queue_push(ptr noundef %46, ptr noundef %47)
  %49 = icmp ne ptr %48, null
  br i1 %49, label %54, label %50

50:                                               ; preds = %34
  %51 = load ptr, ptr @stderr, align 8, !tbaa !9
  %52 = call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %51, i32 noundef 69, ptr noundef @.str, i32 noundef 182, ptr noundef @__func__.net_input_handler, ptr noundef @.str.9)
  %53 = load ptr, ptr %11, align 8, !tbaa !9
  call void @memory_free(ptr noundef %53)
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %76

54:                                               ; preds = %34
  %55 = load ptr, ptr @stderr, align 8, !tbaa !9
  %56 = load ptr, ptr %10, align 8, !tbaa !9
  %57 = getelementptr inbounds %struct.net_protocol, ptr %56, i32 0, i32 3
  %58 = getelementptr inbounds %struct.queue_head, ptr %57, i32 0, i32 2
  %59 = load i32, ptr %58, align 8, !tbaa !20
  %60 = load ptr, ptr %9, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct.net_device, ptr %60, i32 0, i32 3
  %62 = getelementptr inbounds [16 x i8], ptr %61, i64 0, i64 0
  %63 = load ptr, ptr %10, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.net_protocol, ptr %63, i32 0, i32 1
  %65 = getelementptr inbounds [16 x i8], ptr %64, i64 0, i64 0
  %66 = load i16, ptr %6, align 2, !tbaa !5
  %67 = zext i16 %66 to i32
  %68 = load i64, ptr %8, align 8, !tbaa !11
  %69 = call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %55, i32 noundef 68, ptr noundef @.str, i32 noundef 186, ptr noundef @__func__.net_input_handler, ptr noundef @.str.10, i32 noundef %59, ptr noundef %62, ptr noundef %65, i32 noundef %67, i64 noundef %68)
  call void @raise_softirq()
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %76

70:                                               ; preds = %17
  br label %71

71:                                               ; preds = %70
  %72 = load ptr, ptr %10, align 8, !tbaa !9
  %73 = getelementptr inbounds %struct.net_protocol, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !21
  store ptr %74, ptr %10, align 8, !tbaa !9
  br label %14, !llvm.loop !22

75:                                               ; preds = %14
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %76

76:                                               ; preds = %75, %54, %50, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %77 = load i32, ptr %5, align 4
  ret i32 %77
}

; 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) #4

declare ptr @queue_push(ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @memory_free(ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @raise_softirq() #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 24}
!14 = !{!"net_protocol", !10, i64 0, !7, i64 8, !6, i64 24, !15, i64 32, !10, i64 56}
!15 = !{!"queue_head", !10, i64 0, !10, i64 8, !16, i64 16}
!16 = !{!"int", !7, i64 0}
!17 = !{!18, !10, i64 0}
!18 = !{!"net_protocol_queue_entry", !10, i64 0, !12, i64 8}
!19 = !{!18, !12, i64 8}
!20 = !{!14, !16, i64 48}
!21 = !{!14, !10, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [57 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1
@protocols = external hidden local_unnamed_addr global ptr, align 8
@__func__.net_input_handler = external hidden unnamed_addr constant [18 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [56 x i8], align 1

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @memory_alloc(i64 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @net_input_handler(i16 noundef zeroext %0, ptr nocapture noundef readonly %1, i64 noundef %2, ptr noundef %3) local_unnamed_addr #2 {
  br label %5

5:                                                ; preds = %6, %4
  %.021.in = phi ptr [ @protocols, %4 ], [ %.021, %6 ]
  %.021 = load ptr, ptr %.021.in, align 8, !tbaa !5
  %.not = icmp eq ptr %.021, null
  br i1 %.not, label %.loopexit, label %6

6:                                                ; preds = %5
  %7 = getelementptr inbounds i8, ptr %.021, i64 24
  %8 = load i16, ptr %7, align 8, !tbaa !9
  %9 = icmp eq i16 %8, %0
  br i1 %9, label %10, label %5, !llvm.loop !14

10:                                               ; preds = %6
  %11 = zext i16 %0 to i32
  %12 = add i64 %2, 16
  %13 = tail call ptr @memory_alloc(i64 noundef %12)
  %.not24 = icmp eq ptr %13, null
  br i1 %.not24, label %14, label %17

14:                                               ; preds = %10
  %15 = load ptr, ptr @stderr, align 8, !tbaa !5
  %16 = tail call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %15, i32 noundef 69, ptr noundef nonnull @.str, i32 noundef 175, ptr noundef nonnull @__func__.net_input_handler, ptr noundef nonnull @.str.1) #4
  br label %.loopexit

17:                                               ; preds = %10
  store ptr %3, ptr %13, align 8, !tbaa !16
  %18 = getelementptr inbounds i8, ptr %13, i64 8
  store i64 %2, ptr %18, align 8, !tbaa !19
  %19 = getelementptr inbounds i8, ptr %13, i64 16
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 %19, ptr align 1 %1, i64 %2, i1 false)
  %20 = getelementptr inbounds i8, ptr %.021, i64 32
  %21 = tail call ptr @queue_push(ptr noundef nonnull %20, ptr noundef nonnull %13) #4
  %.not25 = icmp eq ptr %21, null
  %22 = load ptr, ptr @stderr, align 8, !tbaa !5
  br i1 %.not25, label %23, label %25

23:                                               ; preds = %17
  %24 = tail call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %22, i32 noundef 69, ptr noundef nonnull @.str, i32 noundef 182, ptr noundef nonnull @__func__.net_input_handler, ptr noundef nonnull @.str.9) #4
  tail call void @memory_free(ptr noundef nonnull %13)
  br label %.loopexit

25:                                               ; preds = %17
  %26 = getelementptr inbounds i8, ptr %.021, i64 48
  %27 = load i32, ptr %26, align 8, !tbaa !20
  %28 = getelementptr inbounds i8, ptr %3, i64 20
  %29 = getelementptr inbounds i8, ptr %.021, i64 8
  %30 = tail call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %22, i32 noundef 68, ptr noundef nonnull @.str, i32 noundef 186, ptr noundef nonnull @__func__.net_input_handler, ptr noundef nonnull @.str.10, i32 noundef %27, ptr noundef nonnull %28, ptr noundef nonnull %29, i32 noundef %11, i64 noundef %2) #4
  tail call void @raise_softirq()
  br label %.loopexit

.loopexit:                                        ; preds = %5, %25, %23, %14
  %.0 = phi i32 [ 0, %25 ], [ -1, %23 ], [ -1, %14 ], [ 0, %5 ]
  ret i32 %.0
}

; 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 ptr @queue_push(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @memory_free(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @raise_softirq() local_unnamed_addr #0

attributes #0 = { 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 #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 24}
!10 = !{!"net_protocol", !6, i64 0, !7, i64 8, !11, i64 24, !12, i64 32, !6, i64 56}
!11 = !{!"short", !7, i64 0}
!12 = !{!"queue_head", !6, i64 0, !6, i64 8, !13, i64 16}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !6, i64 0}
!17 = !{!"net_protocol_queue_entry", !6, i64 0, !18, i64 8}
!18 = !{!"long", !7, i64 0}
!19 = !{!17, !18, i64 8}
!20 = !{!10, !13, i64 48}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass