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

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

@GL_width = external global i16, align 2
@GL_height = external global i16, align 2

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %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
  store i32 0, ptr %1, align 4
  call void @GL_init(i32 noundef -3)
  call void (...) @GL_clear()
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %55, %0
  %10 = load i16, ptr @GL_width, align 2, !tbaa !9
  %11 = zext i16 %10 to i32
  %12 = sub nsw i32 %11, 1
  %13 = load i16, ptr @GL_height, align 2, !tbaa !9
  %14 = zext i16 %13 to i32
  %15 = sub nsw i32 %14, 1
  call void @GL_write_window(i32 noundef 0, i32 noundef 0, i32 noundef %12, i32 noundef %15)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %52, %9
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = load i16, ptr @GL_height, align 2, !tbaa !9
  %19 = zext i16 %18 to i32
  %20 = icmp ult i32 %17, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %16
  store i32 4, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %55

22:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %48, %22
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = load i16, ptr @GL_width, align 2, !tbaa !9
  %26 = zext i16 %25 to i32
  %27 = icmp ult i32 %24, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %23
  store i32 7, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %51

29:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = add i32 %30, %31
  %33 = and i32 %32, 63
  store i32 %33, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = lshr i32 %34, 3
  %36 = and i32 %35, 63
  store i32 %36, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = add i32 %37, %38
  %40 = and i32 %39, 63
  store i32 %40, ptr %8, align 4, !tbaa !5
  %41 = load i32, ptr %8, align 4, !tbaa !5
  %42 = load i32, ptr %7, align 4, !tbaa !5
  %43 = shl i32 %42, 6
  %44 = or i32 %41, %43
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = shl i32 %45, 11
  %47 = or i32 %44, %46
  store volatile i32 %47, ptr inttoptr (i64 4202752 to ptr), align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %48

48:                                               ; preds = %29
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = add i32 %49, 1
  store i32 %50, ptr %5, align 4, !tbaa !5
  br label %23, !llvm.loop !11

51:                                               ; preds = %28
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = add i32 %53, 1
  store i32 %54, ptr %3, align 4, !tbaa !5
  br label %16, !llvm.loop !13

55:                                               ; preds = %21
  %56 = load i32, ptr %2, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %2, align 4, !tbaa !5
  br label %9
}

declare void @GL_init(i32 noundef) #1

declare void @GL_clear(...) #1

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

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

; 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 = { "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 = { 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 #4 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@GL_width = external local_unnamed_addr global i16, align 2
@GL_height = external local_unnamed_addr global i16, align 2

; Function Attrs: noreturn nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  tail call void @GL_init(i32 noundef -3) #3
  tail call void (...) @GL_clear() #3
  %.pre = load i16, ptr @GL_height, align 2, !tbaa !5
  br label %1

1:                                                ; preds = %._crit_edge17, %0
  %2 = phi i16 [ %.pre, %0 ], [ %8, %._crit_edge17 ]
  %.0 = phi i32 [ 0, %0 ], [ %39, %._crit_edge17 ]
  %3 = load i16, ptr @GL_width, align 2, !tbaa !5
  %4 = zext i16 %3 to i32
  %5 = add nsw i32 %4, -1
  %6 = zext i16 %2 to i32
  %7 = add nsw i32 %6, -1
  tail call void @GL_write_window(i32 noundef 0, i32 noundef 0, i32 noundef %5, i32 noundef %7)
  %8 = load i16, ptr @GL_height, align 2, !tbaa !5
  %9 = zext i16 %8 to i32
  %.not = icmp eq i16 %8, 0
  br i1 %.not, label %._crit_edge17, label %.preheader.lr.ph

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

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %xtraiter = and i32 %11, 1
  %12 = icmp eq i16 %.fr, 1
  %unroll_iter = and i32 %11, 65534
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %.01316.us = phi i32 [ %38, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  %13 = add nuw i32 %.01316.us, %.0
  %14 = and i32 %13, 63
  br i1 %12, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %.01415.us = phi i32 [ %30, %.preheader.us.new ], [ 0, %.preheader.us ]
  %niter = phi i32 [ %niter.next.1, %.preheader.us.new ], [ 0, %.preheader.us ]
  %15 = add nuw i32 %.01415.us, %.0
  %16 = shl nuw nsw i32 %.01415.us, 3
  %17 = and i32 %16, 4032
  %18 = shl i32 %15, 11
  %19 = and i32 %18, 129024
  %20 = or i32 %17, %19
  %21 = or disjoint i32 %20, %14
  store volatile i32 %21, ptr inttoptr (i64 4202752 to ptr), align 256, !tbaa !9
  %22 = or disjoint i32 %.01415.us, 1
  %23 = add nuw i32 %22, %.0
  %24 = shl nuw nsw i32 %.01415.us, 3
  %25 = and i32 %24, 4032
  %26 = shl i32 %23, 11
  %27 = and i32 %26, 129024
  %28 = or i32 %25, %27
  %29 = or disjoint i32 %28, %14
  store volatile i32 %29, ptr inttoptr (i64 4202752 to ptr), align 256, !tbaa !9
  %30 = add nuw nsw i32 %.01415.us, 2
  %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 !11

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader.us.new, %.preheader.us
  %.01415.us.unr = phi i32 [ 0, %.preheader.us ], [ %30, %.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
  %31 = add nuw i32 %.01415.us.unr, %.0
  %32 = shl nuw nsw i32 %.01415.us.unr, 3
  %33 = and i32 %32, 4032
  %34 = shl i32 %31, 11
  %35 = and i32 %34, 129024
  %36 = or i32 %33, %35
  %37 = or disjoint i32 %36, %14
  store volatile i32 %37, 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
  %38 = add nuw nsw i32 %.01316.us, 1
  %exitcond20.not = icmp eq i32 %38, %9
  br i1 %exitcond20.not, label %._crit_edge17, label %.preheader.us, !llvm.loop !13

._crit_edge17:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph, %1
  %39 = add nuw nsw i32 %.0, 1
  br label %1
}

declare void @GL_init(i32 noundef) local_unnamed_addr #1

declare void @GL_clear(...) local_unnamed_addr #1

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

attributes #0 = { noreturn 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 = { 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 #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 = !{!"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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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