; LLVM IR from DanEngelbrecht/longtail :: cmd/lib/minifb/ext/minifb/src (MiniFB_common)

; 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.SWindowData = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, float, float, float, float, ptr, i32, i32, i32, i32, i32, float, float, [8 x i8], [512 x i8], i32, i8, i8, i8 }

; 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

declare void @mfb_get_monitor_scale(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @mfb_set_viewport_best_fit(ptr noundef %0, i32 noundef %1, i32 noundef %2) #2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca float, align 4
  %12 = alloca float, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %86

19:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %20, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.SWindowData, ptr %21, i32 0, i32 10
  %23 = load i32, ptr %22, align 8, !tbaa !11
  store i32 %23, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.SWindowData, ptr %24, i32 0, i32 11
  %26 = load i32, ptr %25, align 4, !tbaa !15
  store i32 %26, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = uitofp i32 %27 to float
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = uitofp i32 %29 to float
  %31 = fdiv float %28, %30
  store float %31, ptr %11, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %32 = load i32, ptr %10, align 4, !tbaa !9
  %33 = uitofp i32 %32 to float
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = uitofp i32 %34 to float
  %36 = fdiv float %33, %35
  store float %36, ptr %12, align 4, !tbaa !16
  %37 = load float, ptr %11, align 4, !tbaa !16
  %38 = load float, ptr %12, align 4, !tbaa !16
  %39 = fcmp oge float %37, %38
  br i1 %39, label %40, label %42

40:                                               ; preds = %19
  %41 = load float, ptr %12, align 4, !tbaa !16
  store float %41, ptr %11, align 4, !tbaa !16
  br label %44

42:                                               ; preds = %19
  %43 = load float, ptr %11, align 4, !tbaa !16
  store float %43, ptr %12, align 4, !tbaa !16
  br label %44

44:                                               ; preds = %42, %40
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = uitofp i32 %45 to float
  %47 = load float, ptr %11, align 4, !tbaa !16
  %48 = call float @llvm.fmuladd.f32(float %46, float %47, float 5.000000e-01)
  %49 = fptoui float %48 to i32
  store i32 %49, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = uitofp i32 %50 to float
  %52 = load float, ptr %12, align 4, !tbaa !16
  %53 = call float @llvm.fmuladd.f32(float %51, float %52, float 5.000000e-01)
  %54 = fptoui float %53 to i32
  store i32 %54, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %55 = load i32, ptr %9, align 4, !tbaa !9
  %56 = load i32, ptr %13, align 4, !tbaa !9
  %57 = sub i32 %55, %56
  %58 = lshr i32 %57, 1
  store i32 %58, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  %59 = load i32, ptr %10, align 4, !tbaa !9
  %60 = load i32, ptr %14, align 4, !tbaa !9
  %61 = sub i32 %59, %60
  %62 = lshr i32 %61, 1
  store i32 %62, ptr %16, align 4, !tbaa !9
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  call void @mfb_get_monitor_scale(ptr noundef %63, ptr noundef %11, ptr noundef %12)
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = load i32, ptr %15, align 4, !tbaa !9
  %66 = uitofp i32 %65 to float
  %67 = load float, ptr %11, align 4, !tbaa !16
  %68 = fdiv float %66, %67
  %69 = fptoui float %68 to i32
  %70 = load i32, ptr %16, align 4, !tbaa !9
  %71 = uitofp i32 %70 to float
  %72 = load float, ptr %12, align 4, !tbaa !16
  %73 = fdiv float %71, %72
  %74 = fptoui float %73 to i32
  %75 = load i32, ptr %13, align 4, !tbaa !9
  %76 = uitofp i32 %75 to float
  %77 = load float, ptr %11, align 4, !tbaa !16
  %78 = fdiv float %76, %77
  %79 = fptoui float %78 to i32
  %80 = load i32, ptr %14, align 4, !tbaa !9
  %81 = uitofp i32 %80 to float
  %82 = load float, ptr %12, align 4, !tbaa !16
  %83 = fdiv float %81, %82
  %84 = fptoui float %83 to i32
  %85 = call zeroext i1 @mfb_set_viewport(ptr noundef %64, i32 noundef %69, i32 noundef %74, i32 noundef %79, i32 noundef %84)
  store i1 %85, ptr %4, align 1
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %87

86:                                               ; preds = %3
  store i1 false, ptr %4, align 1
  br label %87

87:                                               ; preds = %86, %44
  %88 = load i1, ptr %4, align 1
  ret i1 %88
}

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

declare zeroext i1 @mfb_set_viewport(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 = !{!"any pointer", !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 = !{!12, !10, i64 80}
!12 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !10, i64 96, !10, i64 100, !13, i64 104, !13, i64 108, !13, i64 112, !13, i64 116, !6, i64 120, !10, i64 128, !10, i64 132, !10, i64 136, !10, i64 140, !10, i64 144, !13, i64 148, !13, i64 152, !7, i64 156, !7, i64 164, !10, i64 676, !14, i64 680, !14, i64 681, !14, i64 682}
!13 = !{!"float", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!12, !10, i64 84}
!16 = !{!13, !13, i64 0}


; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

declare void @mfb_get_monitor_scale(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @mfb_set_viewport_best_fit(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #2 {
  %4 = alloca float, align 4
  %5 = alloca float, align 4
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %45, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 80
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 84
  %10 = load i32, ptr %9, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  %11 = uitofp i32 %8 to float
  %12 = uitofp i32 %1 to float
  %13 = fdiv float %11, %12
  store float %13, ptr %4, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #4
  %14 = uitofp i32 %10 to float
  %15 = uitofp i32 %2 to float
  %16 = fdiv float %14, %15
  store float %16, ptr %5, align 4, !tbaa !14
  %17 = fcmp ult float %13, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %6
  store float %16, ptr %4, align 4, !tbaa !14
  br label %20

19:                                               ; preds = %6
  store float %13, ptr %5, align 4, !tbaa !14
  br label %20

20:                                               ; preds = %19, %18
  %21 = phi float [ %13, %19 ], [ %16, %18 ]
  %22 = tail call float @llvm.fmuladd.f32(float %12, float %21, float 5.000000e-01)
  %23 = fptoui float %22 to i32
  %24 = tail call float @llvm.fmuladd.f32(float %15, float %21, float 5.000000e-01)
  %25 = fptoui float %24 to i32
  %26 = sub i32 %8, %23
  %27 = lshr i32 %26, 1
  %28 = sub i32 %10, %25
  %29 = lshr i32 %28, 1
  call void @mfb_get_monitor_scale(ptr noundef nonnull %0, ptr noundef nonnull %4, ptr noundef nonnull %5) #4
  %30 = uitofp nneg i32 %27 to float
  %31 = load float, ptr %4, align 4, !tbaa !14
  %32 = fdiv float %30, %31
  %33 = fptoui float %32 to i32
  %34 = uitofp nneg i32 %29 to float
  %35 = load float, ptr %5, align 4, !tbaa !14
  %36 = fdiv float %34, %35
  %37 = fptoui float %36 to i32
  %38 = uitofp i32 %23 to float
  %39 = fdiv float %38, %31
  %40 = fptoui float %39 to i32
  %41 = uitofp i32 %25 to float
  %42 = fdiv float %41, %35
  %43 = fptoui float %42 to i32
  %44 = call zeroext i1 @mfb_set_viewport(ptr noundef nonnull %0, i32 noundef %33, i32 noundef %37, i32 noundef %40, i32 noundef %43) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  br label %45

45:                                               ; preds = %3, %20
  %.0 = phi i1 [ %44, %20 ], [ false, %3 ]
  ret i1 %.0
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #3

declare zeroext i1 @mfb_set_viewport(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { mustprogress 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, !10, i64 80}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !10, i64 96, !10, i64 100, !11, i64 104, !11, i64 108, !11, i64 112, !11, i64 116, !7, i64 120, !10, i64 128, !10, i64 132, !10, i64 136, !10, i64 140, !10, i64 144, !11, i64 148, !11, i64 152, !8, i64 156, !8, i64 164, !10, i64 676, !12, i64 680, !12, i64 681, !12, i64 682}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"float", !8, i64 0}
!12 = !{!"_Bool", !8, i64 0}
!13 = !{!6, !10, i64 84}
!14 = !{!11, !11, i64 0}


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