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

; 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.EEPROMData = type { [4 x i8], [8 x i8], [5 x i8], [12 x i8] }

@boardId = external dso_local global i32, align 4
@boardVersion = external dso_local global [5 x i8], align 1
@boardName = external dso_local global [8 x i8], align 1
@boardData = external dso_local global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @BoardInfoInit() #0 {
  %1 = alloca i32, align 4
  %2 = alloca [29 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 29, ptr %2) #3
  %3 = getelementptr inbounds [29 x i8], ptr %2, i64 0, i64 0
  call void @BoardInfoRead(ptr noundef %3)
  %4 = getelementptr inbounds [29 x i8], ptr %2, i64 0, i64 0
  store ptr %4, ptr @boardData, align 8, !tbaa !5
  store i32 0, ptr %1, align 4, !tbaa !9
  br label %5

5:                                                ; preds = %18, %0
  %6 = load i32, ptr %1, align 4, !tbaa !9
  %7 = icmp ult i32 %6, 4
  br i1 %7, label %8, label %21

8:                                                ; preds = %5
  %9 = load ptr, ptr @boardData, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.EEPROMData, ptr %9, i32 0, i32 2
  %11 = load i32, ptr %1, align 4, !tbaa !9
  %12 = zext i32 %11 to i64
  %13 = getelementptr inbounds [5 x i8], ptr %10, i64 0, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !11
  %15 = load i32, ptr %1, align 4, !tbaa !9
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds [5 x i8], ptr @boardVersion, i64 0, i64 %16
  store i8 %14, ptr %17, align 1, !tbaa !11
  br label %18

18:                                               ; preds = %8
  %19 = load i32, ptr %1, align 4, !tbaa !9
  %20 = add i32 %19, 1
  store i32 %20, ptr %1, align 4, !tbaa !9
  br label %5, !llvm.loop !12

21:                                               ; preds = %5
  %22 = load i32, ptr %1, align 4, !tbaa !9
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds [5 x i8], ptr @boardVersion, i64 0, i64 %23
  store i8 0, ptr %24, align 1, !tbaa !11
  store i32 0, ptr %1, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %38, %21
  %26 = load i32, ptr %1, align 4, !tbaa !9
  %27 = icmp ult i32 %26, 7
  br i1 %27, label %28, label %41

28:                                               ; preds = %25
  %29 = load ptr, ptr @boardData, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.EEPROMData, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %1, align 4, !tbaa !9
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds [8 x i8], ptr %30, i64 0, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !11
  %35 = load i32, ptr %1, align 4, !tbaa !9
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds [8 x i8], ptr @boardName, i64 0, i64 %36
  store i8 %34, ptr %37, align 1, !tbaa !11
  br label %38

38:                                               ; preds = %28
  %39 = load i32, ptr %1, align 4, !tbaa !9
  %40 = add i32 %39, 1
  store i32 %40, ptr %1, align 4, !tbaa !9
  br label %25, !llvm.loop !14

41:                                               ; preds = %25
  %42 = load i32, ptr %1, align 4, !tbaa !9
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds [8 x i8], ptr @boardName, i64 0, i64 %43
  store i8 0, ptr %44, align 1, !tbaa !11
  %45 = call i32 @BoardInfoCheck(ptr noundef @boardName, ptr noundef @boardVersion)
  store i32 %45, ptr @boardId, align 4, !tbaa !9
  %46 = load i32, ptr @boardId, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 29, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret i32 %46
}

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

declare void @BoardInfoRead(ptr noundef) #2

declare i32 @BoardInfoCheck(ptr noundef, ptr noundef) #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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

@boardId = external dso_local local_unnamed_addr global i32, align 4
@boardVersion = external dso_local global [5 x i8], align 1
@boardName = external dso_local global [8 x i8], align 1
@boardData = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @BoardInfoInit() local_unnamed_addr #0 {
  %1 = alloca [29 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 29, ptr nonnull %1) #4
  call void @BoardInfoRead(ptr noundef nonnull %1) #4
  store ptr %1, ptr @boardData, align 8, !tbaa !5
  %2 = getelementptr inbounds i8, ptr %1, i64 12
  %3 = load i32, ptr %2, align 4, !tbaa !9
  store i32 %3, ptr @boardVersion, align 1, !tbaa !9
  store i8 0, ptr getelementptr inbounds (i8, ptr @boardVersion, i64 4), align 1, !tbaa !9
  %4 = getelementptr inbounds i8, ptr %1, i64 4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(7) @boardName, ptr noundef nonnull align 4 dereferenceable(7) %4, i64 7, i1 false), !tbaa !9
  store i8 0, ptr getelementptr inbounds (i8, ptr @boardName, i64 7), align 1, !tbaa !9
  %5 = call i32 @BoardInfoCheck(ptr noundef nonnull @boardName, ptr noundef nonnull @boardVersion) #4
  store i32 %5, ptr @boardId, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 29, ptr nonnull %1) #4
  ret i32 %5
}

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

declare void @BoardInfoRead(ptr noundef) local_unnamed_addr #2

declare i32 @BoardInfoCheck(ptr noundef, ptr noundef) 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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,SROAPass,SimplifyCFGPass