; LLVM IR from BrunoLevy/learn-fpga :: FemtoRV/FIRMWARE/EXAMPLES (riscv_logo_2)

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

@logo = external dso_local global [16 x [16 x i8]], align 16
@cmap = external dso_local global [8 x i16], align 16
@sintab = external dso_local constant [64 x i32], align 16
@GL_width = external global i16, align 2
@GL_height = external global i16, align 2

; Function Attrs: nounwind uwtable
define dso_local void @draw_frame(i32 noundef %0) #0 {
  %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
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i8, align 1
  store i32 %0, ptr %2, align 4, !tbaa !5
  %16 = load i16, ptr @GL_width, align 2, !tbaa !9
  %17 = zext i16 %16 to i32
  %18 = sub nsw i32 %17, 1
  %19 = load i16, ptr @GL_height, align 2, !tbaa !9
  %20 = zext i16 %19 to i32
  %21 = sub nsw i32 %20, 1
  call void @GL_write_window(i32 noundef 0, i32 noundef 0, i32 noundef %18, i32 noundef %21)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = and i32 %22, 63
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [64 x i32], ptr @sintab, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = add nsw i32 %26, 400
  store i32 %27, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = and i32 %29, 63
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [64 x i32], ptr @sintab, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = mul nsw i32 %28, %33
  store i32 %34, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = add nsw i32 %36, 16
  %38 = and i32 %37, 63
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [64 x i32], ptr @sintab, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = mul nsw i32 %35, %41
  store i32 %42, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = sub nsw i32 0, %43
  store i32 %44, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %45 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %45, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = add nsw i32 %46, %47
  %49 = mul nsw i32 -64, %48
  store i32 %49, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = add nsw i32 %50, %51
  %53 = mul nsw i32 -64, %52
  store i32 %53, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %102, %1
  %55 = load i32, ptr %10, align 4, !tbaa !5
  %56 = load i16, ptr @GL_height, align 2, !tbaa !9
  %57 = zext i16 %56 to i32
  %58 = icmp slt i32 %55, %57
  br i1 %58, label %60, label %59

59:                                               ; preds = %54
  store i32 2, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %105

60:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %61 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %61, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %62 = load i32, ptr %9, align 4, !tbaa !5
  store i32 %62, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store i32 0, ptr %14, align 4, !tbaa !5
  br label %63

63:                                               ; preds = %92, %60
  %64 = load i32, ptr %14, align 4, !tbaa !5
  %65 = load i16, ptr @GL_width, align 2, !tbaa !9
  %66 = zext i16 %65 to i32
  %67 = icmp slt i32 %64, %66
  br i1 %67, label %69, label %68

68:                                               ; preds = %63
  store i32 5, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %95

69:                                               ; preds = %63
  call void @llvm.lifetime.start.p0(i64 1, ptr %15) #3
  %70 = load i32, ptr %13, align 4, !tbaa !5
  %71 = ashr i32 %70, 18
  %72 = and i32 %71, 15
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [16 x [16 x i8]], ptr @logo, i64 0, i64 %73
  %75 = load i32, ptr %12, align 4, !tbaa !5
  %76 = ashr i32 %75, 18
  %77 = and i32 %76, 15
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [16 x i8], ptr %74, i64 0, i64 %78
  %80 = load i8, ptr %79, align 1, !tbaa !11
  store i8 %80, ptr %15, align 1, !tbaa !11
  %81 = load i8, ptr %15, align 1, !tbaa !11
  %82 = zext i8 %81 to i64
  %83 = getelementptr inbounds [8 x i16], ptr @cmap, i64 0, i64 %82
  %84 = load i16, ptr %83, align 2, !tbaa !9
  %85 = zext i16 %84 to i32
  store volatile i32 %85, ptr inttoptr (i64 4202752 to ptr), align 4, !tbaa !5
  %86 = load i32, ptr %4, align 4, !tbaa !5
  %87 = load i32, ptr %12, align 4, !tbaa !5
  %88 = add nsw i32 %87, %86
  store i32 %88, ptr %12, align 4, !tbaa !5
  %89 = load i32, ptr %5, align 4, !tbaa !5
  %90 = load i32, ptr %13, align 4, !tbaa !5
  %91 = add nsw i32 %90, %89
  store i32 %91, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %15) #3
  br label %92

92:                                               ; preds = %69
  %93 = load i32, ptr %14, align 4, !tbaa !5
  %94 = add nsw i32 %93, 1
  store i32 %94, ptr %14, align 4, !tbaa !5
  br label %63, !llvm.loop !12

95:                                               ; preds = %68
  %96 = load i32, ptr %6, align 4, !tbaa !5
  %97 = load i32, ptr %8, align 4, !tbaa !5
  %98 = add nsw i32 %97, %96
  store i32 %98, ptr %8, align 4, !tbaa !5
  %99 = load i32, ptr %7, align 4, !tbaa !5
  %100 = load i32, ptr %9, align 4, !tbaa !5
  %101 = add nsw i32 %100, %99
  store i32 %101, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %102

102:                                              ; preds = %95
  %103 = load i32, ptr %10, align 4, !tbaa !5
  %104 = add nsw i32 %103, 1
  store i32 %104, ptr %10, align 4, !tbaa !5
  br label %54, !llvm.loop !14

105:                                              ; preds = %59
  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
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @GL_write_window(i32 noundef, i32 noundef, i32 noundef, i32 noundef) #1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { inlinehint 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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

@logo = external dso_local local_unnamed_addr global [16 x [16 x i8]], align 16
@cmap = external dso_local local_unnamed_addr global [8 x i16], align 16
@sintab = external dso_local local_unnamed_addr constant [64 x i32], align 16
@GL_width = external local_unnamed_addr global i16, align 2
@GL_height = external local_unnamed_addr global i16, align 2

