#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 */
int /*<<< orphan*/ SendToICS(char *);
int /*<<< orphan*/ SendToPlayer(char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void SendMultiLineToICS(char *buf) {
  char temp[512 + 1], *p;
  int len;
  len = strlen(buf);
  if (len > 512)
    len = 512;
  strncpy(temp, buf, len);
  temp[len] = 0;
  p = temp;
  while (*p) {
    if (*p == '\n' || *p == '\r')
      *p = ' ';
    ++p;
  }
  strcat(temp, "\n");
  SendToICS(temp);
  SendToPlayer(temp, strlen(temp));
}


x86 assembly (clang, -O0):
<SendMultiLineToICS>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x21c(%rbp)
cmpl   $0x200,-0x21c(%rbp)
jle    1188 <SendMultiLineToICS+0x38>
movl   $0x200,-0x21c(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x21c(%rbp),%edx
call   1030 <strncpy@plt>
movslq -0x21c(%rbp),%rax
movb   $0x0,-0x210(%rbp,%rax,1)
lea    -0x210(%rbp),%rax
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rax
cmpb   $0x0,(%rax)
je     1212 <SendMultiLineToICS+0xc2>
mov    -0x218(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     11f1 <SendMultiLineToICS+0xa1>
mov    -0x218(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
jne    11fb <SendMultiLineToICS+0xab>
mov    -0x218(%rbp),%rax
movb   $0x20,(%rax)
mov    -0x218(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x218(%rbp)
jmp    11bb <SendMultiLineToICS+0x6b>
lea    -0x210(%rbp),%rdi
lea    0xde0(%rip),%rsi
call   1060 <strcat@plt>
lea    -0x210(%rbp),%rdi
call   1070 <SendToICS@plt>
lea    -0x210(%rbp),%rax
mov    %rax,-0x228(%rbp)
lea    -0x210(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x228(%rbp),%rdi
mov    %eax,%esi
call   1040 <SendToPlayer@plt>
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SendMultiLineToICS>:
push   %rbp
push   %r14
push   %rbx
sub    $0x210,%rsp
mov    %rdi,%r14
mov    %rsp,%rbx
call   1050 <strlen@plt>
cmp    $0x200,%eax
mov    $0x200,%ebp
cmovl  %eax,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movslq %ebp,%rax
movb   $0x0,(%rsp,%rax,1)
jmp    1197 <SendMultiLineToICS+0x47>
nopl   0x0(%rax)
movb   $0x20,(%rbx)
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0xa,%al
je     1190 <SendMultiLineToICS+0x40>
cmp    $0xd,%al
je     1190 <SendMultiLineToICS+0x40>
test   %al,%al
jne    1193 <SendMultiLineToICS+0x43>
lea    0xe53(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
call   1070 <SendToICS@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <SendToPlayer@plt>
add    $0x210,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define void @SendMultiLineToICS(i8* %0) {
%2 = alloca i8*
%3 = alloca [513 x i8]
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp sgt i32 %8, 512
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 512, i32* %5
br label %11
11: ; preds = %10, %1
%12 = getelementptr inbounds [513 x i8], [513 x i8]* %3, i64 0, i64 0
%13 = load i8*, i8** %2
%14 = load i32, i32* %5
%15 = call i32 @strncpy(i8* %12, i8* %13, i32 %14)
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [513 x i8], [513 x i8]* %3, i64 0, i64 %17
store i8 0, i8* %18
%19 = getelementptr inbounds [513 x i8], [513 x i8]* %3, i64 0, i64 0
store i8* %19, i8** %4
br label %20
20: ; preds = %36, %11
%21 = load i8*, i8** %4
%22 = load i8, i8* %21
%23 = icmp ne i8 %22, 0
br i1 %23, label %24, label %39
24: ; preds = %20
%25 = load i8*, i8** %4
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 10
br i1 %28, label %34, label %29
29: ; preds = %24
%30 = load i8*, i8** %4
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 13
br i1 %33, label %34, label %36
34: ; preds = %29, %24
%35 = load i8*, i8** %4
store i8 32, i8* %35
br label %36
36: ; preds = %34, %29
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %4
br label %20
39: ; preds = %20
%40 = getelementptr inbounds [513 x i8], [513 x i8]* %3, i64 0, i64 0
%41 = call i32 @strcat(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%42 = getelementptr inbounds [513 x i8], [513 x i8]* %3, i64 0, i64 0
%43 = call i32 @SendToICS(i8* %42)
%44 = getelementptr inbounds [513 x i8], [513 x i8]* %3, i64 0, i64 0
%45 = getelementptr inbounds [513 x i8], [513 x i8]* %3, i64 0, i64 0
%46 = call i32 @strlen(i8* %45)
%47 = call i32 @SendToPlayer(i8* %44, i32 %46)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define void @SendMultiLineToICS(i8* %0) {
%2 = alloca [513 x i8]
%3 = getelementptr inbounds [513 x i8], [513 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp slt i32 %4, 512
%6 = select i1 %5, i32 %4, i32 512
%7 = call i32 @strncpy(i8* %3, i8* %0, i32 %6)
%8 = sext i32 %6 to i64
%9 = getelementptr inbounds [513 x i8], [513 x i8]* %2, i64 0, i64 %8
store i8 0, i8* %9
br label %10
10: ; preds = %14, %1
%11 = phi i8* [ %3, %1 ], [ %15, %14 ]
%12 = load i8, i8* %11
switch i8 %12, label %14 [
i8 0, label %16
i8 10, label %13
i8 13, label %13
]
13: ; preds = %10, %10
store i8 32, i8* %11
br label %14
14: ; preds = %10, %13
%15 = getelementptr inbounds i8, i8* %11, i64 1
br label %10
16: ; preds = %10
%17 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @SendToICS(i8* %3)
%19 = call i32 @strlen(i8* %3)
%20 = call i32 @SendToPlayer(i8* %3, i32 %19)
ret void
}