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

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

%struct.ImVec2 = type { float, float }

@GL_width = external global i16, align 2
@GL_height = external global i16, align 2
@n = external dso_local global i32, align 4
@C = external dso_local global <{ [36 x i32], [630 x i32] }>, align 16
@T = external dso_local global [130 x [128 x i8]], 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 void @FX(<2 x float> %0, <2 x float> %1, <2 x float> %2, float noundef %3) #1 {
  %5 = alloca %struct.ImVec2, align 4
  %6 = alloca %struct.ImVec2, align 4
  %7 = alloca %struct.ImVec2, align 4
  %8 = alloca float, 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 i32, align 4
  store <2 x float> %0, ptr %5, align 4
  store <2 x float> %1, ptr %6, align 4
  store <2 x float> %2, ptr %7, align 4
  store float %3, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %16 = load i16, ptr @GL_width, align 2, !tbaa !9
  %17 = zext i16 %16 to i32
  %18 = icmp slt i32 128, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %4
  br label %23

20:                                               ; preds = %4
  %21 = load i16, ptr @GL_width, align 2, !tbaa !9
  %22 = zext i16 %21 to i32
  br label %23

23:                                               ; preds = %20, %19
  %24 = phi i32 [ 128, %19 ], [ %22, %20 ]
  store i32 %24, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %25 = load i16, ptr @GL_height, align 2, !tbaa !9
  %26 = zext i16 %25 to i32
  %27 = icmp slt i32 128, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %23
  br label %32

29:                                               ; preds = %23
  %30 = load i16, ptr @GL_height, align 2, !tbaa !9
  %31 = zext i16 %30 to i32
  br label %32

32:                                               ; preds = %29, %28
  %33 = phi i32 [ 128, %28 ], [ %31, %29 ]
  store i32 %33, ptr %10, align 4, !tbaa !11
  %34 = load float, ptr %8, align 4, !tbaa !5
  %35 = fmul float 2.000000e+01, %34
  %36 = load i32, ptr @n, align 4, !tbaa !11
  %37 = uitofp i32 %36 to float
  %38 = fcmp ogt float %35, %37
  br i1 %38, label %39, label %42

39:                                               ; preds = %32
  %40 = load i32, ptr @n, align 4, !tbaa !11
  %41 = add i32 %40, 1
  store i32 %41, ptr @n, align 4, !tbaa !11
  br label %43

42:                                               ; preds = %32
  store float 0.000000e+00, ptr %8, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %42, %39
  %44 = load i32, ptr %9, align 4, !tbaa !11
  %45 = sub nsw i32 %44, 1
  %46 = load i32, ptr %10, align 4, !tbaa !11
  %47 = sub nsw i32 %46, 1
  call void @GL_write_window(i32 noundef 0, i32 noundef 0, i32 noundef %45, i32 noundef %47)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !11
  br label %48

48:                                               ; preds = %107, %43
  %49 = load i32, ptr %11, align 4, !tbaa !11
  %50 = load i32, ptr %10, align 4, !tbaa !11
  %51 = icmp ult i32 %49, %50
  br i1 %51, label %53, label %52

52:                                               ; preds = %48
  store i32 2, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %110

53:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 0, ptr %13, align 4, !tbaa !11
  br label %54

54:                                               ; preds = %103, %53
  %55 = load i32, ptr %13, align 4, !tbaa !11
  %56 = load i32, ptr %9, align 4, !tbaa !11
  %57 = icmp ult i32 %55, %56
  br i1 %57, label %59, label %58

58:                                               ; preds = %54
  store i32 5, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %106

59:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %60 = load i32, ptr %13, align 4, !tbaa !11
  %61 = add i32 %60, 1
  %62 = zext i32 %61 to i64
  %63 = getelementptr inbounds [130 x [128 x i8]], ptr @T, i64 0, i64 %62
  %64 = load i32, ptr %11, align 4, !tbaa !11
  %65 = zext i32 %64 to i64
  %66 = getelementptr inbounds [128 x i8], ptr %63, i64 0, i64 %65
  %67 = load i8, ptr %66, align 1, !tbaa !13
  %68 = zext i8 %67 to i64
  %69 = getelementptr inbounds [666 x i32], ptr @C, i64 0, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !11
  store i32 %70, ptr %14, align 4, !tbaa !11
  %71 = load i32, ptr %14, align 4, !tbaa !11
  store volatile i32 %71, ptr inttoptr (i64 4202752 to ptr), align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %72 = call i32 @rand() #4
  %73 = and i32 3, %72
  store i32 %73, ptr %15, align 4, !tbaa !11
  %74 = load float, ptr %8, align 4, !tbaa !5
  %75 = fcmp une float %74, 0.000000e+00
  br i1 %75, label %76, label %102

76:                                               ; preds = %59
  %77 = load i32, ptr %13, align 4, !tbaa !11
  %78 = zext i32 %77 to i64
  %79 = getelementptr inbounds [130 x [128 x i8]], ptr @T, i64 0, i64 %78
  %80 = load i32, ptr %11, align 4, !tbaa !11
  %81 = load i32, ptr %15, align 4, !tbaa !11
  %82 = add i32 %80, %81
  %83 = load i32, ptr %15, align 4, !tbaa !11
  %84 = icmp ugt i32 %83, 1
  %85 = zext i1 %84 to i32
  %86 = sub i32 %82, %85
  %87 = zext i32 %86 to i64
  %88 = getelementptr inbounds [128 x i8], ptr %79, i64 0, i64 %87
  %89 = load i8, ptr %88, align 1, !tbaa !13
  %90 = zext i8 %89 to i32
  %91 = load i32, ptr %15, align 4, !tbaa !11
  %92 = and i32 %91, 1
  %93 = add i32 %90, %92
  %94 = trunc i32 %93 to i8
  %95 = load i32, ptr %13, align 4, !tbaa !11
  %96 = add i32 %95, 1
  %97 = zext i32 %96 to i64
  %98 = getelementptr inbounds [130 x [128 x i8]], ptr @T, i64 0, i64 %97
  %99 = load i32, ptr %11, align 4, !tbaa !11
  %100 = zext i32 %99 to i64
  %101 = getelementptr inbounds [128 x i8], ptr %98, i64 0, i64 %100
  store i8 %94, ptr %101, align 1, !tbaa !13
  br label %102

102:                                              ; preds = %76, %59
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %103

103:                                              ; preds = %102
  %104 = load i32, ptr %13, align 4, !tbaa !11
  %105 = add i32 %104, 1
  store i32 %105, ptr %13, align 4, !tbaa !11
  br label %54, !llvm.loop !14

106:                                              ; preds = %58
  br label %107

107:                                              ; preds = %106
  %108 = load i32, ptr %11, align 4, !tbaa !11
  %109 = add i32 %108, 1
  store i32 %109, ptr %11, align 4, !tbaa !11
  br label %48, !llvm.loop !16

110:                                              ; preds = %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret void
}

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

; Function Attrs: nounwind
declare i32 @rand() #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="64" "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 "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 = !{!"float", !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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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
@n = external dso_local local_unnamed_addr global i32, align 4
@C = external dso_local local_unnamed_addr global <{ [36 x i32], [630 x i32] }>, align 16
@T = external dso_local local_unnamed_addr global [130 x [128 x i8]], align 16

; Function Attrs: nounwind uwtable
define dso_local void @FX(<2 x float> %0, <2 x float> %1, <2 x float> %2, float noundef %3) local_unnamed_addr #0 {
  %5 = load i16, ptr @GL_width, align 2
  %6 = tail call i16 @llvm.umin.i16(i16 %5, i16 128)
  %7 = zext nneg i16 %6 to i32
  %8 = load i16, ptr @GL_height, align 2
  %9 = tail call i16 @llvm.umin.i16(i16 %8, i16 128)
  %10 = zext nneg i16 %9 to i32
  %11 = fmul float %3, 2.000000e+01
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = uitofp i32 %12 to float
  %14 = fcmp ogt float %11, %13
  br i1 %14, label %15, label %18

15:                                               ; preds = %4
  %16 = add i32 %12, 1
  store i32 %16, ptr @n, align 4, !tbaa !5
  %17 = fcmp une float %3, 0.000000e+00
  br label %18

18:                                               ; preds = %4, %15
  %.0 = phi i1 [ %17, %15 ], [ false, %4 ]
  %19 = add nsw i32 %7, -1
  %20 = add nsw i32 %10, -1
  tail call void @GL_write_window(i32 noundef 0, i32 noundef 0, i32 noundef %19, i32 noundef %20)
  %.not = icmp eq i16 %8, 0
  %.not30 = icmp eq i16 %5, 0
  %or.cond = select i1 %.not, i1 true, i1 %.not30
  br i1 %or.cond, label %._crit_edge26, label %.preheader.lr.ph.split.us

.preheader.lr.ph.split.us:                        ; preds = %18
  %wide.trip.count47 = zext nneg i16 %9 to i64
  %wide.trip.count42 = zext nneg i16 %6 to i64
  br i1 %.0, label %.preheader.us.us, label %.preheader.us

.preheader.us.us:                                 ; preds = %.preheader.lr.ph.split.us, %._crit_edge.split.us.us.us
  %indvars.iv44 = phi i64 [ %indvars.iv.next45, %._crit_edge.split.us.us.us ], [ 0, %.preheader.lr.ph.split.us ]
  %21 = trunc nuw nsw i64 %indvars.iv44 to i32
  br label %22

22:                                               ; preds = %22, %.preheader.us.us
  %indvars.iv39 = phi i64 [ %indvars.iv.next40, %22 ], [ 0, %.preheader.us.us ]
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %23 = getelementptr inbounds [130 x [128 x i8]], ptr @T, i64 0, i64 %indvars.iv.next40, i64 %indvars.iv44
  %24 = load i8, ptr %23, align 1, !tbaa !9
  %25 = zext i8 %24 to i64
  %26 = getelementptr inbounds [666 x i32], ptr @C, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  store volatile i32 %27, ptr inttoptr (i64 4202752 to ptr), align 256, !tbaa !5
  %28 = tail call i32 @rand() #4
  %29 = and i32 %28, 3
  %30 = add nuw nsw i32 %29, %21
  %31 = icmp ugt i32 %29, 1
  %.neg.us.us.us = sext i1 %31 to i32
  %32 = add i32 %30, %.neg.us.us.us
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds [130 x [128 x i8]], ptr @T, i64 0, i64 %indvars.iv39, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !9
  %36 = trunc i32 %28 to i8
  %37 = and i8 %36, 1
  %38 = add i8 %35, %37
  store i8 %38, ptr %23, align 1, !tbaa !9
  %exitcond43.not = icmp eq i64 %indvars.iv.next40, %wide.trip.count42
  br i1 %exitcond43.not, label %._crit_edge.split.us.us.us, label %22, !llvm.loop !10

._crit_edge.split.us.us.us:                       ; preds = %22
  %indvars.iv.next45 = add nuw nsw i64 %indvars.iv44, 1
  %exitcond48.not = icmp eq i64 %indvars.iv.next45, %wide.trip.count47
  br i1 %exitcond48.not, label %._crit_edge26, label %.preheader.us.us, !llvm.loop !12

.preheader.us:                                    ; preds = %.preheader.lr.ph.split.us, %._crit_edge.split.us28
  %indvars.iv34 = phi i64 [ %indvars.iv.next35, %._crit_edge.split.us28 ], [ 0, %.preheader.lr.ph.split.us ]
  br label %39

39:                                               ; preds = %.preheader.us, %39
  %indvars.iv = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next, %39 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %40 = getelementptr inbounds [130 x [128 x i8]], ptr @T, i64 0, i64 %indvars.iv.next, i64 %indvars.iv34
  %41 = load i8, ptr %40, align 1, !tbaa !9
  %42 = zext i8 %41 to i64
  %43 = getelementptr inbounds [666 x i32], ptr @C, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  store volatile i32 %44, ptr inttoptr (i64 4202752 to ptr), align 256, !tbaa !5
  %45 = tail call i32 @rand() #4
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count42
  br i1 %exitcond.not, label %._crit_edge.split.us28, label %39, !llvm.loop !10

._crit_edge.split.us28:                           ; preds = %39
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %exitcond38.not = icmp eq i64 %indvars.iv.next35, %wide.trip.count47
  br i1 %exitcond38.not, label %._crit_edge26, label %.preheader.us, !llvm.loop !12

._crit_edge26:                                    ; preds = %._crit_edge.split.us28, %._crit_edge.split.us.us.us, %18
  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

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i16 @llvm.umin.i16(i16, i16) #3

attributes #0 = { nounwind uwtable "min-legal-vector-width"="64" "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 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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