; Function Attrs: nounwind uwtable
define dso_local void @draw_frame(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load i16, ptr @GL_width, align 2, !tbaa !5
  %3 = zext i16 %2 to i32
  %4 = add nsw i32 %3, -1
  %5 = load i16, ptr @GL_height, align 2, !tbaa !5
  %6 = zext i16 %5 to i32
  %7 = add nsw i32 %6, -1
  tail call void @GL_write_window(i32 noundef 0, i32 noundef 0, i32 noundef %4, i32 noundef %7)
  %8 = and i32 %0, 63
  %9 = zext nneg i32 %8 to i64
  %10 = getelementptr inbounds [64 x i32], ptr @sintab, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !9
  %12 = add nsw i32 %11, 400
  %13 = mul nsw i32 %12, %11
  %14 = add nsw i32 %0, 16
  %15 = and i32 %14, 63
  %16 = zext nneg i32 %15 to i64
  %17 = getelementptr inbounds [64 x i32], ptr @sintab, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = mul nsw i32 %12, %18
  %20 = load i16, ptr @GL_height, align 2, !tbaa !5
  %21 = zext i16 %20 to i32
  %.not = icmp eq i16 %20, 0
  br i1 %.not, label %._crit_edge39, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %1
  %22 = load i16, ptr @GL_width, align 2, !tbaa !5
  %.fr = freeze i16 %22
  %23 = zext i16 %.fr to i32
  %.not40 = icmp eq i16 %.fr, 0
  br i1 %.not40, label %._crit_edge39, label %.preheader.us.preheader

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %.neg = sub i32 %19, %13
  %24 = shl nsw i32 %.neg, 6
  %25 = add nsw i32 %19, %13
  %26 = mul nsw i32 %25, -64
  %xtraiter = and i32 %23, 1
  %27 = icmp eq i16 %.fr, 1
  %unroll_iter = and i32 %23, 65534
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %.038.us = phi i32 [ %68, %._crit_edge.us ], [ %24, %.preheader.us.preheader ]
  %.03137.us = phi i32 [ %70, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  %.03236.us = phi i32 [ %69, %._crit_edge.us ], [ %26, %.preheader.us.preheader ]
  br i1 %27, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %.02934.us = phi i32 [ %55, %.preheader.us.new ], [ %.03236.us, %.preheader.us ]
  %.03033.us = phi i32 [ %54, %.preheader.us.new ], [ %.038.us, %.preheader.us ]
  %niter = phi i32 [ %niter.next.1, %.preheader.us.new ], [ 0, %.preheader.us ]
  %28 = lshr i32 %.02934.us, 18
  %29 = and i32 %28, 15
  %30 = zext nneg i32 %29 to i64
  %31 = lshr i32 %.03033.us, 18
  %32 = and i32 %31, 15
  %33 = zext nneg i32 %32 to i64
  %34 = getelementptr inbounds [16 x [16 x i8]], ptr @logo, i64 0, i64 %30, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !11
  %36 = zext i8 %35 to i64
  %37 = getelementptr inbounds [8 x i16], ptr @cmap, i64 0, i64 %36
  %38 = load i16, ptr %37, align 2, !tbaa !5
  %39 = zext i16 %38 to i32
  store volatile i32 %39, ptr inttoptr (i64 4202752 to ptr), align 256, !tbaa !9
  %40 = add nsw i32 %.03033.us, %13
  %41 = add nsw i32 %.02934.us, %19
  %42 = lshr i32 %41, 18
  %43 = and i32 %42, 15
  %44 = zext nneg i32 %43 to i64
  %45 = lshr i32 %40, 18
  %46 = and i32 %45, 15
  %47 = zext nneg i32 %46 to i64
  %48 = getelementptr inbounds [16 x [16 x i8]], ptr @logo, i64 0, i64 %44, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !11
  %50 = zext i8 %49 to i64
  %51 = getelementptr inbounds [8 x i16], ptr @cmap, i64 0, i64 %50
  %52 = load i16, ptr %51, align 2, !tbaa !5
  %53 = zext i16 %52 to i32
  store volatile i32 %53, ptr inttoptr (i64 4202752 to ptr), align 256, !tbaa !9
  %54 = add nsw i32 %40, %13
  %55 = add nsw i32 %41, %19
  %niter.next.1 = add i32 %niter, 2
  %niter.ncmp.1 = icmp eq i32 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !12

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader.us.new, %.preheader.us
  %.02934.us.unr = phi i32 [ %.03236.us, %.preheader.us ], [ %55, %.preheader.us.new ]
  %.03033.us.unr = phi i32 [ %.038.us, %.preheader.us ], [ %54, %.preheader.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %._crit_edge.us.epilog-lcssa

._crit_edge.us.epilog-lcssa:                      ; preds = %._crit_edge.us.unr-lcssa
  %56 = lshr i32 %.02934.us.unr, 18
  %57 = and i32 %56, 15
  %58 = zext nneg i32 %57 to i64
  %59 = lshr i32 %.03033.us.unr, 18
  %60 = and i32 %59, 15
  %61 = zext nneg i32 %60 to i64
  %62 = getelementptr inbounds [16 x [16 x i8]], ptr @logo, i64 0, i64 %58, i64 %61
  %63 = load i8, ptr %62, align 1, !tbaa !11
  %64 = zext i8 %63 to i64
  %65 = getelementptr inbounds [8 x i16], ptr @cmap, i64 0, i64 %64
  %66 = load i16, ptr %65, align 2, !tbaa !5
  %67 = zext i16 %66 to i32
  store volatile i32 %67, ptr inttoptr (i64 4202752 to ptr), align 256, !tbaa !9
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %._crit_edge.us.epilog-lcssa
  %68 = sub i32 %.038.us, %19
  %69 = add nsw i32 %.03236.us, %13
  %70 = add nuw nsw i32 %.03137.us, 1
  %exitcond42.not = icmp eq i32 %70, %21
  br i1 %exitcond42.not, label %._crit_edge39, label %.preheader.us, !llvm.loop !14

._crit_edge39:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph, %1
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @GL_write_window(i32 noundef, i32 noundef, i32 noundef, 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 = { inlinehint 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 = !{!"short", !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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass