; 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

; 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

declare void @ETHERNET_HOOK_YIELD() #1

declare void @ETHERNET_HOOK_DELAY(i32 noundef) #1

declare i32 @PhyLinkStatusGet(i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @ETHERNET_INSTANCE_PORT_ISLINKUP(i32 noundef %0, i32 noundef %1, i32 noundef %2) #2 {
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = icmp uge i32 %12, 1
  br i1 %13, label %14, label %15

14:                                               ; preds = %3
  store i8 0, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %73

15:                                               ; preds = %3
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = zext i32 %16 to i64
  %18 = getelementptr inbounds [1 x %struct._ETHERNET_CPSW_INSTANCE], ptr @ETHERNET_CPSW_INSTANCES, i64 0, i64 %17
  store ptr %18, ptr %8, align 8, !tbaa !9
  %19 = load ptr, ptr %8, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct._ETHERNET_CPSW_INSTANCE, ptr %19, i32 0, i32 0
  %21 = load i8, ptr %20, align 8, !tbaa !11
  %22 = icmp ne i8 %21, 0
  br i1 %22, label %24, label %23

23:                                               ; preds = %15
  store i8 0, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %73

24:                                               ; preds = %15
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = sub i32 %25, 1
  %27 = icmp uge i32 %26, 1
  br i1 %27, label %28, label %29

28:                                               ; preds = %24
  store i8 0, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %73

29:                                               ; preds = %24
  %30 = load ptr, ptr %8, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct._ETHERNET_CPSW_INSTANCE, ptr %30, i32 0, i32 16
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = sub i32 %32, 1
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds [1 x %struct._ETHERNET_CPSW_PORT], ptr %31, i64 0, i64 %34
  store ptr %35, ptr %9, align 8, !tbaa !9
  %36 = load ptr, ptr %9, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct._ETHERNET_CPSW_PORT, ptr %36, i32 0, i32 0
  %38 = load i8, ptr %37, align 4, !tbaa !13
  %39 = icmp ne i8 %38, 0
  br i1 %39, label %41, label %40

40:                                               ; preds = %29
  store i8 0, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %73

41:                                               ; preds = %29
  %42 = load i32, ptr %7, align 4, !tbaa !5
  %43 = icmp uge i32 %42, 10
  br i1 %43, label %44, label %47

44:                                               ; preds = %41
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = udiv i32 %45, 10
  br label %48

47:                                               ; preds = %41
  br label %48

48:                                               ; preds = %47, %44
  %49 = phi i32 [ %46, %44 ], [ 0, %47 ]
  store i32 %49, ptr %10, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %71, %48
  br label %51

51:                                               ; preds = %50
  call void @ETHERNET_HOOK_DELAY(i32 noundef 10)
  %52 = load ptr, ptr %8, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct._ETHERNET_CPSW_INSTANCE, ptr %52, i32 0, i32 2
  %54 = load i32, ptr %53, align 8, !tbaa !15
  %55 = load ptr, ptr %9, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct._ETHERNET_CPSW_PORT, ptr %55, i32 0, i32 3
  %57 = load i32, ptr %56, align 4, !tbaa !16
  %58 = call i32 @PhyLinkStatusGet(i32 noundef %54, i32 noundef %57, i32 noundef 1)
  %59 = icmp eq i32 %58, 1
  br i1 %59, label %60, label %61

60:                                               ; preds = %51
  br label %72

61:                                               ; preds = %51
  %62 = load i32, ptr %10, align 4, !tbaa !5
  %63 = icmp ugt i32 %62, 0
  br i1 %63, label %64, label %71

64:                                               ; preds = %61
  %65 = load i32, ptr %10, align 4, !tbaa !5
  %66 = add i32 %65, -1
  store i32 %66, ptr %10, align 4, !tbaa !5
  %67 = load i32, ptr %10, align 4, !tbaa !5
  %68 = icmp eq i32 %67, 0
  br i1 %68, label %69, label %70

69:                                               ; preds = %64
  store i8 0, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %73

70:                                               ; preds = %64
  br label %71

71:                                               ; preds = %70, %61
  call void @ETHERNET_HOOK_YIELD()
  br label %50

72:                                               ; preds = %60
  store i8 1, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %73

73:                                               ; preds = %72, %69, %40, %28, %23, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %74 = load i8, ptr %4, align 1
  ret i8 %74
}

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 }

