; LLVM IR from lfarcaro/ARINC653_ARMV7A_AM335X :: ARINC653_PORT (ethernet)

; 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._ETHERNET_CPSW_INSTANCE = type { i8, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, [1 x %struct._ETHERNET_CPSW_PORT] }
%struct._ETHERNET_CPSW_PORT = type { i8, i32, i32, i32, i8, i32, i32 }

@ETHERNET_CPSW_INSTANCES = external hidden global [1 x %struct._ETHERNET_CPSW_INSTANCE], align 16
@ETHERNET_POLLING_MODE = external hidden global 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 zeroext i8 @ETHERNET_STARTUP(i8 noundef zeroext %0) #1 {
  %2 = alloca i8, align 1
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i8 %0, ptr %3, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !8
  br label %6

6:                                                ; preds = %14, %1
  %7 = load i32, ptr %4, align 4, !tbaa !8
  %8 = icmp ult i32 %7, 1
  br i1 %8, label %9, label %17

9:                                                ; preds = %6
  %10 = load i32, ptr %4, align 4, !tbaa !8
  %11 = zext i32 %10 to i64
  %12 = getelementptr inbounds [1 x %struct._ETHERNET_CPSW_INSTANCE], ptr @ETHERNET_CPSW_INSTANCES, i64 0, i64 %11
  %13 = getelementptr inbounds %struct._ETHERNET_CPSW_INSTANCE, ptr %12, i32 0, i32 0
  store i8 0, ptr %13, align 8, !tbaa !10
  br label %14

14:                                               ; preds = %9
  %15 = load i32, ptr %4, align 4, !tbaa !8
  %16 = add i32 %15, 1
  store i32 %16, ptr %4, align 4, !tbaa !8
  br label %6, !llvm.loop !13

17:                                               ; preds = %6
  %18 = load i8, ptr %3, align 1, !tbaa !5
  store i8 %18, ptr @ETHERNET_POLLING_MODE, align 1, !tbaa !5
  call void @CPSWPinMuxSetup()
  call void @CPSWClkEnable()
  call void @EVMPortMIIModeSelect()
  call void @ETHERNET_HOOK_YIELD()
  %19 = load i8, ptr %3, align 1, !tbaa !5
  %20 = icmp ne i8 %19, 0
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  call void @IntRegister(i32 noundef 42, ptr noundef @ETHERNET_CPSW_CORE0TXISR)
  call void @IntRegister(i32 noundef 41, ptr noundef @ETHERNET_CPSW_CORE0RXISR)
  call void @IntPrioritySet(i32 noundef 42, i32 noundef 0, i32 noundef 0)
  call void @IntPrioritySet(i32 noundef 41, i32 noundef 0, i32 noundef 0)
  call void @IntSystemEnable(i32 noundef 42)
  call void @IntSystemEnable(i32 noundef 41)
  br label %22

22:                                               ; preds = %21, %17
  call void @ETHERNET_HOOK_YIELD()
  %23 = call zeroext i8 @ETHERNET_HOOK_INITIALIZE()
  %24 = icmp ne i8 %23, 0
  br i1 %24, label %26, label %25

25:                                               ; preds = %22
  store i8 0, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %27

26:                                               ; preds = %22
  store i8 1, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %27

27:                                               ; preds = %26, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %28 = load i8, ptr %2, align 1
  ret i8 %28
}

declare void @CPSWPinMuxSetup() #2

declare void @CPSWClkEnable() #2

declare void @EVMPortMIIModeSelect() #2

declare void @ETHERNET_HOOK_YIELD() #2

declare void @IntRegister(i32 noundef, ptr noundef) #2

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

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

declare void @IntPrioritySet(i32 noundef, i32 noundef, i32 noundef) #2

declare void @IntSystemEnable(i32 noundef) #2

declare zeroext i8 @ETHERNET_HOOK_INITIALIZE() #2

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 = { "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = !{!11, !6, i64 0}
!11 = !{!"_ETHERNET_CPSW_INSTANCE", !6, i64 0, !9, i64 4, !9, i64 8, !9, i64 12, !9, i64 16, !9, i64 20, !9, i64 24, !9, i64 28, !9, i64 32, !9, i64 36, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !6, i64 88}
!12 = !{!"any pointer", !6, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

%struct._ETHERNET_CPSW_INSTANCE = type { i8, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, [1 x %struct._ETHERNET_CPSW_PORT] }
%struct._ETHERNET_CPSW_PORT = type { i8, i32, i32, i32, i8, i32, i32 }

@ETHERNET_CPSW_INSTANCES = external hidden local_unnamed_addr global [1 x %struct._ETHERNET_CPSW_INSTANCE], align 16
@ETHERNET_POLLING_MODE = external hidden local_unnamed_addr global i8, align 1

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @ETHERNET_STARTUP(i8 noundef zeroext %0) local_unnamed_addr #0 {
.critedge:
  store i8 0, ptr @ETHERNET_CPSW_INSTANCES, align 16, !tbaa !5
  store i8 %0, ptr @ETHERNET_POLLING_MODE, align 1, !tbaa !11
  tail call void @CPSWPinMuxSetup() #2
  tail call void @CPSWClkEnable() #2
  tail call void @EVMPortMIIModeSelect() #2
  tail call void @ETHERNET_HOOK_YIELD() #2
  %.not = icmp eq i8 %0, 0
  br i1 %.not, label %1, label %2

1:                                                ; preds = %.critedge
  tail call void @IntRegister(i32 noundef 42, ptr noundef nonnull @ETHERNET_CPSW_CORE0TXISR) #2
  tail call void @IntRegister(i32 noundef 41, ptr noundef nonnull @ETHERNET_CPSW_CORE0RXISR) #2
  tail call void @IntPrioritySet(i32 noundef 42, i32 noundef 0, i32 noundef 0) #2
  tail call void @IntPrioritySet(i32 noundef 41, i32 noundef 0, i32 noundef 0) #2
  tail call void @IntSystemEnable(i32 noundef 42) #2
  tail call void @IntSystemEnable(i32 noundef 41) #2
  br label %2

2:                                                ; preds = %1, %.critedge
  tail call void @ETHERNET_HOOK_YIELD() #2
  %3 = tail call zeroext i8 @ETHERNET_HOOK_INITIALIZE() #2
  %.not7 = icmp ne i8 %3, 0
  %. = zext i1 %.not7 to i8
  ret i8 %.
}

declare void @CPSWPinMuxSetup() local_unnamed_addr #1

declare void @CPSWClkEnable() local_unnamed_addr #1

declare void @EVMPortMIIModeSelect() local_unnamed_addr #1

declare void @ETHERNET_HOOK_YIELD() local_unnamed_addr #1

declare void @IntRegister(i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @ETHERNET_CPSW_CORE0TXISR() #0

; Function Attrs: nounwind uwtable
declare hidden void @ETHERNET_CPSW_CORE0RXISR() #0

declare void @IntPrioritySet(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare void @IntSystemEnable(i32 noundef) local_unnamed_addr #1

declare zeroext i8 @ETHERNET_HOOK_INITIALIZE() local_unnamed_addr #1

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

!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, !7, i64 0}
!6 = !{!"_ETHERNET_CPSW_INSTANCE", !7, i64 0, !9, i64 4, !9, i64 8, !9, i64 12, !9, i64 16, !9, i64 20, !9, i64 24, !9, i64 28, !9, i64 32, !9, i64 36, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !7, i64 88}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}


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