#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 */
typedef int /*<<< orphan*/ lineText;

/* Variables and functions */
int /*<<< orphan*/ G_Error(char *, int);
int /*<<< orphan*/ Q_strncpyz(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *strstr(char *, char *);
char *Bot_LineText(char *text) {
  static char lineText[1024];
  int len;
  len = strstr(text, "\n") - text;
  if (len <= 0)
    return "";
  if (len >= sizeof(lineText) - 1)
    G_Error("Bot_LineText: max line length exceed (%i)", (int)sizeof(lineText));
  memset(lineText, 0, sizeof(lineText));
  Q_strncpyz(lineText, text, len);
  return lineText;
}


x86 assembly (clang, -O0):
<Bot_LineText>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1050 <strstr@plt>
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     1180 <Bot_LineText+0x40>
lea    0xe8a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11d2 <Bot_LineText+0x92>
movslq -0x14(%rbp),%rax
cmp    $0x3ff,%rax
jb     11a1 <Bot_LineText+0x61>
lea    0xe6b(%rip),%rdi
mov    $0x400,%esi
call   1040 <G_Error@plt>
lea    0x2ea8(%rip),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0x2e8e(%rip),%rdi
call   1060 <Q_strncpyz@plt>
lea    0x2e82(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Bot_LineText>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,%rbx
sub    %r14d,%ebx
test   %ebx,%ebx
jle    119a <Bot_LineText+0x5a>
cmp    $0x3ff,%ebx
jb     1175 <Bot_LineText+0x35>
lea    0xe95(%rip),%rdi
mov    $0x400,%esi
call   1050 <G_Error@plt>
lea    0x2ed4(%rip),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1060 <Q_strncpyz@plt>
jmp    11a1 <Bot_LineText+0x61>
lea    0xe88(%rip),%r15
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@Bot_LineText.lineText = internal global [1024 x i8] zeroinitializer
@.str = [2 x i8] c"\0A\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [42 x i8] c"Bot_LineText: max line length exceed (%i)\00"
define i8* @Bot_LineText(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i8* @strstr(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = load i8*, i8** %3
%8 = ptrtoint i8* %6 to i64
%9 = ptrtoint i8* %7 to i64
%10 = sub i64 %8, %9
%11 = trunc i64 %10 to i32
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp sle i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %1
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %26
15: ; preds = %1
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = icmp uge i64 %17, 1023
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @G_Error(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 1024)
br label %21
21: ; preds = %19, %15
%22 = call i32 @memset(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @Bot_LineText.lineText, i64 0, i64 0), i32 0, i32 1024)
%23 = load i8*, i8** %3
%24 = load i32, i32* %4
%25 = call i32 @Q_strncpyz(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @Bot_LineText.lineText, i64 0, i64 0), i8* %23, i32 %24)
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @Bot_LineText.lineText, i64 0, i64 0), i8** %2
br label %26
26: ; preds = %21, %14
%27 = load i8*, i8** %2
ret i8* %27
}

LLVM IR (-O2):
@Bot_LineText.lineText = internal global [1024 x i8] zeroinitializer
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [42 x i8] c"Bot_LineText: max line length exceed (%i)\00"
define i8* @Bot_LineText(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i32 10)
%3 = ptrtoint i8* %2 to i64
%4 = ptrtoint i8* %0 to i64
%5 = sub i64 %3, %4
%6 = trunc i64 %5 to i32
%7 = icmp slt i32 %6, 1
br i1 %7, label %15, label %8
8: ; preds = %1
%9 = icmp ugt i32 %6, 1022
br i1 %9, label %10, label %12
10: ; preds = %8
%11 = tail call i32 @G_Error(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 1024)
br label %12
12: ; preds = %10, %8
%13 = tail call i32 @memset(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @Bot_LineText.lineText, i64 0, i64 0), i32 0, i32 1024)
%14 = tail call i32 @Q_strncpyz(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @Bot_LineText.lineText, i64 0, i64 0), i8* %0, i32 %6)
br label %15
15: ; preds = %1, %12
%16 = phi i8* [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @Bot_LineText.lineText, i64 0, i64 0), %12 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %1 ]
ret i8* %16
}