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

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

@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_protocol_register = external hidden unnamed_addr constant [22 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [28 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_protocol_register(ptr noundef %0, i16 noundef zeroext %1, ptr noundef %2) #3 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i16, align 2
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i16 %1, ptr %6, align 2, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %10 = load ptr, ptr @protocols, align 8, !tbaa !5
  store ptr %10, ptr %8, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %36, %3
  %12 = load ptr, ptr %8, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %40

14:                                               ; preds = %11
  %15 = load i16, ptr %6, align 2, !tbaa !9
  %16 = zext i16 %15 to i32
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.net_protocol, ptr %17, i32 0, i32 2
  %19 = load i16, ptr %18, align 8, !tbaa !11
  %20 = zext i16 %19 to i32
  %21 = icmp eq i32 %16, %20
  br i1 %21, label %22, label %35

22:                                               ; preds = %14
  %23 = load ptr, ptr @stderr, align 8, !tbaa !5
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load i16, ptr %6, align 2, !tbaa !9
  %26 = zext i16 %25 to i32
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.net_protocol, ptr %27, i32 0, i32 1
  %29 = getelementptr inbounds [16 x i8], ptr %28, i64 0, i64 0
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.net_protocol, ptr %30, i32 0, i32 2
  %32 = load i16, ptr %31, align 8, !tbaa !11
  %33 = zext i16 %32 to i32
  %34 = call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %23, i32 noundef 69, ptr noundef @.str, i32 noundef 204, ptr noundef @__func__.net_protocol_register, ptr noundef @.str.11, ptr noundef %24, i32 noundef %26, ptr noundef %29, i32 noundef %33)
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %70

35:                                               ; preds = %14
  br label %36

36:                                               ; preds = %35
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.net_protocol, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !15
  store ptr %39, ptr %8, align 8, !tbaa !5
  br label %11, !llvm.loop !16

40:                                               ; preds = %11
  %41 = call ptr @memory_alloc(i64 noundef 64)
  store ptr %41, ptr %8, align 8, !tbaa !5
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = icmp ne ptr %42, null
  br i1 %43, label %47, label %44

44:                                               ; preds = %40
  %45 = load ptr, ptr @stderr, align 8, !tbaa !5
  %46 = call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %45, i32 noundef 69, ptr noundef @.str, i32 noundef 210, ptr noundef @__func__.net_protocol_register, ptr noundef @.str.1)
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %70

47:                                               ; preds = %40
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.net_protocol, ptr %48, i32 0, i32 1
  %50 = getelementptr inbounds [16 x i8], ptr %49, i64 0, i64 0
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = call ptr @strncpy(ptr noundef %50, ptr noundef %51, i64 noundef 15) #5
  %53 = load i16, ptr %6, align 2, !tbaa !9
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.net_protocol, ptr %54, i32 0, i32 2
  store i16 %53, ptr %55, align 8, !tbaa !11
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.net_protocol, ptr %57, i32 0, i32 4
  store ptr %56, ptr %58, align 8, !tbaa !18
  %59 = load ptr, ptr @protocols, align 8, !tbaa !5
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.net_protocol, ptr %60, i32 0, i32 0
  store ptr %59, ptr %61, align 8, !tbaa !15
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %62, ptr @protocols, align 8, !tbaa !5
  %63 = load ptr, ptr @stderr, align 8, !tbaa !5
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.net_protocol, ptr %64, i32 0, i32 1
  %66 = getelementptr inbounds [16 x i8], ptr %65, i64 0, i64 0
  %67 = load i16, ptr %6, align 2, !tbaa !9
  %68 = zext i16 %67 to i32
  %69 = call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %63, i32 noundef 73, ptr noundef @.str, i32 noundef 218, ptr noundef @__func__.net_protocol_register, ptr noundef @.str.12, ptr noundef %66, i32 noundef %68)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %70

70:                                               ; preds = %47, %44, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %71 = load i32, ptr %4, align 4
  ret i32 %71
}

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

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 = { 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 #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, !10, i64 24}
!12 = !{!"net_protocol", !6, i64 0, !7, i64 8, !10, i64 24, !13, i64 32, !6, i64 56}
!13 = !{!"queue_head", !6, i64 0, !6, i64 8, !14, i64 16}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !6, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!12, !6, i64 56}


; 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_protocol_register = external hidden unnamed_addr constant [22 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [28 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_protocol_register(ptr noundef %0, i16 noundef zeroext %1, ptr noundef %2) local_unnamed_addr #2 {
  br label %4

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

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

9:                                                ; preds = %5
  %10 = zext i16 %1 to i32
  %11 = load ptr, ptr @stderr, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %.0, i64 8
  %13 = tail call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %11, i32 noundef 69, ptr noundef nonnull @.str, i32 noundef 204, ptr noundef nonnull @__func__.net_protocol_register, ptr noundef nonnull @.str.11, ptr noundef %0, i32 noundef %10, ptr noundef nonnull %12, i32 noundef %10) #4
  br label %28

14:                                               ; preds = %4
  %15 = tail call ptr @memory_alloc(i64 noundef 64)
  %.not23 = icmp eq ptr %15, null
  br i1 %.not23, label %16, label %19

16:                                               ; preds = %14
  %17 = load ptr, ptr @stderr, align 8, !tbaa !5
  %18 = tail call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %17, i32 noundef 69, ptr noundef nonnull @.str, i32 noundef 210, ptr noundef nonnull @__func__.net_protocol_register, ptr noundef nonnull @.str.1) #4
  br label %28

19:                                               ; preds = %14
  %20 = getelementptr inbounds i8, ptr %15, i64 8
  %21 = tail call ptr @strncpy(ptr noundef nonnull dereferenceable(1) %20, ptr noundef nonnull dereferenceable(1) %0, i64 noundef 15) #4
  %22 = getelementptr inbounds i8, ptr %15, i64 24
  store i16 %1, ptr %22, align 8, !tbaa !9
  %23 = getelementptr inbounds i8, ptr %15, i64 56
  store ptr %2, ptr %23, align 8, !tbaa !16
  %24 = load ptr, ptr @protocols, align 8, !tbaa !5
  store ptr %24, ptr %15, align 8, !tbaa !17
  store ptr %15, ptr @protocols, align 8, !tbaa !5
  %25 = load ptr, ptr @stderr, align 8, !tbaa !5
  %26 = zext i16 %1 to i32
  %27 = tail call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %25, i32 noundef 73, ptr noundef nonnull @.str, i32 noundef 218, ptr noundef nonnull @__func__.net_protocol_register, ptr noundef nonnull @.str.12, ptr noundef nonnull %20, i32 noundef %26) #4
  br label %28

28:                                               ; preds = %19, %16, %9
  %.019 = phi i32 [ -1, %9 ], [ 0, %19 ], [ -1, %16 ]
  ret i32 %.019
}

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

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 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 #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 = !{!10, !6, i64 56}
!17 = !{!10, !6, i64 0}


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