; LLVM IR from BrunoLevy/learn-fpga :: FemtoRV/FIRMWARE/TOOLS/FONT (make_font5x6)

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

@font_data = external dso_local global [255 x i32], align 16
@.str.3 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [16 x i8], align 1

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

declare i32 @printf(ptr noundef, ...) #1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @get_font_column(i32 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %10 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  %11 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  %12 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %76, %0
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = icmp slt i32 %14, 96
  br i1 %15, label %17, label %16

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

17:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = call i32 @get_font_column(i32 noundef %18, i32 noundef 2)
  store i32 %19, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = call i32 @get_font_column(i32 noundef %20, i32 noundef 3)
  store i32 %21, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = call i32 @get_font_column(i32 noundef %22, i32 noundef 4)
  store i32 %23, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = call i32 @get_font_column(i32 noundef %24, i32 noundef 5)
  store i32 %25, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = call i32 @get_font_column(i32 noundef %26, i32 noundef 6)
  store i32 %27, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !5
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = icmp ugt i32 %28, 63
  br i1 %29, label %42, label %30

30:                                               ; preds = %17
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = icmp ugt i32 %31, 63
  br i1 %32, label %42, label %33

33:                                               ; preds = %30
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = icmp ugt i32 %34, 63
  br i1 %35, label %42, label %36

36:                                               ; preds = %33
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = icmp ugt i32 %37, 63
  br i1 %38, label %42, label %39

39:                                               ; preds = %36
  %40 = load i32, ptr %7, align 4, !tbaa !5
  %41 = icmp ugt i32 %40, 63
  br i1 %41, label %42, label %53

42:                                               ; preds = %39, %36, %33, %30, %17
  store i32 1, ptr %8, align 4, !tbaa !5
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = lshr i32 %43, 2
  store i32 %44, ptr %3, align 4, !tbaa !5
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = lshr i32 %45, 2
  store i32 %46, ptr %4, align 4, !tbaa !5
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = lshr i32 %47, 2
  store i32 %48, ptr %5, align 4, !tbaa !5
  %49 = load i32, ptr %6, align 4, !tbaa !5
  %50 = lshr i32 %49, 2
  store i32 %50, ptr %6, align 4, !tbaa !5
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = lshr i32 %51, 2
  store i32 %52, ptr %7, align 4, !tbaa !5
  br label %53

53:                                               ; preds = %42, %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %54 = load i32, ptr %3, align 4, !tbaa !5
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = shl i32 %55, 6
  %57 = or i32 %54, %56
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = shl i32 %58, 12
  %60 = or i32 %57, %59
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = shl i32 %61, 18
  %63 = or i32 %60, %62
  %64 = load i32, ptr %7, align 4, !tbaa !5
  %65 = shl i32 %64, 24
  %66 = or i32 %63, %65
  %67 = load i32, ptr %8, align 4, !tbaa !5
  %68 = shl i32 %67, 30
  %69 = or i32 %66, %68
  store i32 %69, ptr %9, align 4, !tbaa !5
  %70 = load i32, ptr %9, align 4, !tbaa !5
  %71 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, i32 noundef %70)
  %72 = load i32, ptr %9, align 4, !tbaa !5
  %73 = load i32, ptr %2, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [255 x i32], ptr @font_data, i64 0, i64 %74
  store i32 %72, ptr %75, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %76

76:                                               ; preds = %53
  %77 = load i32, ptr %2, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %2, align 4, !tbaa !5
  br label %13, !llvm.loop !9

79:                                               ; preds = %16
  %80 = call i32 (ptr, ...) @printf(ptr noundef @.str.7)
  %81 = call i32 (ptr, ...) @printf(ptr noundef @.str.8)
  %82 = load i32, ptr %1, align 4
  ret i32 %82
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 = distinct !{!9, !10}
!10 = !{!"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"

@font_data = external dso_local local_unnamed_addr global [255 x i32], align 16
@.str.3 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @get_font_column(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %2 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  br label %7

4:                                                ; preds = %25
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7)
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  ret i32 0

7:                                                ; preds = %0, %25
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %25 ]
  %8 = trunc nuw nsw i64 %indvars.iv to i32
  %9 = tail call i32 @get_font_column(i32 noundef %8, i32 noundef 2)
  %10 = tail call i32 @get_font_column(i32 noundef %8, i32 noundef 3)
  %11 = tail call i32 @get_font_column(i32 noundef %8, i32 noundef 4)
  %12 = tail call i32 @get_font_column(i32 noundef %8, i32 noundef 5)
  %13 = tail call i32 @get_font_column(i32 noundef %8, i32 noundef 6)
  %14 = icmp ugt i32 %9, 63
  %15 = icmp ugt i32 %10, 63
  %or.cond = select i1 %14, i1 true, i1 %15
  %16 = icmp ugt i32 %11, 63
  %or.cond3 = select i1 %or.cond, i1 true, i1 %16
  %17 = icmp ugt i32 %12, 63
  %or.cond5 = select i1 %or.cond3, i1 true, i1 %17
  %18 = icmp ugt i32 %13, 63
  %or.cond7 = select i1 %or.cond5, i1 true, i1 %18
  br i1 %or.cond7, label %19, label %25

19:                                               ; preds = %7
  %20 = lshr i32 %9, 2
  %21 = lshr i32 %10, 2
  %22 = lshr i32 %11, 2
  %23 = lshr i32 %12, 2
  %24 = lshr i32 %13, 2
  br label %25

25:                                               ; preds = %7, %19
  %.039 = phi i32 [ %20, %19 ], [ %9, %7 ]
  %.038 = phi i32 [ %21, %19 ], [ %10, %7 ]
  %.037 = phi i32 [ %22, %19 ], [ %11, %7 ]
  %.036 = phi i32 [ %23, %19 ], [ %12, %7 ]
  %.035 = phi i32 [ %24, %19 ], [ %13, %7 ]
  %.034 = phi i32 [ 1073741824, %19 ], [ 0, %7 ]
  %26 = shl i32 %.038, 6
  %27 = or i32 %26, %.039
  %28 = shl i32 %.037, 12
  %29 = or i32 %27, %28
  %30 = shl i32 %.036, 18
  %31 = or i32 %29, %30
  %32 = shl i32 %.035, 24
  %33 = or i32 %31, %32
  %34 = or i32 %33, %.034
  %35 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, i32 noundef %34)
  %36 = getelementptr inbounds [255 x i32], ptr @font_data, i64 0, i64 %indvars.iv
  store i32 %34, ptr %36, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 96
  br i1 %exitcond.not, label %4, label %7, !llvm.loop !9
}

attributes #0 = { nofree nounwind "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 = { 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" }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass