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

; 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._can_frame = type { i32, i32, i32, ptr }

; Function Attrs: nounwind uwtable
define dso_local void @CANRxObjectConfig(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 32, ptr %6, align 4, !tbaa !5
  %7 = load ptr, ptr %4, align 8, !tbaa !9
  %8 = getelementptr inbounds %struct._can_frame, ptr %7, i32 0, i32 0
  %9 = load i32, ptr %8, align 8, !tbaa !11
  %10 = and i32 %9, 4
  %11 = icmp ne i32 %10, 0
  %12 = zext i1 %11 to i64
  %13 = select i1 %11, i32 1073741824, i32 0
  store i32 %13, ptr %5, align 4, !tbaa !5
  %14 = load i32, ptr %3, align 4, !tbaa !5
  call void @DCANUseAcceptanceMaskControl(i32 noundef %14, i32 noundef 4096, i32 noundef 2)
  %15 = load i32, ptr %3, align 4, !tbaa !5
  call void @DCANMsgObjectMskConfig(i32 noundef %15, i32 noundef 0, i32 noundef 0, i32 noundef -2147483648, i32 noundef 2)
  %16 = load i32, ptr %3, align 4, !tbaa !5
  call void @DCANMsgObjValidate(i32 noundef %16, i32 noundef 2)
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = load ptr, ptr %4, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct._can_frame, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = load i32, ptr %5, align 4, !tbaa !5
  call void @DCANMsgIdSet(i32 noundef %17, i32 noundef %20, i32 noundef %21, i32 noundef 2)
  %22 = load i32, ptr %3, align 4, !tbaa !5
  call void @DCANMsgDirectionSet(i32 noundef %22, i32 noundef 0, i32 noundef 2)
  %23 = load i32, ptr %3, align 4, !tbaa !5
  call void @DCANMsgObjIntEnable(i32 noundef %23, i32 noundef 1024, i32 noundef 2)
  %24 = load i32, ptr %3, align 4, !tbaa !5
  call void @DCANFIFOEndOfBlockControl(i32 noundef %24, i32 noundef 128, i32 noundef 2)
  br label %25

25:                                               ; preds = %35, %2
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = load i32, ptr %6, align 4, !tbaa !5
  %28 = call i32 @DCANMsgValidStatusGet(i32 noundef %26, i32 noundef %27)
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %33

30:                                               ; preds = %25
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = icmp ule i32 %31, 63
  br label %33

33:                                               ; preds = %30, %25
  %34 = phi i1 [ false, %25 ], [ %32, %30 ]
  br i1 %34, label %35, label %38

35:                                               ; preds = %33
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = add i32 %36, 1
  store i32 %37, ptr %6, align 4, !tbaa !5
  br label %25, !llvm.loop !14

38:                                               ; preds = %33
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = load i32, ptr %6, align 4, !tbaa !5
  call void @DCANCommandRegSet(i32 noundef %39, i32 noundef 15728640, i32 noundef %40, i32 noundef 2)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #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 @DCANMsgObjValidate(i32 noundef, i32 noundef) #2

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

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

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

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

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

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

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

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

declare i32 @DCANMsgValidStatusGet(i32 noundef, i32 noundef) #2

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 = !{!"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, !6, i64 0}
!12 = !{!"_can_frame", !6, i64 0, !6, i64 4, !6, i64 8, !10, i64 16}
!13 = !{!12, !6, i64 4}
!14 = distinct !{!14, !15}
!15 = !{!"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"

; Function Attrs: nounwind uwtable
define dso_local void @CANRxObjectConfig(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = load i32, ptr %1, align 8, !tbaa !5
  %4 = shl i32 %3, 28
  %5 = and i32 %4, 1073741824
  tail call void @DCANUseAcceptanceMaskControl(i32 noundef %0, i32 noundef 4096, i32 noundef 2) #2
  tail call void @DCANMsgObjectMskConfig(i32 noundef %0, i32 noundef 0, i32 noundef 0, i32 noundef -2147483648, i32 noundef 2) #2
  tail call void @DCANMsgObjValidate(i32 noundef %0, i32 noundef 2) #2
  %6 = getelementptr inbounds i8, ptr %1, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !11
  tail call void @DCANMsgIdSet(i32 noundef %0, i32 noundef %7, i32 noundef %5, i32 noundef 2) #2
  tail call void @DCANMsgDirectionSet(i32 noundef %0, i32 noundef 0, i32 noundef 2) #2
  tail call void @DCANMsgObjIntEnable(i32 noundef %0, i32 noundef 1024, i32 noundef 2) #2
  tail call void @DCANFIFOEndOfBlockControl(i32 noundef %0, i32 noundef 128, i32 noundef 2) #2
  br label %8

8:                                                ; preds = %8, %2
  %.0 = phi i32 [ 32, %2 ], [ %13, %8 ]
  %9 = tail call i32 @DCANMsgValidStatusGet(i32 noundef %0, i32 noundef %.0) #2
  %10 = icmp ne i32 %9, 0
  %11 = icmp ult i32 %.0, 64
  %12 = and i1 %11, %10
  %13 = add nuw nsw i32 %.0, 1
  br i1 %12, label %8, label %14, !llvm.loop !12

14:                                               ; preds = %8
  tail call void @DCANCommandRegSet(i32 noundef %0, i32 noundef 15728640, i32 noundef %.0, i32 noundef 2) #2
  ret void
}

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

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

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

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

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

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

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

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

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass