; LLVM IR from lfarcaro/ARINC653_ARMV7A_Z7000 :: ARINC653_ARMV7A_Z7000.sw/ARINC653_ARMV7A_Z7000/src/ARINC653 (ACTION)

; 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._SYSTEM_INFORMATION_TYPE = type { ptr }
%struct._SYSTEM_CONFIGURATION_TYPE = type { ptr, i32, ptr, i32, ptr, ptr }
%struct._SYSTEM_CONFIGURATION_HEALTHMONITORING_TYPE = type { i32, ptr }
%struct._SYSTEM_CONFIGURATION_HEALTHMONITORING_ERROR_TYPE = type { i32, i32 }

@SYSTEM_INFORMATION = external global %struct._SYSTEM_INFORMATION_TYPE, align 8

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

15:                                               ; preds = %4
  call void @ENTER_CORE()
  br label %16

16:                                               ; preds = %15, %4
  store i32 1, ptr %9, align 4, !tbaa !8
  %17 = load ptr, ptr @SYSTEM_INFORMATION, align 8, !tbaa !10
  %18 = getelementptr inbounds %struct._SYSTEM_CONFIGURATION_TYPE, ptr %17, i32 0, i32 4
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  store ptr %19, ptr %10, align 8, !tbaa !15
  %20 = load ptr, ptr %10, align 8, !tbaa !15
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %54

22:                                               ; preds = %16
  store i32 0, ptr %11, align 4, !tbaa !8
  br label %23

23:                                               ; preds = %50, %22
  %24 = load i32, ptr %11, align 4, !tbaa !8
  %25 = load ptr, ptr %10, align 8, !tbaa !15
  %26 = getelementptr inbounds %struct._SYSTEM_CONFIGURATION_HEALTHMONITORING_TYPE, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %26, align 8, !tbaa !16
  %28 = icmp ult i32 %24, %27
  br i1 %28, label %29, label %53

29:                                               ; preds = %23
  %30 = load ptr, ptr %10, align 8, !tbaa !15
  %31 = getelementptr inbounds %struct._SYSTEM_CONFIGURATION_HEALTHMONITORING_TYPE, ptr %30, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !18
  %33 = load i32, ptr %11, align 4, !tbaa !8
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds %struct._SYSTEM_CONFIGURATION_HEALTHMONITORING_ERROR_TYPE, ptr %32, i64 %34
  %36 = getelementptr inbounds %struct._SYSTEM_CONFIGURATION_HEALTHMONITORING_ERROR_TYPE, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 4, !tbaa !19
  %38 = load i32, ptr %8, align 4, !tbaa !8
  %39 = icmp eq i32 %37, %38
  br i1 %39, label %40, label %49

40:                                               ; preds = %29
  %41 = load ptr, ptr %10, align 8, !tbaa !15
  %42 = getelementptr inbounds %struct._SYSTEM_CONFIGURATION_HEALTHMONITORING_TYPE, ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !18
  %44 = load i32, ptr %11, align 4, !tbaa !8
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds %struct._SYSTEM_CONFIGURATION_HEALTHMONITORING_ERROR_TYPE, ptr %43, i64 %45
  %47 = getelementptr inbounds %struct._SYSTEM_CONFIGURATION_HEALTHMONITORING_ERROR_TYPE, ptr %46, i32 0, i32 1
  %48 = load i32, ptr %47, align 4, !tbaa !21
  store i32 %48, ptr %9, align 4, !tbaa !8
  br label %53

49:                                               ; preds = %29
  br label %50

50:                                               ; preds = %49
  %51 = load i32, ptr %11, align 4, !tbaa !8
  %52 = add i32 %51, 1
  store i32 %52, ptr %11, align 4, !tbaa !8
  br label %23, !llvm.loop !22

53:                                               ; preds = %40, %23
  br label %54

54:                                               ; preds = %53, %16
  %55 = load i32, ptr %9, align 4, !tbaa !8
  %56 = icmp eq i32 %55, 0
  br i1 %56, label %57, label %58

57:                                               ; preds = %54
  call void @SET_MODULE_MODE(i32 noundef 1, ptr noundef %12)
  br label %63

58:                                               ; preds = %54
  %59 = load i32, ptr %9, align 4, !tbaa !8
  %60 = icmp eq i32 %59, 1
  br i1 %60, label %61, label %62

61:                                               ; preds = %58
  call void @SET_MODULE_MODE(i32 noundef 3, ptr noundef %12)
  br label %62

62:                                               ; preds = %61, %58
  br label %63

63:                                               ; preds = %62, %57
  %64 = load i8, ptr %5, align 1, !tbaa !5
  %65 = icmp ne i8 %64, 0
  br i1 %65, label %66, label %67

66:                                               ; preds = %63
  call void @EXIT_CORE()
  br label %67

67:                                               ; preds = %66, %63
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare void @ENTER_CORE() #2

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

declare void @EXIT_CORE() #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !12, i64 0}
!11 = !{!"_SYSTEM_INFORMATION_TYPE", !12, i64 0}
!12 = !{!"any pointer", !6, i64 0}
!13 = !{!14, !12, i64 32}
!14 = !{!"_SYSTEM_CONFIGURATION_TYPE", !12, i64 0, !9, i64 8, !12, i64 16, !9, i64 24, !12, i64 32, !12, i64 40}
!15 = !{!12, !12, i64 0}
!16 = !{!17, !9, i64 0}
!17 = !{!"_SYSTEM_CONFIGURATION_HEALTHMONITORING_TYPE", !9, i64 0, !12, i64 8}
!18 = !{!17, !12, i64 8}
!19 = !{!20, !9, i64 0}
!20 = !{!"_SYSTEM_CONFIGURATION_HEALTHMONITORING_ERROR_TYPE", !9, i64 0, !9, i64 4}
!21 = !{!20, !9, i64 4}
!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"

%struct._SYSTEM_INFORMATION_TYPE = type { ptr }
%struct._SYSTEM_CONFIGURATION_HEALTHMONITORING_ERROR_TYPE = type { i32, i32 }

@SYSTEM_INFORMATION = external local_unnamed_addr global %struct._SYSTEM_INFORMATION_TYPE, align 8

; Function Attrs: nounwind uwtable
define dso_local void @RUN_SYSTEM_ERROR_ACTION(i8 noundef zeroext %0, i8 noundef zeroext %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %.not = icmp eq i8 %0, 0
  br i1 %.not, label %7, label %6

6:                                                ; preds = %4
  tail call void @ENTER_CORE() #3
  br label %7

7:                                                ; preds = %6, %4
  %8 = load ptr, ptr @SYSTEM_INFORMATION, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 32
  %10 = load ptr, ptr %9, align 8, !tbaa !10
  %.not14 = icmp eq ptr %10, null
  br i1 %.not14, label %.thread, label %.preheader

.preheader:                                       ; preds = %7
  %11 = load i32, ptr %10, align 8, !tbaa !13
  %.not19 = icmp eq i32 %11, 0
  br i1 %.not19, label %.thread, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %12 = getelementptr inbounds i8, ptr %10, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !15
  %wide.trip.count = zext i32 %11 to i64
  br label %15

14:                                               ; preds = %15
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.thread, label %15, !llvm.loop !16

15:                                               ; preds = %.lr.ph, %14
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %14 ]
  %16 = getelementptr inbounds %struct._SYSTEM_CONFIGURATION_HEALTHMONITORING_ERROR_TYPE, ptr %13, i64 %indvars.iv
  %17 = load i32, ptr %16, align 4, !tbaa !18
  %18 = icmp eq i32 %17, %3
  br i1 %18, label %19, label %14

19:                                               ; preds = %15
  %20 = getelementptr inbounds %struct._SYSTEM_CONFIGURATION_HEALTHMONITORING_ERROR_TYPE, ptr %13, i64 %indvars.iv, i32 1
  %21 = load i32, ptr %20, align 4, !tbaa !20
  switch i32 %21, label %22 [
    i32 0, label %.sink.split
    i32 1, label %.thread
  ]

.thread:                                          ; preds = %14, %.preheader, %7, %19
  br label %.sink.split

.sink.split:                                      ; preds = %19, %.thread
  %.sink = phi i32 [ 3, %.thread ], [ 1, %19 ]
  call void @SET_MODULE_MODE(i32 noundef %.sink, ptr noundef nonnull %5) #3
  br label %22

22:                                               ; preds = %.sink.split, %19
  br i1 %.not, label %24, label %23

23:                                               ; preds = %22
  call void @EXIT_CORE() #3
  br label %24

24:                                               ; preds = %23, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare void @ENTER_CORE() local_unnamed_addr #2

declare void @SET_MODULE_MODE(i32 noundef, ptr noundef) local_unnamed_addr #2

declare void @EXIT_CORE() local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !7, i64 0}
!6 = !{!"_SYSTEM_INFORMATION_TYPE", !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 32}
!11 = !{!"_SYSTEM_CONFIGURATION_TYPE", !7, i64 0, !12, i64 8, !7, i64 16, !12, i64 24, !7, i64 32, !7, i64 40}
!12 = !{!"int", !8, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"_SYSTEM_CONFIGURATION_HEALTHMONITORING_TYPE", !12, i64 0, !7, i64 8}
!15 = !{!14, !7, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !12, i64 0}
!19 = !{!"_SYSTEM_CONFIGURATION_HEALTHMONITORING_ERROR_TYPE", !12, i64 0, !12, i64 4}
!20 = !{!19, !12, i64 4}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass