; LLVM IR from pandax381/microps :: net (net_protocol_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
@protocols = external hidden global ptr, align 8
@__func__.net_protocol_handler = external hidden unnamed_addr constant [21 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [52 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

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

; 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_protocol_handler() #2 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %4 = load ptr, ptr @protocols, align 8, !tbaa !5
  store ptr %4, ptr %1, align 8, !tbaa !5
  br label %5

5:                                                ; preds = %50, %0
  %6 = load ptr, ptr %1, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %8, label %54

8:                                                ; preds = %5
  br label %9

9:                                                ; preds = %17, %8
  br label %10

10:                                               ; preds = %9
  %11 = load ptr, ptr %1, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.net_protocol, ptr %11, i32 0, i32 3
  %13 = call ptr @queue_pop(ptr noundef %12)
  store ptr %13, ptr %2, align 8, !tbaa !5
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %17, label %16

16:                                               ; preds = %10
  br label %49

17:                                               ; preds = %10
  %18 = load ptr, ptr %1, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.net_protocol, ptr %18, i32 0, i32 3
  %20 = getelementptr inbounds %struct.queue_head, ptr %19, i32 0, i32 2
  %21 = load i32, ptr %20, align 8, !tbaa !9
  store i32 %21, ptr %3, align 4, !tbaa !14
  %22 = load ptr, ptr @stderr, align 8, !tbaa !5
  %23 = load i32, ptr %3, align 4, !tbaa !14
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.net_protocol_queue_entry, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !15
  %27 = getelementptr inbounds %struct.net_device, ptr %26, i32 0, i32 3
  %28 = getelementptr inbounds [16 x i8], ptr %27, i64 0, i64 0
  %29 = load ptr, ptr %1, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.net_protocol, ptr %29, i32 0, i32 2
  %31 = load i16, ptr %30, align 8, !tbaa !18
  %32 = zext i16 %31 to i32
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.net_protocol_queue_entry, ptr %33, i32 0, i32 1
  %35 = load i64, ptr %34, align 8, !tbaa !19
  %36 = call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %22, i32 noundef 68, ptr noundef @.str, i32 noundef 249, ptr noundef @__func__.net_protocol_handler, ptr noundef @.str.14, i32 noundef %23, ptr noundef %28, i32 noundef %32, i64 noundef %35)
  %37 = load ptr, ptr %1, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.net_protocol, ptr %37, i32 0, i32 4
  %39 = load ptr, ptr %38, align 8, !tbaa !20
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.net_protocol_queue_entry, ptr %40, i64 1
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.net_protocol_queue_entry, ptr %42, i32 0, i32 1
  %44 = load i64, ptr %43, align 8, !tbaa !19
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.net_protocol_queue_entry, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !15
  call void %39(ptr noundef %41, i64 noundef %44, ptr noundef %47)
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %48) #4
  br label %9

49:                                               ; preds = %16
  br label %50

50:                                               ; preds = %49
  %51 = load ptr, ptr %1, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.net_protocol, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !21
  store ptr %53, ptr %1, align 8, !tbaa !5
  br label %5, !llvm.loop !22

54:                                               ; preds = %5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  ret i32 0
}

declare ptr @queue_pop(ptr noundef) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

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 "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, !13, i64 48}
!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 = !{!13, !13, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"net_protocol_queue_entry", !6, i64 0, !17, i64 8}
!17 = !{!"long", !7, i64 0}
!18 = !{!10, !11, i64 24}
!19 = !{!16, !17, i64 8}
!20 = !{!10, !6, i64 56}
!21 = !{!10, !6, 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
@protocols = external hidden local_unnamed_addr global ptr, align 8
@__func__.net_protocol_handler = external hidden unnamed_addr constant [21 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [52 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @net_protocol_handler() local_unnamed_addr #1 {
  %.016 = load ptr, ptr @protocols, align 8, !tbaa !5
  %.not17 = icmp eq ptr %.016, null
  br i1 %.not17, label %._crit_edge, label %.preheader

.loopexit:                                        ; preds = %6, %.preheader
  %.0 = load ptr, ptr %.018, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge, label %.preheader, !llvm.loop !9

.preheader:                                       ; preds = %0, %.loopexit
  %.018 = phi ptr [ %.0, %.loopexit ], [ %.016, %0 ]
  %1 = getelementptr inbounds i8, ptr %.018, i64 32
  %2 = tail call ptr @queue_pop(ptr noundef nonnull %1) #3
  %.not1415 = icmp eq ptr %2, null
  br i1 %.not1415, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %3 = getelementptr inbounds i8, ptr %.018, i64 48
  %4 = getelementptr inbounds i8, ptr %.018, i64 24
  %5 = getelementptr inbounds i8, ptr %.018, i64 56
  br label %6

6:                                                ; preds = %.lr.ph, %6
  %7 = phi ptr [ %2, %.lr.ph ], [ %21, %6 ]
  %8 = load i32, ptr %3, align 8, !tbaa !11
  %9 = load ptr, ptr @stderr, align 8, !tbaa !5
  %10 = load ptr, ptr %7, align 8, !tbaa !16
  %11 = getelementptr inbounds i8, ptr %10, i64 20
  %12 = load i16, ptr %4, align 8, !tbaa !19
  %13 = zext i16 %12 to i32
  %14 = getelementptr inbounds i8, ptr %7, i64 8
  %15 = load i64, ptr %14, align 8, !tbaa !20
  %16 = tail call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %9, i32 noundef 68, ptr noundef nonnull @.str, i32 noundef 249, ptr noundef nonnull @__func__.net_protocol_handler, ptr noundef nonnull @.str.14, i32 noundef %8, ptr noundef nonnull %11, i32 noundef %13, i64 noundef %15) #3
  %17 = load ptr, ptr %5, align 8, !tbaa !21
  %18 = getelementptr inbounds i8, ptr %7, i64 16
  %19 = load i64, ptr %14, align 8, !tbaa !20
  %20 = load ptr, ptr %7, align 8, !tbaa !16
  tail call void %17(ptr noundef nonnull %18, i64 noundef %19, ptr noundef %20) #3
  tail call void @free(ptr noundef nonnull %7) #3
  %21 = tail call ptr @queue_pop(ptr noundef nonnull %1) #3
  %.not14 = icmp eq ptr %21, null
  br i1 %.not14, label %.loopexit, label %6

._crit_edge:                                      ; preds = %.loopexit, %0
  ret i32 0
}

declare ptr @queue_pop(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

attributes #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 = { 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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !15, i64 48}
!12 = !{!"net_protocol", !6, i64 0, !7, i64 8, !13, i64 24, !14, i64 32, !6, i64 56}
!13 = !{!"short", !7, i64 0}
!14 = !{!"queue_head", !6, i64 0, !6, i64 8, !15, i64 16}
!15 = !{!"int", !7, i64 0}
!16 = !{!17, !6, i64 0}
!17 = !{!"net_protocol_queue_entry", !6, i64 0, !18, i64 8}
!18 = !{!"long", !7, i64 0}
!19 = !{!12, !13, i64 24}
!20 = !{!17, !18, i64 8}
!21 = !{!12, !6, i64 56}


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