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

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

; Function Attrs: nounwind uwtable
define dso_local void @CPLDI2CRead(ptr noundef %0, i32 noundef %1, i8 noundef zeroext %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i8 %2, ptr %6, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @I2CSetDataCount(i32 noundef 1155575808, i32 noundef 1)
  call void @cleanupInterrupts()
  call void @I2CMasterControl(i32 noundef 1155575808, i32 noundef 1536)
  call void @I2CMasterStart(i32 noundef 1155575808)
  br label %8

8:                                                ; preds = %11, %3
  %9 = call i32 @I2CMasterBusBusy(i32 noundef 1155575808)
  %10 = icmp eq i32 0, %9
  br i1 %10, label %11, label %12

11:                                               ; preds = %8
  br label %8, !llvm.loop !12

12:                                               ; preds = %8
  br label %13

13:                                               ; preds = %16, %12
  %14 = call i32 @I2CMasterIntRawStatusEx(i32 noundef 1155575808, i32 noundef 16)
  %15 = icmp eq i32 0, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %13
  br label %13, !llvm.loop !14

17:                                               ; preds = %13
  %18 = load i8, ptr %6, align 1, !tbaa !11
  call void @I2CMasterDataPut(i32 noundef 1155575808, i8 noundef zeroext %18)
  call void @I2CMasterIntClearEx(i32 noundef 1155575808, i32 noundef 16)
  br label %19

19:                                               ; preds = %23, %17
  %20 = call i32 @I2CMasterIntRawStatus(i32 noundef 1155575808)
  %21 = and i32 %20, 4
  %22 = icmp eq i32 0, %21
  br i1 %22, label %23, label %24

23:                                               ; preds = %19
  br label %19, !llvm.loop !15

24:                                               ; preds = %19
  %25 = load i32, ptr %5, align 4, !tbaa !9
  call void @I2CSetDataCount(i32 noundef 1155575808, i32 noundef %25)
  call void @cleanupInterrupts()
  call void @I2CMasterControl(i32 noundef 1155575808, i32 noundef 1024)
  call void @I2CMasterStart(i32 noundef 1155575808)
  br label %26

26:                                               ; preds = %29, %24
  %27 = call i32 @I2CMasterBusBusy(i32 noundef 1155575808)
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %26
  br label %26, !llvm.loop !16

30:                                               ; preds = %26
  br label %31

31:                                               ; preds = %40, %30
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = add i32 %32, -1
  store i32 %33, ptr %5, align 4, !tbaa !9
  %34 = icmp ne i32 %32, 0
  br i1 %34, label %35, label %46

35:                                               ; preds = %31
  br label %36

36:                                               ; preds = %39, %35
  %37 = call i32 @I2CMasterIntRawStatusEx(i32 noundef 1155575808, i32 noundef 8)
  %38 = icmp eq i32 0, %37
  br i1 %38, label %39, label %40

39:                                               ; preds = %36
  br label %36, !llvm.loop !17

40:                                               ; preds = %36
  %41 = call zeroext i8 @I2CMasterDataGet(i32 noundef 1155575808)
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds i8, ptr %42, i64 %44
  store i8 %41, ptr %45, align 1, !tbaa !11
  call void @I2CMasterIntClearEx(i32 noundef 1155575808, i32 noundef 8)
  br label %31, !llvm.loop !18

46:                                               ; preds = %31
  call void @I2CMasterStop(i32 noundef 1155575808)
  br label %47

47:                                               ; preds = %51, %46
  %48 = call i32 @I2CMasterIntRawStatus(i32 noundef 1155575808)
  %49 = and i32 %48, 256
  %50 = icmp eq i32 0, %49
  br i1 %50, label %51, label %52

51:                                               ; preds = %47
  br label %47, !llvm.loop !19

52:                                               ; preds = %47
  call void @I2CMasterIntClearEx(i32 noundef 1155575808, i32 noundef 256)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #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 @I2CSetDataCount(i32 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @cleanupInterrupts() #0

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

declare void @I2CMasterStart(i32 noundef) #2

declare i32 @I2CMasterBusBusy(i32 noundef) #2

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

declare void @I2CMasterDataPut(i32 noundef, i8 noundef zeroext) #2

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

declare i32 @I2CMasterIntRawStatus(i32 noundef) #2

declare zeroext i8 @I2CMasterDataGet(i32 noundef) #2

declare void @I2CMasterStop(i32 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}
!15 = distinct !{!15, !13}
!16 = distinct !{!16, !13}
!17 = distinct !{!17, !13}
!18 = distinct !{!18, !13}
!19 = distinct !{!19, !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"

; Function Attrs: nounwind uwtable
define dso_local void @CPLDI2CRead(ptr nocapture noundef writeonly %0, i32 noundef %1, i8 noundef zeroext %2) local_unnamed_addr #0 {
  tail call void @I2CSetDataCount(i32 noundef 1155575808, i32 noundef 1) #2
  tail call void @cleanupInterrupts()
  tail call void @I2CMasterControl(i32 noundef 1155575808, i32 noundef 1536) #2
  tail call void @I2CMasterStart(i32 noundef 1155575808) #2
  br label %4

4:                                                ; preds = %4, %3
  %5 = tail call i32 @I2CMasterBusBusy(i32 noundef 1155575808) #2
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %4, label %.preheader5, !llvm.loop !5

.preheader5:                                      ; preds = %4, %.preheader5
  %7 = tail call i32 @I2CMasterIntRawStatusEx(i32 noundef 1155575808, i32 noundef 16) #2
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %.preheader5, label %9, !llvm.loop !7

9:                                                ; preds = %.preheader5
  tail call void @I2CMasterDataPut(i32 noundef 1155575808, i8 noundef zeroext %2) #2
  tail call void @I2CMasterIntClearEx(i32 noundef 1155575808, i32 noundef 16) #2
  br label %10

10:                                               ; preds = %10, %9
  %11 = tail call i32 @I2CMasterIntRawStatus(i32 noundef 1155575808) #2
  %12 = and i32 %11, 4
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %10, label %14, !llvm.loop !8

14:                                               ; preds = %10
  tail call void @I2CSetDataCount(i32 noundef 1155575808, i32 noundef %1) #2
  tail call void @cleanupInterrupts()
  tail call void @I2CMasterControl(i32 noundef 1155575808, i32 noundef 1024) #2
  tail call void @I2CMasterStart(i32 noundef 1155575808) #2
  br label %15

15:                                               ; preds = %15, %14
  %16 = tail call i32 @I2CMasterBusBusy(i32 noundef 1155575808) #2
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %15, label %.preheader4, !llvm.loop !9

.preheader4:                                      ; preds = %15
  %.not6 = icmp eq i32 %1, 0
  br i1 %.not6, label %._crit_edge, label %.preheader

.preheader:                                       ; preds = %.preheader4, %21
  %.in = phi i32 [ %22, %21 ], [ %1, %.preheader4 ]
  br label %18

18:                                               ; preds = %.preheader, %18
  %19 = tail call i32 @I2CMasterIntRawStatusEx(i32 noundef 1155575808, i32 noundef 8) #2
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %18, label %21, !llvm.loop !10

21:                                               ; preds = %18
  %22 = add i32 %.in, -1
  %23 = tail call zeroext i8 @I2CMasterDataGet(i32 noundef 1155575808) #2
  store i8 %23, ptr %0, align 1, !tbaa !11
  tail call void @I2CMasterIntClearEx(i32 noundef 1155575808, i32 noundef 8) #2
  %.not = icmp eq i32 %22, 0
  br i1 %.not, label %._crit_edge, label %.preheader, !llvm.loop !14

._crit_edge:                                      ; preds = %21, %.preheader4
  tail call void @I2CMasterStop(i32 noundef 1155575808) #2
  br label %24

24:                                               ; preds = %24, %._crit_edge
  %25 = tail call i32 @I2CMasterIntRawStatus(i32 noundef 1155575808) #2
  %26 = and i32 %25, 256
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %24, label %28, !llvm.loop !15

28:                                               ; preds = %24
  tail call void @I2CMasterIntClearEx(i32 noundef 1155575808, i32 noundef 256) #2
  ret void
}

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

; Function Attrs: nounwind uwtable
declare hidden void @cleanupInterrupts() local_unnamed_addr #0

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

declare void @I2CMasterStart(i32 noundef) local_unnamed_addr #1

declare i32 @I2CMasterBusBusy(i32 noundef) local_unnamed_addr #1

declare i32 @I2CMasterIntRawStatusEx(i32 noundef, i32 noundef) local_unnamed_addr #1

declare void @I2CMasterDataPut(i32 noundef, i8 noundef zeroext) local_unnamed_addr #1

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

declare i32 @I2CMasterIntRawStatus(i32 noundef) local_unnamed_addr #1

declare zeroext i8 @I2CMasterDataGet(i32 noundef) local_unnamed_addr #1

declare void @I2CMasterStop(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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}
!8 = distinct !{!8, !6}
!9 = distinct !{!9, !6}
!10 = distinct !{!10, !6}
!11 = !{!12, !12, i64 0}
!12 = !{!"omnipotent char", !13, i64 0}
!13 = !{!"Simple C/C++ TBAA"}
!14 = distinct !{!14, !6}
!15 = distinct !{!15, !6}


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