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

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

@pico8_font3x5_xpm = external hidden global [131 x ptr], align 16

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

; 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
define dso_local i32 @get_font_column(i32 noundef %0, i32 noundef %1) #1 {
  %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
  %10 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = sdiv i32 %11, 16
  store i32 %12, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = srem i32 %13, 16
  store i32 %14, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %45, %2
  %16 = load i32, ptr %8, align 4, !tbaa !5
  %17 = icmp slt i32 %16, 8
  br i1 %17, label %19, label %18

18:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %48

19:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = mul nsw i32 %20, 8
  %22 = add nsw i32 19, %21
  %23 = load i32, ptr %8, align 4, !tbaa !5
  %24 = add nsw i32 %22, %23
  store i32 %24, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %25 = load i32, ptr %7, align 4, !tbaa !5
  %26 = mul nsw i32 %25, 8
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = add nsw i32 %26, %27
  store i32 %28, ptr %10, align 4, !tbaa !5
  %29 = load i32, ptr %9, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [131 x ptr], ptr @pico8_font3x5_xpm, i64 0, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  %33 = load i32, ptr %10, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds i8, ptr %32, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !11
  %37 = sext i8 %36 to i32
  %38 = icmp ne i32 %37, 32
  br i1 %38, label %39, label %44

39:                                               ; preds = %19
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = load i32, ptr %8, align 4, !tbaa !5
  %42 = shl i32 1, %41
  %43 = or i32 %40, %42
  store i32 %43, ptr %5, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %39, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %8, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %8, align 4, !tbaa !5
  br label %15, !llvm.loop !12

48:                                               ; preds = %18
  %49 = load i32, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, 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 i32 %49
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, 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"

@pico8_font3x5_xpm = external hidden local_unnamed_addr global [131 x ptr], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local i32 @get_font_column(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sdiv i32 %0, 16
  %4 = srem i32 %0, 16
  %5 = shl nsw i32 %3, 3
  %6 = add nsw i32 %5, 19
  %7 = shl nsw i32 %4, 3
  %8 = add nsw i32 %7, %1
  %9 = sext i32 %8 to i64
  %10 = sext i32 %6 to i64
  %11 = getelementptr inbounds [131 x ptr], ptr @pico8_font3x5_xpm, i64 0, i64 %10
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %12, i64 %9
  %14 = load i8, ptr %13, align 1, !tbaa !9
  %.not = icmp ne i8 %14, 32
  %15 = zext i1 %.not to i32
  %16 = add nuw nsw i64 %10, 1
  %17 = getelementptr inbounds [131 x ptr], ptr @pico8_font3x5_xpm, i64 0, i64 %16
  %18 = load ptr, ptr %17, align 16, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 %9
  %20 = load i8, ptr %19, align 1, !tbaa !9
  %.not.1 = icmp eq i8 %20, 32
  %21 = select i1 %.not.1, i32 0, i32 2
  %.1.1 = or disjoint i32 %21, %15
  %22 = add nuw nsw i64 %10, 2
  %23 = getelementptr inbounds [131 x ptr], ptr @pico8_font3x5_xpm, i64 0, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 %9
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %.not.2 = icmp eq i8 %26, 32
  %27 = select i1 %.not.2, i32 0, i32 4
  %.1.2 = or disjoint i32 %27, %.1.1
  %28 = add nuw nsw i64 %10, 3
  %29 = getelementptr inbounds [131 x ptr], ptr @pico8_font3x5_xpm, i64 0, i64 %28
  %30 = load ptr, ptr %29, align 16, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i64 %9
  %32 = load i8, ptr %31, align 1, !tbaa !9
  %.not.3 = icmp eq i8 %32, 32
  %33 = select i1 %.not.3, i32 0, i32 8
  %.1.3 = or disjoint i32 %33, %.1.2
  %34 = or disjoint i64 %10, 4
  %35 = getelementptr inbounds [131 x ptr], ptr @pico8_font3x5_xpm, i64 0, i64 %34
  %36 = load ptr, ptr %35, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 %9
  %38 = load i8, ptr %37, align 1, !tbaa !9
  %.not.4 = icmp eq i8 %38, 32
  %39 = select i1 %.not.4, i32 0, i32 16
  %.1.4 = or disjoint i32 %39, %.1.3
  %40 = add nsw i64 %10, 5
  %41 = getelementptr inbounds [131 x ptr], ptr @pico8_font3x5_xpm, i64 0, i64 %40
  %42 = load ptr, ptr %41, align 16, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %42, i64 %9
  %44 = load i8, ptr %43, align 1, !tbaa !9
  %.not.5 = icmp eq i8 %44, 32
  %45 = select i1 %.not.5, i32 0, i32 32
  %.1.5 = or disjoint i32 %45, %.1.4
  %46 = add nsw i64 %10, 6
  %47 = getelementptr inbounds [131 x ptr], ptr @pico8_font3x5_xpm, i64 0, i64 %46
  %48 = load ptr, ptr %47, align 8, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %48, i64 %9
  %50 = load i8, ptr %49, align 1, !tbaa !9
  %.not.6 = icmp eq i8 %50, 32
  %51 = select i1 %.not.6, i32 0, i32 64
  %.1.6 = or i32 %51, %.1.5
  %52 = add nsw i64 %10, 7
  %53 = getelementptr inbounds [131 x ptr], ptr @pico8_font3x5_xpm, i64 0, i64 %52
  %54 = load ptr, ptr %53, align 16, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i64 %9
  %56 = load i8, ptr %55, align 1, !tbaa !9
  %.not.7 = icmp eq i8 %56, 32
  %57 = select i1 %.not.7, i32 0, i32 128
  %.1.7 = or i32 %57, %.1.6
  ret i32 %.1.7
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: 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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}


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