#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 */
scalar_t__ send_command_to_variable_server(int, char *);
int strlen(char const *);
int /*<<< orphan*/ strncat(char *, char const *, int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int add_variable_to_server(int socket, char *variable_name) {
  char cmd[512];
  const char *prefix = "trick.var_add(\"";
  const char *suffix = "\")";
  if (sizeof(cmd) <
      (strlen(prefix) + strlen(variable_name) + strlen(suffix) + 1)) {
    return -1;
  } else {
    strncpy(cmd, prefix, sizeof(cmd));
    strncat(cmd, variable_name, (sizeof(cmd) - strlen(cmd) - 1));
    strncat(cmd, suffix, (sizeof(cmd) - strlen(cmd) - 1));
    if (send_command_to_variable_server(socket, cmd) < 0) {
      return -1;
    } else {
      return 0;
    }
  }
}


x86 assembly (clang, -O0):
<add_variable_to_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea7(%rip),%rax
mov    %rax,-0x218(%rbp)
lea    0xea9(%rip),%rax
mov    %rax,-0x220(%rbp)
mov    -0x218(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x228(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x228(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x224(%rbp)
mov    -0x220(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x224(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
movslq %eax,%rcx
mov    $0x200,%eax
cmp    %rcx,%rax
jae    11cf <add_variable_to_server+0x8f>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a8 <add_variable_to_server+0x168>
lea    -0x210(%rbp),%rdi
mov    -0x218(%rbp),%rsi
mov    $0x200,%edx
call   1030 <strncpy@plt>
lea    -0x210(%rbp),%rax
mov    %rax,-0x248(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x240(%rbp)
lea    -0x210(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x248(%rbp),%rdi
mov    -0x240(%rbp),%rsi
movslq %eax,%rcx
mov    $0x200,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
call   1050 <strncat@plt>
lea    -0x210(%rbp),%rax
mov    %rax,-0x238(%rbp)
mov    -0x220(%rbp),%rax
mov    %rax,-0x230(%rbp)
lea    -0x210(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x238(%rbp),%rdi
mov    -0x230(%rbp),%rsi
movslq %eax,%rcx
mov    $0x200,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
call   1050 <strncat@plt>
mov    -0x8(%rbp),%edi
lea    -0x210(%rbp),%rsi
call   1060 <send_command_to_variable_server@plt>
cmp    $0x0,%rax
jge    12a1 <add_variable_to_server+0x161>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a8 <add_variable_to_server+0x168>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_variable_to_server>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%r15
mov    %edi,%r14d
lea    0xea6(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    0xe9e(%rip),%rdi
call   1040 <strlen@plt>
add    %ebp,%ebx
lea    (%rax,%rbx,1),%ecx
add    $0xfffffe00,%ecx
mov    $0xffffffff,%eax
cmp    $0xfffffdff,%ecx
jb     11ef <add_variable_to_server+0xaf>
lea    0xe6a(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x200,%edx
call   1030 <strncpy@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    $0x1ff,%ebx
mov    $0x1ff,%edx
sub    %eax,%edx
mov    %rbp,%rdi
mov    %r15,%rsi
call   1050 <strncat@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebx
lea    0xe3a(%rip),%rsi
mov    %rbp,%rdi
mov    %ebx,%edx
call   1050 <strncat@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
call   1060 <send_command_to_variable_server@plt>
sar    $0x3f,%rax
add    $0x208,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"trick.var_add(\22\00"
@.str.1 = [3 x i8] c"\22)\00"
define i32 @add_variable_to_server(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [512 x i8]
%7 = alloca i8*
%8 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %8
%9 = load i8*, i8** %7
%10 = call i32 @strlen(i8* %9)
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 %10, %12
%14 = load i8*, i8** %8
%15 = call i32 @strlen(i8* %14)
%16 = add nsw i32 %13, %15
%17 = add nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = icmp ult i64 512, %18
br i1 %19, label %20, label %21
20: ; preds = %2
store i32 -1, i32* %3
br label %49
21: ; preds = %2
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%23 = load i8*, i8** %7
%24 = call i32 @strncpy(i8* %22, i8* %23, i32 512)
%25 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%26 = load i8*, i8** %5
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%28 = call i32 @strlen(i8* %27)
%29 = sext i32 %28 to i64
%30 = sub i64 512, %29
%31 = sub i64 %30, 1
%32 = trunc i64 %31 to i32
%33 = call i32 @strncat(i8* %25, i8* %26, i32 %32)
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%35 = load i8*, i8** %8
%36 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%37 = call i32 @strlen(i8* %36)
%38 = sext i32 %37 to i64
%39 = sub i64 512, %38
%40 = sub i64 %39, 1
%41 = trunc i64 %40 to i32
%42 = call i32 @strncat(i8* %34, i8* %35, i32 %41)
%43 = load i32, i32* %4
%44 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%45 = call i64 @send_command_to_variable_server(i32 %43, i8* %44)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %21
store i32 -1, i32* %3
br label %49
48: ; preds = %21
store i32 0, i32* %3
br label %49
49: ; preds = %48, %47, %20
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@.str = [16 x i8] c"trick.var_add(\22\00"
@.str.1 = [3 x i8] c"\22)\00"
define i32 @add_variable_to_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* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @strlen(i8* %1)
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = add i32 %5, -512
%9 = add i32 %8, %6
%10 = add i32 %9, %7
%11 = icmp ult i32 %10, -513
br i1 %11, label %23, label %12
12: ; preds = %2
%13 = call i32 @strncpy(i8* %4, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 512)
%14 = call i32 @strlen(i8* %4)
%15 = sub i32 511, %14
%16 = call i32 @strncat(i8* %4, i8* %1, i32 %15)
%17 = call i32 @strlen(i8* %4)
%18 = sub i32 511, %17
%19 = call i32 @strncat(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = call i64 @send_command_to_variable_server(i32 %0, i8* %4)
%21 = ashr i64 %20, 63
%22 = trunc i64 %21 to i32
br label %23
23: ; preds = %12, %2
%24 = phi i32 [ -1, %2 ], [ %22, %12 ]
ret i32 %24
}