; LLVM IR from asllop/AppOS :: net (net)

; 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.NetIfaceStruct = type { i32, i8, i16, i8, i32, i32, i32, [128 x ptr], %struct.NetFragStruct, %struct.NetFragStruct }
%struct.NetFragStruct = type { i16, i8, [32 x ptr] }

@numNetInterfaces = external hidden global i32, align 4
@netInterfaces = external hidden global [1 x %struct.NetIfaceStruct], align 16

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @net_create(i32 noundef %0, i8 noundef zeroext %1) #0 {
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  %5 = alloca i8, align 1
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  %6 = load i32, ptr @numNetInterfaces, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 1
  br i1 %7, label %8, label %65

8:                                                ; preds = %2
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = load i32, ptr @numNetInterfaces, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [1 x %struct.NetIfaceStruct], ptr @netInterfaces, i64 0, i64 %11
  %13 = getelementptr inbounds %struct.NetIfaceStruct, ptr %12, i32 0, i32 0
  store i32 %9, ptr %13, align 8, !tbaa !10
  %14 = load i8, ptr %5, align 1, !tbaa !9
  %15 = load i32, ptr @numNetInterfaces, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [1 x %struct.NetIfaceStruct], ptr @netInterfaces, i64 0, i64 %16
  %18 = getelementptr inbounds %struct.NetIfaceStruct, ptr %17, i32 0, i32 1
  store i8 %14, ptr %18, align 4, !tbaa !14
  %19 = load i32, ptr %4, align 4, !tbaa !5
  switch i32 %19, label %40 [
    i32 2, label %20
    i32 3, label %25
    i32 0, label %30
    i32 1, label %30
    i32 4, label %35
  ]

20:                                               ; preds = %8
  %21 = load i32, ptr @numNetInterfaces, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1 x %struct.NetIfaceStruct], ptr @netInterfaces, i64 0, i64 %22
  %24 = getelementptr inbounds %struct.NetIfaceStruct, ptr %23, i32 0, i32 2
  store i16 296, ptr %24, align 2, !tbaa !15
  br label %45

25:                                               ; preds = %8
  %26 = load i32, ptr @numNetInterfaces, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [1 x %struct.NetIfaceStruct], ptr @netInterfaces, i64 0, i64 %27
  %29 = getelementptr inbounds %struct.NetIfaceStruct, ptr %28, i32 0, i32 2
  store i16 1492, ptr %29, align 2, !tbaa !15
  br label %45

30:                                               ; preds = %8, %8
  %31 = load i32, ptr @numNetInterfaces, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [1 x %struct.NetIfaceStruct], ptr @netInterfaces, i64 0, i64 %32
  %34 = getelementptr inbounds %struct.NetIfaceStruct, ptr %33, i32 0, i32 2
  store i16 1500, ptr %34, align 2, !tbaa !15
  br label %45

35:                                               ; preds = %8
  %36 = load i32, ptr @numNetInterfaces, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [1 x %struct.NetIfaceStruct], ptr @netInterfaces, i64 0, i64 %37
  %39 = getelementptr inbounds %struct.NetIfaceStruct, ptr %38, i32 0, i32 2
  store i16 672, ptr %39, align 2, !tbaa !15
  br label %45

40:                                               ; preds = %8
  %41 = load i32, ptr @numNetInterfaces, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [1 x %struct.NetIfaceStruct], ptr @netInterfaces, i64 0, i64 %42
  %44 = getelementptr inbounds %struct.NetIfaceStruct, ptr %43, i32 0, i32 2
  store i16 576, ptr %44, align 2, !tbaa !15
  br label %45

45:                                               ; preds = %40, %35, %30, %25, %20
  %46 = load i32, ptr @numNetInterfaces, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [1 x %struct.NetIfaceStruct], ptr @netInterfaces, i64 0, i64 %47
  %49 = getelementptr inbounds %struct.NetIfaceStruct, ptr %48, i32 0, i32 3
  store i8 0, ptr %49, align 8, !tbaa !16
  %50 = load i32, ptr @numNetInterfaces, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [1 x %struct.NetIfaceStruct], ptr @netInterfaces, i64 0, i64 %51
  %53 = getelementptr inbounds %struct.NetIfaceStruct, ptr %52, i32 0, i32 4
  store i32 0, ptr %53, align 4, !tbaa !17
  %54 = load i32, ptr @numNetInterfaces, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [1 x %struct.NetIfaceStruct], ptr @netInterfaces, i64 0, i64 %55
  %57 = getelementptr inbounds %struct.NetIfaceStruct, ptr %56, i32 0, i32 5
  store i32 -1, ptr %57, align 8, !tbaa !18
  %58 = load i32, ptr @numNetInterfaces, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [1 x %struct.NetIfaceStruct], ptr @netInterfaces, i64 0, i64 %59
  %61 = getelementptr inbounds %struct.NetIfaceStruct, ptr %60, i32 0, i32 6
  store i32 0, ptr %61, align 4, !tbaa !19
  %62 = load i32, ptr @numNetInterfaces, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr @numNetInterfaces, align 4, !tbaa !5
  %64 = trunc i32 %62 to i8
  store i8 %64, ptr %3, align 1
  br label %66

