; LLVM IR from BrunoLevy/learn-fpga :: FemtoRV/FIRMWARE/LIBFEMTOGL (max7219_text)

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

@buff = external hidden global [16 x i8], align 16

; Function Attrs: nounwind uwtable
define dso_local void @MAX7219_shift() #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %2

2:                                                ; preds = %26, %0
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = icmp slt i32 %3, 15
  br i1 %4, label %6, label %5

5:                                                ; preds = %2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  br label %29

6:                                                ; preds = %2
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = icmp slt i32 %7, 8
  br i1 %8, label %9, label %17

9:                                                ; preds = %6
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = add nsw i32 %10, 1
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [16 x i8], ptr @buff, i64 0, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !9
  %16 = zext i8 %15 to i32
  call void @MAX7219(i32 noundef %11, i32 noundef %16)
  br label %17

17:                                               ; preds = %9, %6
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [16 x i8], ptr @buff, i64 0, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !9
  %23 = load i32, ptr %1, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [16 x i8], ptr @buff, i64 0, i64 %24
  store i8 %22, ptr %25, align 1, !tbaa !9
  br label %26

26:                                               ; preds = %17
  %27 = load i32, ptr %1, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %1, align 4, !tbaa !5
  br label %2, !llvm.loop !10

29:                                               ; preds = %5
  call void @milliwait(i32 noundef 60)
  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 @MAX7219(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 @milliwait(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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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"

@buff = external hidden local_unnamed_addr global [16 x i8], align 16

; Function Attrs: nounwind uwtable
define dso_local void @MAX7219_shift() local_unnamed_addr #0 {
  %1 = load i8, ptr @buff, align 16, !tbaa !5
  %2 = zext i8 %1 to i32
  tail call void @MAX7219(i32 noundef 1, i32 noundef %2) #2
  %3 = load i8, ptr getelementptr inbounds (i8, ptr @buff, i64 1), align 1, !tbaa !5
  store i8 %3, ptr @buff, align 16, !tbaa !5
  %4 = zext i8 %3 to i32
  tail call void @MAX7219(i32 noundef 2, i32 noundef %4) #2
  %5 = load i8, ptr getelementptr inbounds (i8, ptr @buff, i64 2), align 2, !tbaa !5
  store i8 %5, ptr getelementptr inbounds (i8, ptr @buff, i64 1), align 1, !tbaa !5
  %6 = zext i8 %5 to i32
  tail call void @MAX7219(i32 noundef 3, i32 noundef %6) #2
  %7 = load i8, ptr getelementptr inbounds (i8, ptr @buff, i64 3), align 1, !tbaa !5
  store i8 %7, ptr getelementptr inbounds (i8, ptr @buff, i64 2), align 2, !tbaa !5
  %8 = zext i8 %7 to i32
  tail call void @MAX7219(i32 noundef 4, i32 noundef %8) #2
  %9 = load i8, ptr getelementptr inbounds (i8, ptr @buff, i64 4), align 4, !tbaa !5
  store i8 %9, ptr getelementptr inbounds (i8, ptr @buff, i64 3), align 1, !tbaa !5
  %10 = zext i8 %9 to i32
  tail call void @MAX7219(i32 noundef 5, i32 noundef %10) #2
  %11 = load i8, ptr getelementptr inbounds (i8, ptr @buff, i64 5), align 1, !tbaa !5
  store i8 %11, ptr getelementptr inbounds (i8, ptr @buff, i64 4), align 4, !tbaa !5
  %12 = zext i8 %11 to i32
  tail call void @MAX7219(i32 noundef 6, i32 noundef %12) #2
  %13 = load i8, ptr getelementptr inbounds (i8, ptr @buff, i64 6), align 2, !tbaa !5
  store i8 %13, ptr getelementptr inbounds (i8, ptr @buff, i64 5), align 1, !tbaa !5
  %14 = zext i8 %13 to i32
  tail call void @MAX7219(i32 noundef 7, i32 noundef %14) #2
  %15 = load i8, ptr getelementptr inbounds (i8, ptr @buff, i64 7), align 1, !tbaa !5
  store i8 %15, ptr getelementptr inbounds (i8, ptr @buff, i64 6), align 2, !tbaa !5
  %16 = zext i8 %15 to i32
  tail call void @MAX7219(i32 noundef 8, i32 noundef %16) #2
  %17 = load <8 x i8>, ptr getelementptr inbounds (i8, ptr @buff, i64 8), align 8, !tbaa !5
  store <8 x i8> %17, ptr getelementptr inbounds (i8, ptr @buff, i64 7), align 1, !tbaa !5
  tail call void @milliwait(i32 noundef 60) #2
  ret void
}

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

declare void @milliwait(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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,SCCPPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass