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

; 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 @EEPROMI2CRead(ptr noundef %0, i32 noundef %1, i16 noundef zeroext %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i16, align 2
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i16 %2, ptr %6, align 2, !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 2)
  call void @StatusClear()
  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 !13

12:                                               ; preds = %8
  %13 = load i16, ptr %6, align 2, !tbaa !11
  %14 = zext i16 %13 to i32
  %15 = ashr i32 %14, 8
  %16 = and i32 %15, 255
  %17 = trunc i32 %16 to i8
  call void @I2CMasterDataPut(i32 noundef 1155575808, i8 noundef zeroext %17)
  br label %18

18:                                               ; preds = %21, %12
  %19 = call i32 @I2CMasterIntRawStatusEx(i32 noundef 1155575808, i32 noundef 16)
  %20 = icmp eq i32 0, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %18
  br label %18, !llvm.loop !15

22:                                               ; preds = %18
  %23 = load i16, ptr %6, align 2, !tbaa !11
  %24 = zext i16 %23 to i32
  %25 = and i32 %24, 255
  %26 = trunc i32 %25 to i8
  call void @I2CMasterDataPut(i32 noundef 1155575808, i8 noundef zeroext %26)
  call void @I2CMasterIntClearEx(i32 noundef 1155575808, i32 noundef 16)
  br label %27

27:                                               ; preds = %31, %22
  %28 = call i32 @I2CMasterIntRawStatus(i32 noundef 1155575808)
  %29 = and i32 %28, 4
  %30 = icmp eq i32 0, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %27
  br label %27, !llvm.loop !16

32:                                               ; preds = %27
  call void @StatusClear()
  %33 = load i32, ptr %5, align 4, !tbaa !9
  call void @I2CSetDataCount(i32 noundef 1155575808, i32 noundef %33)
  call void @I2CMasterControl(i32 noundef 1155575808, i32 noundef 1024)
  call void @I2CMasterStart(i32 noundef 1155575808)
  br label %34

34:                                               ; preds = %43, %32
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = add i32 %35, -1
  store i32 %36, ptr %5, align 4, !tbaa !9
  %37 = icmp ne i32 %35, 0
  br i1 %37, label %38, label %50

38:                                               ; preds = %34
  br label %39

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

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

43:                                               ; preds = %39
  %44 = call zeroext i8 @I2CMasterDataGet(i32 noundef 1155575808)
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = add i32 %46, 1
  store i32 %47, ptr %7, align 4, !tbaa !9
  %48 = zext i32 %46 to i64
  %49 = getelementptr inbounds i8, ptr %45, i64 %48
  store i8 %44, ptr %49, align 1, !tbaa !18
  call void @I2CMasterIntClearEx(i32 noundef 1155575808, i32 noundef 8)
  br label %34, !llvm.loop !19

50:                                               ; preds = %34
  call void @I2CMasterStop(i32 noundef 1155575808)
  br label %51

51:                                               ; preds = %55, %50
  %52 = call i32 @I2CMasterIntRawStatus(i32 noundef 1155575808)
  %53 = and i32 %52, 256
  %54 = icmp eq i32 0, %53
  br i1 %54, label %55, label %56

55:                                               ; preds = %51
  br label %51, !llvm.loop !20

56:                                               ; preds = %51
  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 @StatusClear() #0

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

declare void @I2CMasterStart(i32 noundef) #2

declare i32 @I2CMasterBusBusy(i32 noundef) #2

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

declare i32 @I2CMasterIntRawStatusEx(i32 noundef, i32 noundef) #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 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14}
!18 = !{!7, !7, i64 0}
!19 = distinct !{!19, !14}
!20 = distinct !{!20, !14}


; 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 @EEPROMI2CRead(ptr nocapture noundef writeonly %0, i32 noundef %1, i16 noundef zeroext %2) local_unnamed_addr #0 {
  tail call void @I2CSetDataCount(i32 noundef 1155575808, i32 noundef 2) #2
  tail call void @StatusClear()
  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 %7, !llvm.loop !5

7:                                                ; preds = %4
  %8 = lshr i16 %2, 8
  %9 = trunc nuw i16 %8 to i8
  tail call void @I2CMasterDataPut(i32 noundef 1155575808, i8 noundef zeroext %9) #2
  br label %10

10:                                               ; preds = %10, %7
  %11 = tail call i32 @I2CMasterIntRawStatusEx(i32 noundef 1155575808, i32 noundef 16) #2
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %10, label %13, !llvm.loop !7

13:                                               ; preds = %10
  %14 = trunc i16 %2 to i8
  tail call void @I2CMasterDataPut(i32 noundef 1155575808, i8 noundef zeroext %14) #2
  tail call void @I2CMasterIntClearEx(i32 noundef 1155575808, i32 noundef 16) #2
  br label %15

15:                                               ; preds = %15, %13
  %16 = tail call i32 @I2CMasterIntRawStatus(i32 noundef 1155575808) #2
  %17 = and i32 %16, 4
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %15, label %19, !llvm.loop !8

19:                                               ; preds = %15
  tail call void @StatusClear()
  tail call void @I2CSetDataCount(i32 noundef 1155575808, i32 noundef %1) #2
  tail call void @I2CMasterControl(i32 noundef 1155575808, i32 noundef 1024) #2
  tail call void @I2CMasterStart(i32 noundef 1155575808) #2
  %.not6 = icmp eq i32 %1, 0
  br i1 %.not6, label %._crit_edge, label %.preheader

.preheader:                                       ; preds = %19, %23
  %indvars.iv = phi i64 [ %indvars.iv.next, %23 ], [ 0, %19 ]
  %.in = phi i32 [ %24, %23 ], [ %1, %19 ]
  br label %20

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

23:                                               ; preds = %20
  %24 = add i32 %.in, -1
  %25 = tail call zeroext i8 @I2CMasterDataGet(i32 noundef 1155575808) #2
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %26 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  store i8 %25, ptr %26, align 1, !tbaa !10
  tail call void @I2CMasterIntClearEx(i32 noundef 1155575808, i32 noundef 8) #2
  %.not = icmp eq i32 %24, 0
  br i1 %.not, label %._crit_edge, label %.preheader, !llvm.loop !13

._crit_edge:                                      ; preds = %23, %19
  tail call void @I2CMasterStop(i32 noundef 1155575808) #2
  br label %27

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

31:                                               ; preds = %27
  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 @StatusClear() 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 void @I2CMasterDataPut(i32 noundef, i8 noundef zeroext) local_unnamed_addr #1

declare i32 @I2CMasterIntRawStatusEx(i32 noundef, i32 noundef) 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 = !{!11, !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C/C++ TBAA"}
!13 = distinct !{!13, !6}
!14 = distinct !{!14, !6}


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