; LLVM IR from Eukky/TRender :: lib/imgui (imgui_draw)

; 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.ImDrawVert = type { %struct.ImVec2, %struct.ImVec2, i32 }
%struct.ImVec2 = type { float, float }

; 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: inlinehint mustprogress nounwind uwtable
declare hidden noundef float @_ZL7ImClampIfET_S0_S0_S0_(float noundef, float noundef, float noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5ImGui47ShadeVertsLinearAlphaGradientForLeftToRightTextEP10ImDrawVertS1_ff(ptr noundef %0, ptr noundef %1, float noundef %2, float noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca float, align 4
  %15 = alloca float, align 4
  %16 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store float %2, ptr %7, align 4, !tbaa !9
  store float %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %17 = load float, ptr %8, align 4, !tbaa !9
  %18 = load float, ptr %7, align 4, !tbaa !9
  %19 = fsub float %17, %18
  store float %19, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %20 = load float, ptr %9, align 4, !tbaa !9
  %21 = load float, ptr %9, align 4, !tbaa !9
  %22 = fmul float %20, %21
  %23 = fdiv float 1.000000e+00, %22
  store float %23, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.ImDrawVert, ptr %24, i64 -1
  store ptr %25, ptr %12, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %74, %4
  %27 = load ptr, ptr %12, align 8, !tbaa !5
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = icmp uge ptr %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  store i32 2, ptr %13, align 4
  br label %77

31:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %32 = load ptr, ptr %12, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.ImDrawVert, ptr %32, i32 0, i32 0
  %34 = getelementptr inbounds %struct.ImVec2, ptr %33, i32 0, i32 0
  %35 = load float, ptr %34, align 4, !tbaa !13
  %36 = load float, ptr %7, align 4, !tbaa !9
  %37 = fsub float %35, %36
  %38 = load float, ptr %9, align 4, !tbaa !9
  %39 = fmul float %37, %38
  store float %39, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %40 = load float, ptr %14, align 4, !tbaa !9
  %41 = load float, ptr %10, align 4, !tbaa !9
  %42 = fmul float %40, %41
  %43 = call noundef float @_ZL7ImClampIfET_S0_S0_S0_(float noundef %42, float noundef 0.000000e+00, float noundef 1.000000e+00)
  %44 = fsub float 1.000000e+00, %43
  store float %44, ptr %15, align 4, !tbaa !9
  %45 = load float, ptr %15, align 4, !tbaa !9
  %46 = fcmp oge float %45, 1.000000e+00
  br i1 %46, label %47, label %52

47:                                               ; preds = %31
  %48 = load i32, ptr %11, align 4, !tbaa !11
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %11, align 4, !tbaa !11
  %50 = icmp sgt i32 %49, 2
  br i1 %50, label %51, label %52

51:                                               ; preds = %47
  store i32 1, ptr %13, align 4
  br label %71

52:                                               ; preds = %47, %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %53 = load ptr, ptr %12, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.ImDrawVert, ptr %53, i32 0, i32 2
  %55 = load i32, ptr %54, align 4, !tbaa !16
  %56 = lshr i32 %55, 24
  %57 = and i32 %56, 255
  %58 = uitofp i32 %57 to float
  %59 = load float, ptr %15, align 4, !tbaa !9
  %60 = fmul float %58, %59
  %61 = fptosi float %60 to i32
  store i32 %61, ptr %16, align 4, !tbaa !11
  %62 = load ptr, ptr %12, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.ImDrawVert, ptr %62, i32 0, i32 2
  %64 = load i32, ptr %63, align 4, !tbaa !16
  %65 = and i32 %64, 16777215
  %66 = load i32, ptr %16, align 4, !tbaa !11
  %67 = shl i32 %66, 24
  %68 = or i32 %65, %67
  %69 = load ptr, ptr %12, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.ImDrawVert, ptr %69, i32 0, i32 2
  store i32 %68, ptr %70, align 4, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  store i32 0, ptr %13, align 4
  br label %71

71:                                               ; preds = %52, %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  %72 = load i32, ptr %13, align 4
  switch i32 %72, label %77 [
    i32 0, label %73
  ]

73:                                               ; preds = %71
  br label %74

74:                                               ; preds = %73
  %75 = load ptr, ptr %12, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.ImDrawVert, ptr %75, i32 -1
  store ptr %76, ptr %12, align 8, !tbaa !5
  br label %26, !llvm.loop !17

77:                                               ; preds = %71, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %78 = load i32, ptr %13, align 4
  switch i32 %78, label %80 [
    i32 2, label %79
  ]

79:                                               ; preds = %77
  store i32 0, ptr %13, align 4
  br label %80

80:                                               ; preds = %79, %77
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  %81 = load i32, ptr %13, align 4
  switch i32 %81, label %83 [
    i32 0, label %82
    i32 1, label %82
  ]

82:                                               ; preds = %80, %80
  ret void

83:                                               ; preds = %80
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint mustprogress 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 = { mustprogress 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTS10ImDrawVert", !15, i64 0, !15, i64 8, !12, i64 16}
!15 = !{!"_ZTS6ImVec2", !10, i64 0, !10, i64 4}
!16 = !{!14, !12, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"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"

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef float @_ZL7ImClampIfET_S0_S0_S0_(float noundef, float noundef, float noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN5ImGui47ShadeVertsLinearAlphaGradientForLeftToRightTextEP10ImDrawVertS1_ff(ptr noundef readnone %0, ptr noundef %1, float noundef %2, float noundef %3) local_unnamed_addr #1 {
  %5 = fsub float %3, %2
  %6 = fmul float %5, %5
  %7 = fdiv float 1.000000e+00, %6
  %.02229 = getelementptr inbounds i8, ptr %1, i64 -20
  %.not30 = icmp ult ptr %.02229, %0
  br i1 %.not30, label %.thread, label %.lr.ph

.lr.ph:                                           ; preds = %4, %18
  %.02233 = phi ptr [ %.022, %18 ], [ %.02229, %4 ]
  %.032 = phi i32 [ %.1, %18 ], [ 0, %4 ]
  %.pn31 = phi ptr [ %.02233, %18 ], [ %1, %4 ]
  %8 = load float, ptr %.02233, align 4, !tbaa !5
  %9 = fsub float %8, %2
  %10 = fmul float %5, %9
  %11 = fmul float %7, %10
  %12 = tail call noundef float @_ZL7ImClampIfET_S0_S0_S0_(float noundef %11, float noundef 0.000000e+00, float noundef 1.000000e+00)
  %13 = fsub float 1.000000e+00, %12
  %14 = fcmp ult float %13, 1.000000e+00
  br i1 %14, label %18, label %15

15:                                               ; preds = %.lr.ph
  %16 = add nsw i32 %.032, 1
  %17 = icmp sgt i32 %.032, 1
  br i1 %17, label %.thread, label %18

18:                                               ; preds = %.lr.ph, %15
  %.1 = phi i32 [ %16, %15 ], [ %.032, %.lr.ph ]
  %19 = getelementptr inbounds i8, ptr %.pn31, i64 -4
  %20 = load i32, ptr %19, align 4, !tbaa !12
  %21 = lshr i32 %20, 24
  %22 = uitofp nneg i32 %21 to float
  %23 = fmul float %13, %22
  %24 = fptosi float %23 to i32
  %25 = and i32 %20, 16777215
  %26 = shl i32 %24, 24
  %27 = or disjoint i32 %26, %25
  store i32 %27, ptr %19, align 4, !tbaa !12
  %.022 = getelementptr inbounds i8, ptr %.02233, i64 -20
  %.not = icmp ult ptr %.022, %0
  br i1 %.not, label %.thread, label %.lr.ph, !llvm.loop !13

.thread:                                          ; preds = %18, %15, %4
  ret void
}

attributes #0 = { inlinehint mustprogress 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 = { mustprogress 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, !8, i64 0}
!6 = !{!"_ZTS10ImDrawVert", !7, i64 0, !7, i64 8, !11, i64 16}
!7 = !{!"_ZTS6ImVec2", !8, i64 0, !8, i64 4}
!8 = !{!"float", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!6, !11, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass