; LLVM IR from atabakd/MuJoCo-Tutorials :: include (uitools)

; 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.GLFWvidmode = type { i32, i32, i32, i32, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @uiFontScale(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  call void @glfwGetWindowSize(ptr noundef %12, ptr noundef %3, ptr noundef %5)
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  call void @glfwGetFramebufferSize(ptr noundef %13, ptr noundef %4, ptr noundef %5)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = sitofp i32 %14 to double
  %16 = load i32, ptr %3, align 4, !tbaa !9
  %17 = sitofp i32 %16 to double
  %18 = fdiv double %15, %17
  store double %18, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %19 = call ptr @glfwGetPrimaryMonitor()
  call void @glfwGetMonitorPhysicalSize(ptr noundef %19, ptr noundef %7, ptr noundef %8)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %20 = call ptr @glfwGetPrimaryMonitor()
  %21 = call ptr @glfwGetVideoMode(ptr noundef %20)
  %22 = getelementptr inbounds %struct.GLFWvidmode, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 4, !tbaa !13
  store i32 %23, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %24 = load double, ptr %6, align 8, !tbaa !11
  %25 = fmul double 2.540000e+01, %24
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = sitofp i32 %26 to double
  %28 = fmul double %25, %27
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = sitofp i32 %29 to double
  %31 = fdiv double %28, %30
  store double %31, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %32 = load i32, ptr %4, align 4, !tbaa !9
  %33 = load i32, ptr %3, align 4, !tbaa !9
  %34 = icmp sgt i32 %32, %33
  br i1 %34, label %35, label %39

35:                                               ; preds = %1
  %36 = load double, ptr %6, align 8, !tbaa !11
  %37 = fmul double %36, 1.000000e+02
  %38 = call i32 @mju_round(double noundef %37)
  store i32 %38, ptr %11, align 4, !tbaa !9
  br label %50

39:                                               ; preds = %1
  %40 = load double, ptr %10, align 8, !tbaa !11
  %41 = fcmp ogt double %40, 5.000000e+01
  br i1 %41, label %42, label %48

42:                                               ; preds = %39
  %43 = load double, ptr %10, align 8, !tbaa !11
  %44 = fcmp olt double %43, 3.500000e+02
  br i1 %44, label %45, label %48

45:                                               ; preds = %42
  %46 = load double, ptr %10, align 8, !tbaa !11
  %47 = call i32 @mju_round(double noundef %46)
  store i32 %47, ptr %11, align 4, !tbaa !9
  br label %49

48:                                               ; preds = %42, %39
  store i32 150, ptr %11, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %48, %45
  br label %50

50:                                               ; preds = %49, %35
  %51 = load i32, ptr %11, align 4, !tbaa !9
  %52 = sitofp i32 %51 to double
  %53 = fmul double %52, 2.000000e-02
  %54 = call i32 @mju_round(double noundef %53)
  %55 = mul nsw i32 %54, 50
  store i32 %55, ptr %11, align 4, !tbaa !9
  %56 = load i32, ptr %11, align 4, !tbaa !9
  %57 = icmp sgt i32 100, %56
  br i1 %57, label %58, label %59

58:                                               ; preds = %50
  br label %61

59:                                               ; preds = %50
  %60 = load i32, ptr %11, align 4, !tbaa !9
  br label %61

61:                                               ; preds = %59, %58
  %62 = phi i32 [ 100, %58 ], [ %60, %59 ]
  %63 = icmp slt i32 300, %62
  br i1 %63, label %64, label %65

64:                                               ; preds = %61
  br label %73

65:                                               ; preds = %61
  %66 = load i32, ptr %11, align 4, !tbaa !9
  %67 = icmp sgt i32 100, %66
  br i1 %67, label %68, label %69

68:                                               ; preds = %65
  br label %71

69:                                               ; preds = %65
  %70 = load i32, ptr %11, align 4, !tbaa !9
  br label %71

71:                                               ; preds = %69, %68
  %72 = phi i32 [ 100, %68 ], [ %70, %69 ]
  br label %73

73:                                               ; preds = %71, %64
  %74 = phi i32 [ 300, %64 ], [ %72, %71 ]
  store i32 %74, ptr %11, align 4, !tbaa !9
  %75 = load i32, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 %75
}

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

declare void @glfwGetWindowSize(ptr noundef, ptr noundef, ptr noundef) #2

declare void @glfwGetFramebufferSize(ptr noundef, ptr noundef, ptr noundef) #2

declare void @glfwGetMonitorPhysicalSize(ptr noundef, ptr noundef, ptr noundef) #2

declare ptr @glfwGetPrimaryMonitor() #2

declare ptr @glfwGetVideoMode(ptr noundef) #2

declare i32 @mju_round(double noundef) #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"="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 = { 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 = !{!"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, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"GLFWvidmode", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}


; 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: nounwind uwtable
define dso_local i32 @uiFontScale(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  call void @glfwGetWindowSize(ptr noundef %0, ptr noundef nonnull %2, ptr noundef nonnull %4) #4
  call void @glfwGetFramebufferSize(ptr noundef %0, ptr noundef nonnull %3, ptr noundef nonnull %4) #4
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = sitofp i32 %7 to double
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = sitofp i32 %9 to double
  %11 = fdiv double %8, %10
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #4
  %12 = call ptr @glfwGetPrimaryMonitor() #4
  call void @glfwGetMonitorPhysicalSize(ptr noundef %12, ptr noundef nonnull %5, ptr noundef nonnull %6) #4
  %13 = call ptr @glfwGetPrimaryMonitor() #4
  %14 = call ptr @glfwGetVideoMode(ptr noundef %13) #4
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = icmp sgt i32 %15, %16
  br i1 %17, label %18, label %20

18:                                               ; preds = %1
  %19 = fmul double %11, 1.000000e+02
  br label %.sink.split

20:                                               ; preds = %1
  %21 = fmul double %11, 2.540000e+01
  %22 = load i32, ptr %14, align 4, !tbaa !9
  %23 = sitofp i32 %22 to double
  %24 = fmul double %21, %23
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = sitofp i32 %25 to double
  %27 = fdiv double %24, %26
  %28 = fcmp ogt double %27, 5.000000e+01
  %29 = fcmp olt double %27, 3.500000e+02
  %or.cond = and i1 %28, %29
  br i1 %or.cond, label %.sink.split, label %33

.sink.split:                                      ; preds = %20, %18
  %.sink = phi double [ %19, %18 ], [ %27, %20 ]
  %30 = call i32 @mju_round(double noundef %.sink) #4
  %31 = sitofp i32 %30 to double
  %32 = fmul double %31, 2.000000e-02
  br label %33

33:                                               ; preds = %.sink.split, %20
  %.0 = phi double [ 3.000000e+00, %20 ], [ %32, %.sink.split ]
  %34 = call i32 @mju_round(double noundef %.0) #4
  %35 = mul nsw i32 %34, 50
  %36 = call i32 @llvm.smax.i32(i32 %35, i32 100)
  %37 = call i32 @llvm.umin.i32(i32 %36, i32 300)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #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
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  ret i32 %37
}

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

declare void @glfwGetWindowSize(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @glfwGetFramebufferSize(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @glfwGetMonitorPhysicalSize(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @glfwGetPrimaryMonitor() local_unnamed_addr #2

declare ptr @glfwGetVideoMode(ptr noundef) local_unnamed_addr #2

declare i32 @mju_round(double noundef) 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

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

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

attributes #0 = { 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 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 = { 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 = !{!10, !6, i64 0}
!10 = !{!"GLFWvidmode", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20}


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