!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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"_ETHERNET_CPSW_INSTANCE", !7, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !7, i64 88}
!13 = !{!14, !7, i64 0}
!14 = !{!"_ETHERNET_CPSW_PORT", !7, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !7, i64 16, !6, i64 20, !6, i64 24}
!15 = !{!12, !6, i64 8}
!16 = !{!14, !6, i64 12}


; 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

declare void @ETHERNET_HOOK_YIELD() local_unnamed_addr #0

declare void @ETHERNET_HOOK_DELAY(i32 noundef) local_unnamed_addr #0

declare i32 @PhyLinkStatusGet(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @ETHERNET_INSTANCE_PORT_ISLINKUP(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %.not = icmp ne i32 %0, 0
  %4 = load i8, ptr @ETHERNET_CPSW_INSTANCES, align 16
  %.not19 = icmp eq i8 %4, 0
  %or.cond.not25.not27 = select i1 %.not, i1 true, i1 %.not19
  %.not20 = icmp ne i32 %1, 1
  %or.cond23.not26 = or i1 %.not20, %or.cond.not25.not27
  %5 = load i8, ptr getelementptr inbounds (i8, ptr @ETHERNET_CPSW_INSTANCES, i64 88), align 8
  %.not21 = icmp eq i8 %5, 0
  %or.cond24 = select i1 %or.cond23.not26, i1 true, i1 %.not21
  br i1 %or.cond24, label %.loopexit, label %6

6:                                                ; preds = %3
  tail call void @ETHERNET_HOOK_DELAY(i32 noundef 10) #2
  %7 = load i32, ptr getelementptr inbounds (i8, ptr @ETHERNET_CPSW_INSTANCES, i64 8), align 8, !tbaa !5
  %8 = load i32, ptr getelementptr inbounds (i8, ptr @ETHERNET_CPSW_INSTANCES, i64 100), align 4, !tbaa !11
  %9 = tail call i32 @PhyLinkStatusGet(i32 noundef %7, i32 noundef %8, i32 noundef 1) #2
  %10 = icmp eq i32 %9, 1
  br i1 %10, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %6
  %11 = udiv i32 %2, 10
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %15
  %.028 = phi i32 [ %.1, %15 ], [ %11, %.lr.ph.preheader ]
  %.not22 = icmp eq i32 %.028, 0
  br i1 %.not22, label %15, label %12

12:                                               ; preds = %.lr.ph
  %13 = add nsw i32 %.028, -1
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %.loopexit, label %15

15:                                               ; preds = %12, %.lr.ph
  %.1 = phi i32 [ %13, %12 ], [ 0, %.lr.ph ]
  tail call void @ETHERNET_HOOK_YIELD() #2
  tail call void @ETHERNET_HOOK_DELAY(i32 noundef 10) #2
  %16 = load i32, ptr getelementptr inbounds (i8, ptr @ETHERNET_CPSW_INSTANCES, i64 8), align 8, !tbaa !5
  %17 = load i32, ptr getelementptr inbounds (i8, ptr @ETHERNET_CPSW_INSTANCES, i64 100), align 4, !tbaa !11
  %18 = tail call i32 @PhyLinkStatusGet(i32 noundef %16, i32 noundef %17, i32 noundef 1) #2
  %19 = icmp eq i32 %18, 1
  br i1 %19, label %.loopexit, label %.lr.ph

.loopexit:                                        ; preds = %12, %15, %6, %3
  %.014 = phi i8 [ 0, %3 ], [ 1, %6 ], [ 0, %12 ], [ 1, %15 ]
  ret i8 %.014
}

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 = { 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, !9, i64 8}
!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 = !{!12, !9, i64 12}
!12 = !{!"_ETHERNET_CPSW_PORT", !7, i64 0, !9, i64 4, !9, i64 8, !9, i64 12, !7, i64 16, !9, i64 20, !9, i64 24}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass