; LLVM IR from NotManyIdeasDev/double-pendulum-sim :: double-pendulum-sim/Libraries/raygui-2.8/examples/text_box_selection (ColorButton)

; 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.Texture = type { i32, i32, i32, i32, i32 }
%struct.Rectangle = type { float, float, float, float }
%struct.Color = type { i8, i8, i8, i8 }
%struct.Vector2 = type { float, float }

@checked = external hidden global %struct.Texture, align 4

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

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

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

declare <2 x float> @GetMousePosition() #2

declare zeroext i1 @CheckCollisionPointRec(<2 x float>, <2 x float>, <2 x float>) #2

declare zeroext i1 @IsMouseButtonPressed(i32 noundef) #2

declare void @DrawRectangleLinesEx(<2 x float>, <2 x float>, i32 noundef, i32) #2

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @ColorButton(<2 x float> %0, <2 x float> %1, i32 %2) #3 {
  %4 = alloca %struct.Rectangle, align 4
  %5 = alloca %struct.Color, align 1
  %6 = alloca %struct.Rectangle, align 4
  %7 = alloca i8, align 1
  %8 = alloca %struct.Vector2, align 4
  %9 = alloca %struct.Color, align 1
  %10 = alloca %struct.Texture, align 8
  %11 = alloca %struct.Color, align 1
  %12 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %4, i32 0, i32 0
  store <2 x float> %0, ptr %12, align 4
  %13 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %4, i32 0, i32 1
  store <2 x float> %1, ptr %13, align 4
  store i32 %2, ptr %5, align 1
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #4
  %14 = getelementptr inbounds %struct.Rectangle, ptr %6, i32 0, i32 0
  %15 = getelementptr inbounds %struct.Rectangle, ptr %4, i32 0, i32 0
  %16 = load float, ptr %15, align 4, !tbaa !5
  %17 = fadd float %16, 2.000000e+00
  store float %17, ptr %14, align 4, !tbaa !5
  %18 = getelementptr inbounds %struct.Rectangle, ptr %6, i32 0, i32 1
  %19 = getelementptr inbounds %struct.Rectangle, ptr %4, i32 0, i32 1
  %20 = load float, ptr %19, align 4, !tbaa !10
  %21 = fadd float %20, 2.000000e+00
  store float %21, ptr %18, align 4, !tbaa !10
  %22 = getelementptr inbounds %struct.Rectangle, ptr %6, i32 0, i32 2
  %23 = getelementptr inbounds %struct.Rectangle, ptr %4, i32 0, i32 2
  %24 = load float, ptr %23, align 4, !tbaa !11
  %25 = fsub float %24, 4.000000e+00
  store float %25, ptr %22, align 4, !tbaa !11
  %26 = getelementptr inbounds %struct.Rectangle, ptr %6, i32 0, i32 3
  %27 = getelementptr inbounds %struct.Rectangle, ptr %4, i32 0, i32 3
  %28 = load float, ptr %27, align 4, !tbaa !12
  %29 = fsub float %28, 4.000000e+00
  store float %29, ptr %26, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #4
  store i8 0, ptr %7, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %30 = call <2 x float> @GetMousePosition()
  store <2 x float> %30, ptr %8, align 4
  %31 = call zeroext i1 @IsMouseButtonPressed(i32 noundef 0)
  br i1 %31, label %32, label %40

32:                                               ; preds = %3
  %33 = load <2 x float>, ptr %8, align 4
  %34 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %4, i32 0, i32 0
  %35 = load <2 x float>, ptr %34, align 4
  %36 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %4, i32 0, i32 1
  %37 = load <2 x float>, ptr %36, align 4
  %38 = call zeroext i1 @CheckCollisionPointRec(<2 x float> %33, <2 x float> %35, <2 x float> %37)
  br i1 %38, label %39, label %40

39:                                               ; preds = %32
  store i8 1, ptr %7, align 1, !tbaa !13
  br label %40

40:                                               ; preds = %39, %32, %3
  %41 = getelementptr inbounds %struct.Rectangle, ptr %6, i32 0, i32 0
  %42 = load float, ptr %41, align 4, !tbaa !5
  %43 = fptosi float %42 to i32
  %44 = getelementptr inbounds %struct.Rectangle, ptr %6, i32 0, i32 1
  %45 = load float, ptr %44, align 4, !tbaa !10
  %46 = fptosi float %45 to i32
  %47 = getelementptr inbounds %struct.Color, ptr %9, i32 0, i32 0
  store i8 -1, ptr %47, align 1, !tbaa !15
  %48 = getelementptr inbounds %struct.Color, ptr %9, i32 0, i32 1
  store i8 -1, ptr %48, align 1, !tbaa !17
  %49 = getelementptr inbounds %struct.Color, ptr %9, i32 0, i32 2
  store i8 -1, ptr %49, align 1, !tbaa !18
  %50 = getelementptr inbounds %struct.Color, ptr %9, i32 0, i32 3
  store i8 -1, ptr %50, align 1, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 20, ptr %10) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %10, ptr align 4 @checked, i64 20, i1 false), !tbaa.struct !20
  %51 = load i32, ptr %9, align 1
  call void @DrawTexture(ptr noundef byval(%struct.Texture) align 8 %10, i32 noundef %43, i32 noundef %46, i32 %51)
  call void @llvm.lifetime.end.p0(i64 20, ptr %10) #4
  %52 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %6, i32 0, i32 0
  %53 = load <2 x float>, ptr %52, align 4
  %54 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %6, i32 0, i32 1
  %55 = load <2 x float>, ptr %54, align 4
  %56 = load i32, ptr %5, align 1
  call void @DrawRectangleRec(<2 x float> %53, <2 x float> %55, i32 %56)
  %57 = getelementptr inbounds %struct.Color, ptr %11, i32 0, i32 0
  store i8 0, ptr %57, align 1, !tbaa !15
  %58 = getelementptr inbounds %struct.Color, ptr %11, i32 0, i32 1
  store i8 0, ptr %58, align 1, !tbaa !17
  %59 = getelementptr inbounds %struct.Color, ptr %11, i32 0, i32 2
  store i8 0, ptr %59, align 1, !tbaa !18
  %60 = getelementptr inbounds %struct.Color, ptr %11, i32 0, i32 3
  store i8 -1, ptr %60, align 1, !tbaa !19
  %61 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %4, i32 0, i32 0
  %62 = load <2 x float>, ptr %61, align 4
  %63 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %4, i32 0, i32 1
  %64 = load <2 x float>, ptr %63, align 4
  %65 = load i32, ptr %11, align 1
  call void @DrawRectangleLinesEx(<2 x float> %62, <2 x float> %64, i32 noundef 1, i32 %65)
  %66 = load i8, ptr %7, align 1, !tbaa !13, !range !23, !noundef !24
  %67 = trunc i8 %66 to i1
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #4
  ret i1 %67
}

declare void @DrawTexture(ptr noundef byval(%struct.Texture) align 8, i32 noundef, i32 noundef, i32) #2

declare void @DrawRectangleRec(<2 x float>, <2 x float>, i32) #2

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 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 #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, !7, i64 0}
!6 = !{!"Rectangle", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!6, !7, i64 8}
!12 = !{!6, !7, i64 12}
!13 = !{!14, !14, i64 0}
!14 = !{!"_Bool", !8, i64 0}
!15 = !{!16, !8, i64 0}
!16 = !{!"Color", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3}
!17 = !{!16, !8, i64 1}
!18 = !{!16, !8, i64 2}
!19 = !{!16, !8, i64 3}
!20 = !{i64 0, i64 4, !21, i64 4, i64 4, !21, i64 8, i64 4, !21, i64 12, i64 4, !21, i64 16, i64 4, !21}
!21 = !{!22, !22, i64 0}
!22 = !{!"int", !8, i64 0}
!23 = !{i8 0, i8 2}
!24 = !{}


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

%struct.Texture = type { i32, i32, i32, i32, i32 }

@checked = external hidden local_unnamed_addr global %struct.Texture, align 4

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

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

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

declare <2 x float> @GetMousePosition() local_unnamed_addr #2

declare zeroext i1 @CheckCollisionPointRec(<2 x float>, <2 x float>, <2 x float>) local_unnamed_addr #2

declare zeroext i1 @IsMouseButtonPressed(i32 noundef) local_unnamed_addr #2

declare void @DrawRectangleLinesEx(<2 x float>, <2 x float>, i32 noundef, i32) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @ColorButton(<2 x float> %0, <2 x float> %1, i32 %2) local_unnamed_addr #3 {
  %4 = alloca %struct.Texture, align 8
  %5 = tail call <2 x float> @GetMousePosition() #4
  %6 = tail call zeroext i1 @IsMouseButtonPressed(i32 noundef 0) #4
  br i1 %6, label %7, label %9

7:                                                ; preds = %3
  %8 = tail call zeroext i1 @CheckCollisionPointRec(<2 x float> %5, <2 x float> %0, <2 x float> %1) #4
  br label %9

9:                                                ; preds = %7, %3
  %.0 = phi i1 [ false, %3 ], [ %8, %7 ]
  %10 = fadd <2 x float> %1, <float -4.000000e+00, float -4.000000e+00>
  %11 = fadd <2 x float> %0, <float 2.000000e+00, float 2.000000e+00>
  %12 = extractelement <2 x float> %11, i64 0
  %13 = fptosi float %12 to i32
  %14 = extractelement <2 x float> %11, i64 1
  %15 = fptosi float %14 to i32
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %4) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(20) %4, ptr noundef nonnull align 4 dereferenceable(20) @checked, i64 20, i1 false), !tbaa.struct !5
  tail call void @DrawTexture(ptr noundef nonnull byval(%struct.Texture) align 8 %4, i32 noundef %13, i32 noundef %15, i32 -1) #4
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %4) #4
  tail call void @DrawRectangleRec(<2 x float> %11, <2 x float> %10, i32 %2) #4
  tail call void @DrawRectangleLinesEx(<2 x float> %0, <2 x float> %1, i32 noundef 1, i32 -16777216) #4
  ret i1 %.0
}

declare void @DrawTexture(ptr noundef byval(%struct.Texture) align 8, i32 noundef, i32 noundef, i32) local_unnamed_addr #2

declare void @DrawRectangleRec(<2 x float>, <2 x float>, i32) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 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 #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 = !{i64 0, i64 4, !6, i64 4, i64 4, !6, i64 8, i64 4, !6, i64 12, i64 4, !6, i64 16, i64 4, !6}
!6 = !{!7, !7, i64 0}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}


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