#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*/ cmd;

/* Variables and functions */
int send(int, char *, int, int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int send_command_to_variable_server(int socket, char *command) {
  char cmd[512];
  if (sizeof(cmd) < strlen(command) + 2) {
    return -1;
  } else {
    strncpy(cmd, command, sizeof(cmd));
    strncat(cmd, "\n", (sizeof(cmd) - strlen(cmd) - 1));
    return send(socket, cmd, strlen(cmd), 0);
  }
}


x86 assembly (clang, -O0):
<send_command_to_variable_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x2,%eax
movslq %eax,%rcx
mov    $0x200,%eax
cmp    %rcx,%rax
jae    117b <send_command_to_variable_server+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <send_command_to_variable_server+0xca>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x200,%edx
call   1030 <strncpy@plt>
lea    -0x210(%rbp),%rax
mov    %rax,-0x228(%rbp)
lea    -0x210(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x228(%rbp),%rdi
movslq %eax,%rcx
mov    $0x200,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
lea    0xe37(%rip),%rsi
call   1060 <strncat@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x21c(%rbp)
lea    -0x210(%rbp),%rax
mov    %rax,-0x218(%rbp)
lea    -0x210(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x21c(%rbp),%edi
mov    -0x218(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_command_to_variable_server>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
add    $0xfffffe01,%ecx
mov    $0xffffffff,%eax
cmp    $0xfffffdff,%ecx
jb     11b6 <send_command_to_variable_server+0x76>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1030 <strncpy@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    $0x1ff,%edx
sub    %eax,%edx
lea    0xe69(%rip),%rsi
mov    %rbp,%rdi
call   1060 <strncat@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define i32 @send_command_to_variable_server(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [512 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i32 @strlen(i8* %7)
%9 = add nsw i32 %8, 2
%10 = sext i32 %9 to i64
%11 = icmp ult i64 512, %10
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %30
13: ; preds = %2
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%15 = load i8*, i8** %5
%16 = call i32 @strncpy(i8* %14, i8* %15, i32 512)
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
%20 = sext i32 %19 to i64
%21 = sub i64 512, %20
%22 = sub i64 %21, 1
%23 = trunc i64 %22 to i32
%24 = call i32 @strncat(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %4
%26 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%28 = call i32 @strlen(i8* %27)
%29 = call i32 @send(i32 %25, i8* %26, i32 %28, i32 0)
store i32 %29, i32* %3
br label %30
30: ; preds = %13, %12
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define i32 @send_command_to_variable_server(i32 %0, i8* %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @strlen(i8* %1)
%6 = add i32 %5, -511
%7 = icmp ult i32 %6, -513
br i1 %7, label %15, label %8
8: ; preds = %2
%9 = call i32 @strncpy(i8* %4, i8* %1, i32 512)
%10 = call i32 @strlen(i8* %4)
%11 = sub i32 511, %10
%12 = call i32 @strncat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = call i32 @strlen(i8* %4)
%14 = call i32 @send(i32 %0, i8* %4, i32 %13, i32 0)
br label %15
15: ; preds = %2, %8
%16 = phi i32 [ %14, %8 ], [ -1, %2 ]
ret i32 %16
}