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

; 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

; Function Attrs: nounwind uwtable
define dso_local void @addQuad(<2 x float> %0, <2 x float> %1, <2 x float> %2, <2 x float> %3, i32 noundef %4) #0 {
  %6 = alloca %struct.ImVec2, align 4
  %7 = alloca %struct.ImVec2, align 4
  %8 = alloca %struct.ImVec2, align 4
  %9 = alloca %struct.ImVec2, align 4
  %10 = alloca i32, align 4
  %11 = alloca i16, align 2
  %12 = alloca i16, align 2
  %13 = alloca i16, align 2
  %14 = alloca [8 x i32], align 16
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store <2 x float> %0, ptr %6, align 4
  store <2 x float> %1, ptr %7, align 4
  store <2 x float> %2, ptr %8, align 4
  store <2 x float> %3, ptr %9, align 4
  store i32 %4, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #3
  %17 = load i32, ptr %10, align 4, !tbaa !5
  %18 = and i32 %17, 255
  %19 = trunc i32 %18 to i16
  store i16 %19, ptr %11, align 2, !tbaa !9
  %20 = load i32, ptr %10, align 4, !tbaa !5
  %21 = lshr i32 %20, 8
  store i32 %21, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %12) #3
  %22 = load i32, ptr %10, align 4, !tbaa !5
  %23 = and i32 %22, 255
  %24 = trunc i32 %23 to i16
  store i16 %24, ptr %12, align 2, !tbaa !9
  %25 = load i32, ptr %10, align 4, !tbaa !5
  %26 = lshr i32 %25, 8
  store i32 %26, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %13) #3
  %27 = load i32, ptr %10, align 4, !tbaa !5
  %28 = and i32 %27, 255
  %29 = trunc i32 %28 to i16
  store i16 %29, ptr %13, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 32, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %30 = load i16, ptr @GL_width, align 2, !tbaa !9
  %31 = zext i16 %30 to i32
  %32 = sdiv i32 %31, 2
  %33 = sub nsw i32 %32, 80
  store i32 %33, ptr %15, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %34 = load i16, ptr @GL_height, align 2, !tbaa !9
  %35 = zext i16 %34 to i32
  %36 = sdiv i32 %35, 2
  %37 = sub nsw i32 %36, 45
  store i32 %37, ptr %16, align 4, !tbaa !5
  %38 = getelementptr inbounds %struct.ImVec2, ptr %6, i32 0, i32 0
  %39 = load float, ptr %38, align 4, !tbaa !11
  %40 = fptosi float %39 to i32
  %41 = sdiv i32 %40, 2
  %42 = load i32, ptr %15, align 4, !tbaa !5
  %43 = add nsw i32 %41, %42
  %44 = getelementptr inbounds [8 x i32], ptr %14, i64 0, i64 0
  store i32 %43, ptr %44, align 16, !tbaa !5
  %45 = getelementptr inbounds %struct.ImVec2, ptr %6, i32 0, i32 1
  %46 = load float, ptr %45, align 4, !tbaa !14
  %47 = fptosi float %46 to i32
  %48 = sdiv i32 %47, 2
  %49 = load i32, ptr %16, align 4, !tbaa !5
  %50 = add nsw i32 %48, %49
  %51 = getelementptr inbounds [8 x i32], ptr %14, i64 0, i64 1
  store i32 %50, ptr %51, align 4, !tbaa !5
  %52 = getelementptr inbounds %struct.ImVec2, ptr %7, i32 0, i32 0
  %53 = load float, ptr %52, align 4, !tbaa !11
  %54 = fptosi float %53 to i32
  %55 = sdiv i32 %54, 2
  %56 = load i32, ptr %15, align 4, !tbaa !5
  %57 = add nsw i32 %55, %56
  %58 = getelementptr inbounds [8 x i32], ptr %14, i64 0, i64 2
  store i32 %57, ptr %58, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.ImVec2, ptr %7, i32 0, i32 1
  %60 = load float, ptr %59, align 4, !tbaa !14
  %61 = fptosi float %60 to i32
  %62 = sdiv i32 %61, 2
  %63 = load i32, ptr %16, align 4, !tbaa !5
  %64 = add nsw i32 %62, %63
  %65 = getelementptr inbounds [8 x i32], ptr %14, i64 0, i64 3
  store i32 %64, ptr %65, align 4, !tbaa !5
  %66 = getelementptr inbounds %struct.ImVec2, ptr %8, i32 0, i32 0
  %67 = load float, ptr %66, align 4, !tbaa !11
  %68 = fptosi float %67 to i32
  %69 = sdiv i32 %68, 2
  %70 = load i32, ptr %15, align 4, !tbaa !5
  %71 = add nsw i32 %69, %70
  %72 = getelementptr inbounds [8 x i32], ptr %14, i64 0, i64 4
  store i32 %71, ptr %72, align 16, !tbaa !5
  %73 = getelementptr inbounds %struct.ImVec2, ptr %8, i32 0, i32 1
  %74 = load float, ptr %73, align 4, !tbaa !14
  %75 = fptosi float %74 to i32
  %76 = sdiv i32 %75, 2
  %77 = load i32, ptr %16, align 4, !tbaa !5
  %78 = add nsw i32 %76, %77
  %79 = getelementptr inbounds [8 x i32], ptr %14, i64 0, i64 5
  store i32 %78, ptr %79, align 4, !tbaa !5
  %80 = getelementptr inbounds %struct.ImVec2, ptr %9, i32 0, i32 0
  %81 = load float, ptr %80, align 4, !tbaa !11
  %82 = fptosi float %81 to i32
  %83 = sdiv i32 %82, 2
  %84 = load i32, ptr %15, align 4, !tbaa !5
  %85 = add nsw i32 %83, %84
  %86 = getelementptr inbounds [8 x i32], ptr %14, i64 0, i64 6
  store i32 %85, ptr %86, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.ImVec2, ptr %9, i32 0, i32 1
  %88 = load float, ptr %87, align 4, !tbaa !14
  %89 = fptosi float %88 to i32
  %90 = sdiv i32 %89, 2
  %91 = load i32, ptr %16, align 4, !tbaa !5
  %92 = add nsw i32 %90, %91
  %93 = getelementptr inbounds [8 x i32], ptr %14, i64 0, i64 7
  store i32 %92, ptr %93, align 4, !tbaa !5
  %94 = getelementptr inbounds [8 x i32], ptr %14, i64 0, i64 0
  %95 = load i16, ptr %11, align 2, !tbaa !9
  %96 = zext i16 %95 to i32
  %97 = and i32 %96, 248
  %98 = shl i32 %97, 5
  %99 = load i16, ptr %12, align 2, !tbaa !9
  %100 = zext i16 %99 to i32
  %101 = and i32 %100, 248
  %102 = or i32 %98, %101
  %103 = shl i32 %102, 3
  %104 = load i16, ptr %13, align 2, !tbaa !9
  %105 = zext i16 %104 to i32
  %106 = ashr i32 %105, 3
  %107 = or i32 %103, %106
  %108 = trunc i32 %107 to i16
  call void @GL_fill_poly(i32 noundef 4, ptr noundef %94, i16 noundef zeroext %108)
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #3
  ret void
}

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

