#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
float CG_Text_Width(char *, float, int /*<<< orphan*/);
int /*<<< orphan*/ Q_strncpyz(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
void CG_FitTextToWidth_SingleLine(char *instr, float scale, float w, int size) {
  char *s, *p;
  char buffer[1024];
  Q_strncpyz(buffer, instr, 1024);
  memset(instr, 0, size);
  p = instr;
  for (s = buffer; *s; s++, p++) {
    *p = *s;
    if (CG_Text_Width(instr, scale, 0) > w) {
      *p = '\0';
      return;
    }
  }
}


x86 assembly (clang, -O0):
<CG_FitTextToWidth_SingleLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
movss  %xmm1,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x400,%edx
call   1050 <Q_strncpyz@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x430(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11e3 <CG_FitTextToWidth_SingleLine+0xb3>
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rdi
movss  -0xc(%rbp),%xmm0
xor    %esi,%esi
call   1040 <CG_Text_Width@plt>
ucomiss -0x10(%rbp),%xmm0
jbe    11c1 <CG_FitTextToWidth_SingleLine+0x91>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
jmp    11e3 <CG_FitTextToWidth_SingleLine+0xb3>
jmp    11c6 <CG_FitTextToWidth_SingleLine+0x96>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1182 <CG_FitTextToWidth_SingleLine+0x52>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CG_FitTextToWidth_SingleLine>:
push   %rbp
push   %rbx
sub    $0x418,%rsp
mov    %esi,%ebp
movss  %xmm1,0xc(%rsp)
movss  %xmm0,0x8(%rsp)
mov    %rdi,%rbx
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1050 <Q_strncpyz@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1030 <memset@plt>
mov    0x10(%rsp),%al
test   %al,%al
je     11ad <CG_FitTextToWidth_SingleLine+0x7d>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %al,(%rbx,%rbp,1)
mov    %rbx,%rdi
movss  0x8(%rsp),%xmm0
xor    %esi,%esi
call   1040 <CG_Text_Width@plt>
ucomiss 0xc(%rsp),%xmm0
ja     11a9 <CG_FitTextToWidth_SingleLine+0x79>
movzbl 0x11(%rsp,%rbp,1),%eax
add    $0x1,%rbp
test   %al,%al
jne    1180 <CG_FitTextToWidth_SingleLine+0x50>
jmp    11ad <CG_FitTextToWidth_SingleLine+0x7d>
movb   $0x0,(%rbx,%rbp,1)
add    $0x418,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @CG_FitTextToWidth_SingleLine(i8* %0, float %1, float %2, i32 %3) {
%5 = alloca i8*
%6 = alloca float
%7 = alloca float
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca [1024 x i8]
store i8* %0, i8** %5
store float %1, float* %6
store float %2, float* %7
store i32 %3, i32* %8
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%13 = load i8*, i8** %5
%14 = call i32 @Q_strncpyz(i8* %12, i8* %13, i32 1024)
%15 = load i8*, i8** %5
%16 = load i32, i32* %8
%17 = call i32 @memset(i8* %15, i32 0, i32 %16)
%18 = load i8*, i8** %5
store i8* %18, i8** %10
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
store i8* %19, i8** %9
br label %20
20: ; preds = %36, %4
%21 = load i8*, i8** %9
%22 = load i8, i8* %21
%23 = icmp ne i8 %22, 0
br i1 %23, label %24, label %41
24: ; preds = %20
%25 = load i8*, i8** %9
%26 = load i8, i8* %25
%27 = load i8*, i8** %10
store i8 %26, i8* %27
%28 = load i8*, i8** %5
%29 = load float, float* %6
%30 = call float @CG_Text_Width(i8* %28, float %29, i32 0)
%31 = load float, float* %7
%32 = fcmp ogt float %30, %31
br i1 %32, label %33, label %35
33: ; preds = %24
%34 = load i8*, i8** %10
store i8 0, i8* %34
br label %41
35: ; preds = %24
br label %36
36: ; preds = %35
%37 = load i8*, i8** %9
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %9
%39 = load i8*, i8** %10
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %10
br label %20
41: ; preds = %33, %20
ret void
}

LLVM IR (-O2):
define void @CG_FitTextToWidth_SingleLine(i8* %0, float %1, float %2, i32 %3) {
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%7 = call i32 @Q_strncpyz(i8* %6, i8* %0, i32 1024)
%8 = call i32 @memset(i8* %0, i32 0, i32 %3)
%9 = load i8, i8* %6
%10 = icmp eq i8 %9, 0
br i1 %10, label %23, label %11
11: ; preds = %4, %18
%12 = phi i8 [ %21, %18 ], [ %9, %4 ]
%13 = phi i8* [ %20, %18 ], [ %0, %4 ]
%14 = phi i8* [ %19, %18 ], [ %6, %4 ]
store i8 %12, i8* %13
%15 = call float @CG_Text_Width(i8* %0, float %1, i32 0)
%16 = fcmp ogt float %15, %2
br i1 %16, label %17, label %18
17: ; preds = %11
store i8 0, i8* %13
br label %23
18: ; preds = %11
%19 = getelementptr inbounds i8, i8* %14, i64 1
%20 = getelementptr inbounds i8, i8* %13, i64 1
%21 = load i8, i8* %19
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %11
23: ; preds = %18, %4, %17
ret void
}