#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 set_validate_addresses(int socket, int validate) {
  char cmd[256];
  const char *prefix = "trick.var_validate_address(";
  char val[16];
  const char *suffix = ")";
  if (validate > 0)
    strncpy(val, "True", 16);
  else
    strncpy(val, "False", 16);
  if (sizeof(cmd) < (strlen(prefix) + strlen(val) + strlen(suffix) + 1)) {
    return -1;
  } else {
    strncpy(cmd, prefix, sizeof(cmd));
    strncat(cmd, val, (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):
<set_validate_addresses>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xea8(%rip),%rax
mov    %rax,-0x118(%rbp)
lea    0xeb6(%rip),%rax
mov    %rax,-0x138(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    1194 <set_validate_addresses+0x54>
lea    -0x130(%rbp),%rdi
lea    0xe99(%rip),%rsi
mov    $0x10,%edx
call   1030 <strncpy@plt>
jmp    11ac <set_validate_addresses+0x6c>
lea    -0x130(%rbp),%rdi
lea    0xe81(%rip),%rsi
mov    $0x10,%edx
call   1030 <strncpy@plt>
mov    -0x118(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x140(%rbp)
lea    -0x130(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x140(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x13c(%rbp)
mov    -0x138(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x13c(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
movslq %eax,%rcx
mov    $0x100,%eax
cmp    %rcx,%rax
jae    1210 <set_validate_addresses+0xd0>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ec <set_validate_addresses+0x1ac>
lea    -0x110(%rbp),%rdi
mov    -0x118(%rbp),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
lea    -0x110(%rbp),%rax
mov    %rax,-0x160(%rbp)
lea    -0x130(%rbp),%rax
mov    %rax,-0x158(%rbp)
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x160(%rbp),%rdi
mov    -0x158(%rbp),%rsi
movslq %eax,%rcx
mov    $0x100,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
call   1050 <strncat@plt>
lea    -0x110(%rbp),%rax
mov    %rax,-0x150(%rbp)
mov    -0x138(%rbp),%rax
mov    %rax,-0x148(%rbp)
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x150(%rbp),%rdi
mov    -0x148(%rbp),%rsi
movslq %eax,%rcx
mov    $0x100,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
call   1050 <strncat@plt>
mov    -0x8(%rbp),%edi
lea    -0x110(%rbp),%rsi
call   1060 <send_command_to_variable_server@plt>
cmp    $0x0,%rax
jge    12e5 <set_validate_addresses+0x1a5>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ec <set_validate_addresses+0x1ac>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_validate_addresses>:
push   %rbp
push   %r14
push   %rbx
sub    $0x110,%rsp
mov    %edi,%r14d
test   %esi,%esi
lea    0xec7(%rip),%rax
lea    0xec5(%rip),%rsi
cmovg  %rax,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x10,%edx
call   1030 <strncpy@plt>
lea    0xe87(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    0xe8b(%rip),%rdi
call   1040 <strlen@plt>
add    %ebp,%ebx
lea    (%rax,%rbx,1),%ecx
add    $0xffffff00,%ecx
mov    $0xffffffff,%eax
cmp    $0xfffffeff,%ecx
jb     1210 <set_validate_addresses+0xd0>
lea    0xe4b(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0xff,%ebp
mov    $0xff,%edx
sub    %eax,%edx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1050 <strncat@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebp
lea    0xe25(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1050 <strncat@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1060 <send_command_to_variable_server@plt>
sar    $0x3f,%rax
add    $0x110,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [28 x i8] c"trick.var_validate_address(\00"
@.str.1 = [2 x i8] c")\00"
@.str.2 = [5 x i8] c"True\00"
@.str.3 = [6 x i8] c"False\00"
define i32 @set_validate_addresses(i32 %0, i32 %1) {
%3 = alloca [256 x i8]
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%7 = icmp sgt i32 %1, 0
%8 = select i1 %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0)
%9 = call i32 @strncpy(i8* %6, i8* %8, i32 16)
%10 = call i32 @strlen(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @strlen(i8* %6)
%12 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = add i32 %10, -256
%14 = add i32 %13, %11
%15 = add i32 %14, %12
%16 = icmp ult i32 %15, -257
br i1 %16, label %28, label %17
17: ; preds = %2
%18 = call i32 @strncpy(i8* %5, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 256)
%19 = call i32 @strlen(i8* %5)
%20 = sub i32 255, %19
%21 = call i32 @strncat(i8* %5, i8* %6, i32 %20)
%22 = call i32 @strlen(i8* %5)
%23 = sub i32 255, %22
%24 = call i32 @strncat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = call i64 @send_command_to_variable_server(i32 %0, i8* %5)
%26 = ashr i64 %25, 63
%27 = trunc i64 %26 to i32
br label %28
28: ; preds = %17, %2
%29 = phi i32 [ -1, %2 ], [ %27, %17 ]
ret i32 %29
}