declare void @GL_fill_poly(i32 noundef, ptr noundef, i16 noundef zeroext) #2

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 4}
!13 = !{!"float", !7, i64 0}
!14 = !{!12, !13, i64 4}


; 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: nounwind uwtable
define dso_local void @addQuad(<2 x float> %0, <2 x float> %1, <2 x float> %2, <2 x float> %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = alloca [8 x i32], align 16
  %7 = lshr i32 %4, 8
  %8 = lshr i32 %4, 19
  %9 = and i32 %8, 31
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %6) #3
  %10 = load i16, ptr @GL_width, align 2, !tbaa !5
  %11 = load i16, ptr @GL_height, align 2, !tbaa !5
  %12 = insertelement <2 x i16> poison, i16 %10, i64 0
  %13 = insertelement <2 x i16> %12, i16 %11, i64 1
  %14 = lshr <2 x i16> %13, <i16 1, i16 1>
  %15 = zext nneg <2 x i16> %14 to <2 x i32>
  %16 = add nsw <2 x i32> %15, <i32 -80, i32 -45>
  %17 = shufflevector <2 x i32> %16, <2 x i32> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
  %18 = shufflevector <2 x float> %0, <2 x float> %1, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
  %19 = fptosi <4 x float> %18 to <4 x i32>
  %20 = sdiv <4 x i32> %19, <i32 2, i32 2, i32 2, i32 2>
  %21 = add nsw <4 x i32> %17, %20
  store <4 x i32> %21, ptr %6, align 16, !tbaa !9
  %22 = getelementptr inbounds i8, ptr %6, i64 16
  %23 = shufflevector <2 x float> %2, <2 x float> %3, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
  %24 = fptosi <4 x float> %23 to <4 x i32>
  %25 = sdiv <4 x i32> %24, <i32 2, i32 2, i32 2, i32 2>
  %26 = add nsw <4 x i32> %17, %25
  store <4 x i32> %26, ptr %22, align 16, !tbaa !9
  %27 = shl i32 %4, 5
  %28 = and i32 %27, 7936
  %29 = and i32 %7, 248
  %30 = or disjoint i32 %28, %29
  %31 = shl nuw nsw i32 %30, 3
  %32 = or disjoint i32 %31, %9
  %33 = trunc nuw i32 %32 to i16
  call void @GL_fill_poly(i32 noundef 4, ptr noundef nonnull %6, i16 noundef zeroext %33) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %6) #3
  ret void
}

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

declare void @GL_fill_poly(i32 noundef, ptr noundef, i16 noundef zeroext) local_unnamed_addr #2

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

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SLPVectorizerPass,SROAPass