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

; 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 zeroext i16 @bcdAdd(i8 noundef zeroext %0, i8 noundef zeroext %1) #0 {
  %3 = alloca i8, align 1
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i16, align 2
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i8 %0, ptr %3, align 1, !tbaa !5
  store i8 %1, ptr %4, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #2
  store i16 0, ptr %7, align 2, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !8
  br label %10

10:                                               ; preds = %40, %2
  %11 = load i32, ptr %5, align 4, !tbaa !8
  %12 = zext i32 %11 to i64
  %13 = icmp ugt i64 2, %12
  br i1 %13, label %14, label %57

14:                                               ; preds = %10
  %15 = load i32, ptr %5, align 4, !tbaa !8
  %16 = mul i32 %15, 4
  store i32 %16, ptr %9, align 4, !tbaa !8
  %17 = load i8, ptr %3, align 1, !tbaa !5
  %18 = zext i8 %17 to i32
  %19 = load i32, ptr %9, align 4, !tbaa !8
  %20 = shl i32 15, %19
  %21 = and i32 %18, %20
  %22 = load i8, ptr %4, align 1, !tbaa !5
  %23 = zext i8 %22 to i32
  %24 = load i32, ptr %9, align 4, !tbaa !8
  %25 = shl i32 15, %24
  %26 = and i32 %23, %25
  %27 = add nsw i32 %21, %26
  %28 = load i32, ptr %9, align 4, !tbaa !8
  %29 = ashr i32 %27, %28
  store i32 %29, ptr %8, align 4, !tbaa !8
  %30 = load i32, ptr %6, align 4, !tbaa !8
  %31 = load i32, ptr %8, align 4, !tbaa !8
  %32 = add i32 %31, %30
  store i32 %32, ptr %8, align 4, !tbaa !8
  store i32 0, ptr %6, align 4, !tbaa !8
  %33 = load i32, ptr %8, align 4, !tbaa !8
  %34 = icmp uge i32 %33, 10
  br i1 %34, label %35, label %38

35:                                               ; preds = %14
  %36 = load i32, ptr %8, align 4, !tbaa !8
  %37 = add i32 %36, 6
  br label %40

38:                                               ; preds = %14
  %39 = load i32, ptr %8, align 4, !tbaa !8
  br label %40

40:                                               ; preds = %38, %35
  %41 = phi i32 [ %37, %35 ], [ %39, %38 ]
  store i32 %41, ptr %8, align 4, !tbaa !8
  %42 = load i32, ptr %8, align 4, !tbaa !8
  %43 = and i32 %42, 240
  %44 = icmp ne i32 %43, 0
  %45 = zext i1 %44 to i64
  %46 = select i1 %44, i32 1, i32 0
  store i32 %46, ptr %6, align 4, !tbaa !8
  %47 = load i32, ptr %8, align 4, !tbaa !8
  %48 = and i32 %47, 15
  %49 = load i32, ptr %9, align 4, !tbaa !8
  %50 = shl i32 %48, %49
  %51 = load i16, ptr %7, align 2, !tbaa !10
  %52 = zext i16 %51 to i32
  %53 = or i32 %52, %50
  %54 = trunc i32 %53 to i16
  store i16 %54, ptr %7, align 2, !tbaa !10
  %55 = load i32, ptr %5, align 4, !tbaa !8
  %56 = add i32 %55, 1
  store i32 %56, ptr %5, align 4, !tbaa !8
  br label %10, !llvm.loop !12

57:                                               ; preds = %10
  %58 = load i32, ptr %6, align 4, !tbaa !8
  %59 = mul i32 %58, 256
  %60 = load i16, ptr %7, align 2, !tbaa !10
  %61 = zext i16 %60 to i32
  %62 = add i32 %61, %59
  %63 = trunc i32 %62 to i16
  store i16 %63, ptr %7, align 2, !tbaa !10
  %64 = load i16, ptr %7, align 2, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i16 %64
}

; 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

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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"short", !6, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local zeroext i16 @bcdAdd(i8 noundef zeroext %0, i8 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = zext i8 %0 to i32
  %4 = zext i8 %1 to i32
  %5 = and i32 %3, 15
  %6 = and i32 %4, 15
  %7 = add nuw nsw i32 %5, %6
  %8 = icmp ugt i32 %7, 9
  %9 = add nuw nsw i32 %7, 6
  %10 = select i1 %8, i32 %9, i32 %7
  %.not = icmp ugt i32 %10, 15
  %11 = zext i1 %.not to i32
  %12 = trunc nuw nsw i32 %10 to i16
  %13 = and i16 %12, 15
  %14 = and i32 %4, 240
  %15 = add nuw nsw i32 %14, %3
  %16 = lshr i32 %15, 4
  %17 = add nuw nsw i32 %16, %11
  %18 = icmp ugt i32 %17, 9
  %19 = add nuw nsw i32 %17, 6
  %20 = select i1 %18, i32 %19, i32 %17
  %.not.1.not = icmp ult i32 %20, 16
  %.tr = trunc nuw nsw i32 %20 to i16
  %21 = shl nuw nsw i16 %.tr, 4
  %22 = and i16 %21, 240
  %23 = or disjoint i16 %13, %22
  %24 = select i1 %.not.1.not, i16 0, i16 256
  %25 = or disjoint i16 %24, %23
  ret i16 %25
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) 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)"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass