; LLVM IR from lfarcaro/ARINC653_ARMV7A_AM335X :: Hardware (clock)

; 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.ModuleClock = type { ptr, i32, i32, ptr, i32, i32, i32, i32, [3 x ptr], [5 x ptr], [2 x ptr], [2 x ptr] }

@ModuleClockList = external global [0 x ptr], align 8

; Function Attrs: nounwind uwtable
declare dso_local void @enableModule(i32 noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @enableModuleClock(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = zext i32 %5 to i64
  %7 = getelementptr inbounds [0 x ptr], ptr @ModuleClockList, i64 0, i64 %6
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %8, ptr %4, align 8, !tbaa !9
  br label %9

9:                                                ; preds = %17, %1
  %10 = load ptr, ptr %4, align 8, !tbaa !9
  %11 = getelementptr inbounds %struct.ModuleClock, ptr %10, i32 0, i32 8
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = zext i32 %12 to i64
  %14 = getelementptr inbounds [3 x ptr], ptr %11, i64 0, i64 %13
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %25

17:                                               ; preds = %9
  %18 = load ptr, ptr %4, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.ModuleClock, ptr %18, i32 0, i32 8
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = add i32 %20, 1
  store i32 %21, ptr %3, align 4, !tbaa !5
  %22 = zext i32 %20 to i64
  %23 = getelementptr inbounds [3 x ptr], ptr %19, i64 0, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  call void @enableClock(ptr noundef %24)
  br label %9, !llvm.loop !11

25:                                               ; preds = %9
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %34, %25
  %27 = load ptr, ptr %4, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.ModuleClock, ptr %27, i32 0, i32 9
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds [5 x ptr], ptr %28, i64 0, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %42

34:                                               ; preds = %26
  %35 = load ptr, ptr %4, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.ModuleClock, ptr %35, i32 0, i32 9
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = add i32 %37, 1
  store i32 %38, ptr %3, align 4, !tbaa !5
  %39 = zext i32 %37 to i64
  %40 = getelementptr inbounds [5 x ptr], ptr %36, i64 0, i64 %39
  %41 = load ptr, ptr %40, align 8, !tbaa !9
  call void @enableClock(ptr noundef %41)
  br label %26, !llvm.loop !13

42:                                               ; preds = %26
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %51, %42
  %44 = load ptr, ptr %4, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.ModuleClock, ptr %44, i32 0, i32 10
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds [2 x ptr], ptr %45, i64 0, i64 %47
  %49 = load ptr, ptr %48, align 8, !tbaa !9
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %59

51:                                               ; preds = %43
  %52 = load ptr, ptr %4, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.ModuleClock, ptr %52, i32 0, i32 10
  %54 = load i32, ptr %3, align 4, !tbaa !5
  %55 = add i32 %54, 1
  store i32 %55, ptr %3, align 4, !tbaa !5
  %56 = zext i32 %54 to i64
  %57 = getelementptr inbounds [2 x ptr], ptr %53, i64 0, i64 %56
  %58 = load ptr, ptr %57, align 8, !tbaa !9
  call void @enableClock(ptr noundef %58)
  br label %43, !llvm.loop !14

59:                                               ; preds = %43
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %68, %59
  %61 = load ptr, ptr %4, align 8, !tbaa !9
  %62 = getelementptr inbounds %struct.ModuleClock, ptr %61, i32 0, i32 11
  %63 = load i32, ptr %3, align 4, !tbaa !5
  %64 = zext i32 %63 to i64
  %65 = getelementptr inbounds [2 x ptr], ptr %62, i64 0, i64 %64
  %66 = load ptr, ptr %65, align 8, !tbaa !9
  %67 = icmp ne ptr %66, null
  br i1 %67, label %68, label %76

68:                                               ; preds = %60
  %69 = load ptr, ptr %4, align 8, !tbaa !9
  %70 = getelementptr inbounds %struct.ModuleClock, ptr %69, i32 0, i32 11
  %71 = load i32, ptr %3, align 4, !tbaa !5
  %72 = add i32 %71, 1
  store i32 %72, ptr %3, align 4, !tbaa !5
  %73 = zext i32 %71 to i64
  %74 = getelementptr inbounds [2 x ptr], ptr %70, i64 0, i64 %73
  %75 = load ptr, ptr %74, align 8, !tbaa !9
  call void @enableClock(ptr noundef %75)
  br label %60, !llvm.loop !15

76:                                               ; preds = %60
  %77 = load i32, ptr %2, align 4, !tbaa !5
  call void @enableModule(i32 noundef %77)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @enableClock(ptr noundef) #0

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 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !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"

@ModuleClockList = external local_unnamed_addr global [0 x ptr], align 8

; Function Attrs: nounwind uwtable
declare dso_local void @enableModule(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @enableModuleClock(i32 noundef %0) local_unnamed_addr #0 {
  %2 = zext i32 %0 to i64
  %3 = getelementptr inbounds [0 x ptr], ptr @ModuleClockList, i64 0, i64 %2
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 40
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %.not26 = icmp eq ptr %6, null
  br i1 %.not26, label %.preheader25, label %.lr.ph

.preheader25:                                     ; preds = %.lr.ph, %1
  %7 = getelementptr inbounds i8, ptr %4, i64 64
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %.not2128 = icmp eq ptr %8, null
  br i1 %.not2128, label %.preheader24, label %.lr.ph30

.lr.ph:                                           ; preds = %1, %.lr.ph
  %9 = phi ptr [ %13, %.lr.ph ], [ %6, %1 ]
  %.027 = phi i32 [ %10, %.lr.ph ], [ 0, %1 ]
  %10 = add i32 %.027, 1
  tail call void @enableClock(ptr noundef nonnull %9)
  %11 = zext i32 %10 to i64
  %12 = getelementptr inbounds [3 x ptr], ptr %5, i64 0, i64 %11
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  %.not = icmp eq ptr %13, null
  br i1 %.not, label %.preheader25, label %.lr.ph, !llvm.loop !9

.preheader24:                                     ; preds = %.lr.ph30, %.preheader25
  %14 = getelementptr inbounds i8, ptr %4, i64 104
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  %.not2231 = icmp eq ptr %15, null
  br i1 %.not2231, label %.preheader, label %.lr.ph33

.lr.ph30:                                         ; preds = %.preheader25, %.lr.ph30
  %16 = phi ptr [ %20, %.lr.ph30 ], [ %8, %.preheader25 ]
  %.129 = phi i32 [ %17, %.lr.ph30 ], [ 0, %.preheader25 ]
  %17 = add i32 %.129, 1
  tail call void @enableClock(ptr noundef nonnull %16)
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds [5 x ptr], ptr %7, i64 0, i64 %18
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %.not21 = icmp eq ptr %20, null
  br i1 %.not21, label %.preheader24, label %.lr.ph30, !llvm.loop !11

.preheader:                                       ; preds = %.lr.ph33, %.preheader24
  %21 = getelementptr inbounds i8, ptr %4, i64 120
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  %.not2334 = icmp eq ptr %22, null
  br i1 %.not2334, label %._crit_edge, label %.lr.ph36

.lr.ph33:                                         ; preds = %.preheader24, %.lr.ph33
  %23 = phi ptr [ %27, %.lr.ph33 ], [ %15, %.preheader24 ]
  %.232 = phi i32 [ %24, %.lr.ph33 ], [ 0, %.preheader24 ]
  %24 = add i32 %.232, 1
  tail call void @enableClock(ptr noundef nonnull %23)
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds [2 x ptr], ptr %14, i64 0, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %.not22 = icmp eq ptr %27, null
  br i1 %.not22, label %.preheader, label %.lr.ph33, !llvm.loop !12

.lr.ph36:                                         ; preds = %.preheader, %.lr.ph36
  %28 = phi ptr [ %32, %.lr.ph36 ], [ %22, %.preheader ]
  %.335 = phi i32 [ %29, %.lr.ph36 ], [ 0, %.preheader ]
  %29 = add i32 %.335, 1
  tail call void @enableClock(ptr noundef nonnull %28)
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds [2 x ptr], ptr %21, i64 0, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %.not23 = icmp eq ptr %32, null
  br i1 %.not23, label %._crit_edge, label %.lr.ph36, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph36, %.preheader
  tail call void @enableModule(i32 noundef %0)
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @enableClock(ptr noundef) local_unnamed_addr #0

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


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