#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_sever_with_units(int socket, char *variable_name,
                                     char *units) {
  char cmd[512];
  const char *prefix = "trick.var_add(\"";
  const char *infix = "\", \"";
  const char *suffix = "\")";
  if (sizeof(cmd) < (strlen(prefix) + strlen(variable_name) + strlen(infix) +
                     strlen(units) + strlen(suffix) + 1)) {
    return -1;
  } else {
    strncpy(cmd, prefix, sizeof(cmd));
    strncat(cmd, variable_name, (sizeof(cmd) - strlen(cmd) - 1));
    strncat(cmd, infix, (sizeof(cmd) - strlen(cmd) - 1));
    strncat(cmd, units, (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_sever_with_units>:
push   %rbp
mov    %rsp,%rbp
sub    $0x290,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xea3(%rip),%rax
mov    %rax,-0x228(%rbp)
lea    0xea5(%rip),%rax
mov    %rax,-0x230(%rbp)
lea    0xe9c(%rip),%rax
mov    %rax,-0x238(%rbp)
mov    -0x228(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x248(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x248(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x244(%rbp)
mov    -0x230(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x244(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x240(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x240(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x23c(%rbp)
mov    -0x238(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x23c(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
movslq %eax,%rcx
mov    $0x200,%eax
cmp    %rcx,%rax
jae    1216 <add_variable_to_sever_with_units+0xd6>
movl   $0xffffffff,-0x4(%rbp)
jmp    1384 <add_variable_to_sever_with_units+0x244>
lea    -0x220(%rbp),%rdi
mov    -0x228(%rbp),%rsi
mov    $0x200,%edx
call   1030 <strncpy@plt>
lea    -0x220(%rbp),%rax
mov    %rax,-0x288(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x280(%rbp)
lea    -0x220(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x288(%rbp),%rdi
mov    -0x280(%rbp),%rsi
movslq %eax,%rcx
mov    $0x200,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
call   1050 <strncat@plt>
lea    -0x220(%rbp),%rax
mov    %rax,-0x278(%rbp)
mov    -0x230(%rbp),%rax
mov    %rax,-0x270(%rbp)
lea    -0x220(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x278(%rbp),%rdi
mov    -0x270(%rbp),%rsi
movslq %eax,%rcx
mov    $0x200,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
call   1050 <strncat@plt>
lea    -0x220(%rbp),%rax
mov    %rax,-0x268(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x260(%rbp)
lea    -0x220(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x268(%rbp),%rdi
mov    -0x260(%rbp),%rsi
movslq %eax,%rcx
mov    $0x200,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
call   1050 <strncat@plt>
lea    -0x220(%rbp),%rax
mov    %rax,-0x258(%rbp)
mov    -0x238(%rbp),%rax
mov    %rax,-0x250(%rbp)
lea    -0x220(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x258(%rbp),%rdi
mov    -0x250(%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    -0x220(%rbp),%rsi
call   1060 <send_command_to_variable_server@plt>
cmp    $0x0,%rax
jge    137d <add_variable_to_sever_with_units+0x23d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1384 <add_variable_to_sever_with_units+0x244>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x290,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_variable_to_sever_with_units>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rdx,%r15
mov    %rsi,%r13
mov    %edi,0xc(%rsp)
lea    0xe9e(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
lea    0xe95(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%r14d
lea    0xe81(%rip),%rdi
call   1040 <strlen@plt>
add    %r12d,%ebp
add    %ebx,%ebp
add    %r14d,%ebp
lea    (%rax,%rbp,1),%ecx
add    $0xfffffe00,%ecx
mov    $0xffffffff,%eax
cmp    $0xfffffdff,%ecx
jb     1259 <add_variable_to_sever_with_units+0x119>
lea    0xe3e(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x200,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0x1ff,%r12d
mov    $0x1ff,%edx
sub    %eax,%edx
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <strncat@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0x1ff,%edx
sub    %eax,%edx
lea    0xe06(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strncat@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0x1ff,%edx
sub    %eax,%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strncat@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
sub    %eax,%r12d
lea    0xdd7(%rip),%rsi
mov    %rbx,%rdi
mov    %r12d,%edx
call   1050 <strncat@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
call   1060 <send_command_to_variable_server@plt>
sar    $0x3f,%rax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"trick.var_add(\22\00"
@.str.1 = [5 x i8] c"\22, \22\00"
@.str.2 = [3 x i8] c"\22)\00"
define i32 @add_variable_to_sever_with_units(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [512 x i8]
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %9
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %10
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %11
%12 = load i8*, i8** %9
%13 = call i32 @strlen(i8* %12)
%14 = load i8*, i8** %6
%15 = call i32 @strlen(i8* %14)
%16 = add nsw i32 %13, %15
%17 = load i8*, i8** %10
%18 = call i32 @strlen(i8* %17)
%19 = add nsw i32 %16, %18
%20 = load i8*, i8** %7
%21 = call i32 @strlen(i8* %20)
%22 = add nsw i32 %19, %21
%23 = load i8*, i8** %11
%24 = call i32 @strlen(i8* %23)
%25 = add nsw i32 %22, %24
%26 = add nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = icmp ult i64 512, %27
br i1 %28, label %29, label %30
29: ; preds = %3
store i32 -1, i32* %4
br label %76
30: ; preds = %3
%31 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%32 = load i8*, i8** %9
%33 = call i32 @strncpy(i8* %31, i8* %32, i32 512)
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%35 = load i8*, i8** %6
%36 = getelementptr inbounds [512 x i8], [512 x i8]* %8, 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 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%44 = load i8*, i8** %10
%45 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%46 = call i32 @strlen(i8* %45)
%47 = sext i32 %46 to i64
%48 = sub i64 512, %47
%49 = sub i64 %48, 1
%50 = trunc i64 %49 to i32
%51 = call i32 @strncat(i8* %43, i8* %44, i32 %50)
%52 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%53 = load i8*, i8** %7
%54 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%55 = call i32 @strlen(i8* %54)
%56 = sext i32 %55 to i64
%57 = sub i64 512, %56
%58 = sub i64 %57, 1
%59 = trunc i64 %58 to i32
%60 = call i32 @strncat(i8* %52, i8* %53, i32 %59)
%61 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%62 = load i8*, i8** %11
%63 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%64 = call i32 @strlen(i8* %63)
%65 = sext i32 %64 to i64
%66 = sub i64 512, %65
%67 = sub i64 %66, 1
%68 = trunc i64 %67 to i32
%69 = call i32 @strncat(i8* %61, i8* %62, i32 %68)
%70 = load i32, i32* %5
%71 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%72 = call i64 @send_command_to_variable_server(i32 %70, i8* %71)
%73 = icmp slt i64 %72, 0
br i1 %73, label %74, label %75
74: ; preds = %30
store i32 -1, i32* %4
br label %76
75: ; preds = %30
store i32 0, i32* %4
br label %76
76: ; preds = %75, %74, %29
%77 = load i32, i32* %4
ret i32 %77
}

LLVM IR (-O2):
@.str = [16 x i8] c"trick.var_add(\22\00"
@.str.1 = [5 x i8] c"\22, \22\00"
@.str.2 = [3 x i8] c"\22)\00"
define i32 @add_variable_to_sever_with_units(i32 %0, i8* %1, i8* %2) {
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @strlen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @strlen(i8* %1)
%8 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @strlen(i8* %2)
%10 = tail call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%11 = add i32 %6, -512
%12 = add i32 %11, %7
%13 = add i32 %12, %8
%14 = add i32 %13, %9
%15 = add i32 %14, %10
%16 = icmp ult i32 %15, -513
br i1 %16, label %34, label %17
17: ; preds = %3
%18 = call i32 @strncpy(i8* %5, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 512)
%19 = call i32 @strlen(i8* %5)
%20 = sub i32 511, %19
%21 = call i32 @strncat(i8* %5, i8* %1, i32 %20)
%22 = call i32 @strlen(i8* %5)
%23 = sub i32 511, %22
%24 = call i32 @strncat(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = call i32 @strlen(i8* %5)
%26 = sub i32 511, %25
%27 = call i32 @strncat(i8* %5, i8* %2, i32 %26)
%28 = call i32 @strlen(i8* %5)
%29 = sub i32 511, %28
%30 = call i32 @strncat(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = call i64 @send_command_to_variable_server(i32 %0, i8* %5)
%32 = ashr i64 %31, 63
%33 = trunc i64 %32 to i32
br label %34
34: ; preds = %17, %3
%35 = phi i32 [ -1, %3 ], [ %33, %17 ]
ret i32 %35
}