65:                                               ; preds = %2
  store i8 -1, ptr %3, align 1
  br label %66

66:                                               ; preds = %65, %45
  %67 = load i8, ptr %3, align 1
  ret i8 %67
}

attributes #0 = { 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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 0}
!11 = !{!"NetIfaceStruct", !6, i64 0, !7, i64 4, !12, i64 6, !7, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !7, i64 24, !13, i64 1048, !13, i64 1312}
!12 = !{!"short", !7, i64 0}
!13 = !{!"NetFragStruct", !12, i64 0, !7, i64 2, !7, i64 8}
!14 = !{!11, !7, i64 4}
!15 = !{!11, !12, i64 6}
!16 = !{!11, !7, i64 8}
!17 = !{!11, !6, i64 12}
!18 = !{!11, !6, i64 16}
!19 = !{!11, !6, i64 20}


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

%struct.NetIfaceStruct = type { i32, i8, i16, i8, i32, i32, i32, [128 x ptr], %struct.NetFragStruct, %struct.NetFragStruct }
%struct.NetFragStruct = type { i16, i8, [32 x ptr] }

@numNetInterfaces = external hidden local_unnamed_addr global i32, align 4
@netInterfaces = external hidden local_unnamed_addr global [1 x %struct.NetIfaceStruct], align 16
@switch.table.net_create = private unnamed_addr constant [5 x i16] [i16 1500, i16 1500, i16 296, i16 1492, i16 672], align 2

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local zeroext i8 @net_create(i32 noundef %0, i8 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @numNetInterfaces, align 4, !tbaa !5
  %4 = icmp slt i32 %3, 1
  br i1 %4, label %5, label %19

5:                                                ; preds = %2
  %6 = sext i32 %3 to i64
  %7 = getelementptr inbounds [1 x %struct.NetIfaceStruct], ptr @netInterfaces, i64 0, i64 %6
  store i32 %0, ptr %7, align 8, !tbaa !9
  %8 = getelementptr inbounds [1 x %struct.NetIfaceStruct], ptr @netInterfaces, i64 0, i64 %6, i32 1
  store i8 %1, ptr %8, align 4, !tbaa !13
  %9 = icmp ult i32 %0, 5
  br i1 %9, label %switch.lookup, label %11

switch.lookup:                                    ; preds = %5
  %10 = zext nneg i32 %0 to i64
  %switch.gep = getelementptr inbounds [5 x i16], ptr @switch.table.net_create, i64 0, i64 %10
  %switch.load = load i16, ptr %switch.gep, align 2
  br label %11

11:                                               ; preds = %5, %switch.lookup
  %.sink = phi i16 [ %switch.load, %switch.lookup ], [ 576, %5 ]
  %12 = getelementptr inbounds [1 x %struct.NetIfaceStruct], ptr @netInterfaces, i64 0, i64 %6, i32 2
  store i16 %.sink, ptr %12, align 2, !tbaa !14
  %13 = getelementptr inbounds [1 x %struct.NetIfaceStruct], ptr @netInterfaces, i64 0, i64 %6, i32 3
  store i8 0, ptr %13, align 8, !tbaa !15
  %14 = getelementptr inbounds [1 x %struct.NetIfaceStruct], ptr @netInterfaces, i64 0, i64 %6, i32 4
  store i32 0, ptr %14, align 4, !tbaa !16
  %15 = getelementptr inbounds [1 x %struct.NetIfaceStruct], ptr @netInterfaces, i64 0, i64 %6, i32 5
  store i32 -1, ptr %15, align 8, !tbaa !17
  %16 = getelementptr inbounds [1 x %struct.NetIfaceStruct], ptr @netInterfaces, i64 0, i64 %6, i32 6
  store i32 0, ptr %16, align 4, !tbaa !18
  %17 = add nsw i32 %3, 1
  store i32 %17, ptr @numNetInterfaces, align 4, !tbaa !5
  %18 = trunc i32 %3 to i8
  br label %19

19:                                               ; preds = %2, %11
  %.0 = phi i8 [ %18, %11 ], [ -1, %2 ]
  ret i8 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) 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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"NetIfaceStruct", !6, i64 0, !7, i64 4, !11, i64 6, !7, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !7, i64 24, !12, i64 1048, !12, i64 1312}
!11 = !{!"short", !7, i64 0}
!12 = !{!"NetFragStruct", !11, i64 0, !7, i64 2, !7, i64 8}
!13 = !{!10, !7, i64 4}
!14 = !{!10, !11, i64 6}
!15 = !{!10, !7, i64 8}
!16 = !{!10, !6, i64 12}
!17 = !{!10, !6, i64 16}
!18 = !{!10, !6, i64 20}


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