#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 get_netword(unsigned char **);
int /*<<< orphan*/ memmove(unsigned char *, unsigned char *, int);
int socket_read(int, unsigned char *, int /*<<< orphan*/);
int write(int, unsigned char *, int);
int remote_command(int fd, unsigned char *buf, int len, int conf) {
  unsigned char *p;
  int l;
  if (write(fd, buf, len) < len)
    return (0);
  if ((l = socket_read(fd, buf, 0)) < 1)
    return (0);
  p = buf + 4;
  if (get_netword(&p) == conf) {
    memmove(buf, buf + 8, l - 8);
    return (l - 8);
  }
  return (0);
}


x86 assembly (clang, -O0):
<remote_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
cmp    -0x14(%rbp),%eax
jge    1179 <remote_command+0x39>
movl   $0x0,-0x4(%rbp)
jmp    11e9 <remote_command+0xa9>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1040 <socket_read@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x1,%eax
jge    119f <remote_command+0x5f>
movl   $0x0,-0x4(%rbp)
jmp    11e9 <remote_command+0xa9>
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
call   1060 <get_netword@plt>
cmp    -0x18(%rbp),%eax
jne    11e2 <remote_command+0xa2>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
mov    -0x24(%rbp),%edx
sub    $0x8,%edx
call   1050 <memmove@plt>
mov    -0x24(%rbp),%eax
sub    $0x8,%eax
mov    %eax,-0x4(%rbp)
jmp    11e9 <remote_command+0xa9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remote_command>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%ebx
mov    %rsi,%r13
mov    %edi,%ebp
call   1030 <write@plt>
xor    %r12d,%r12d
cmp    %ebx,%eax
jl     11a2 <remote_command+0x62>
xor    %r12d,%r12d
mov    %ebp,%edi
mov    %r13,%rsi
xor    %edx,%edx
call   1040 <socket_read@plt>
test   %eax,%eax
jle    11a2 <remote_command+0x62>
mov    %eax,%r15d
lea    0x4(%r13),%rax
mov    %rax,(%rsp)
mov    %rsp,%rdi
call   1060 <get_netword@plt>
cmp    %r14d,%eax
jne    11a2 <remote_command+0x62>
lea    0x8(%r13),%rsi
add    $0xfffffff8,%r15d
mov    %r13,%rdi
mov    %r15d,%edx
call   1050 <memmove@plt>
mov    %r15d,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @remote_command(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%12 = load i32, i32* %6
%13 = load i8*, i8** %7
%14 = load i32, i32* %8
%15 = call i32 @write(i32 %12, i8* %13, i32 %14)
%16 = load i32, i32* %8
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %4
store i32 0, i32* %5
br label %41
19: ; preds = %4
%20 = load i32, i32* %6
%21 = load i8*, i8** %7
%22 = call i32 @socket_read(i32 %20, i8* %21, i32 0)
store i32 %22, i32* %11
%23 = icmp slt i32 %22, 1
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 0, i32* %5
br label %41
25: ; preds = %19
%26 = load i8*, i8** %7
%27 = getelementptr inbounds i8, i8* %26, i64 4
store i8* %27, i8** %10
%28 = call i32 @get_netword(i8** %10)
%29 = load i32, i32* %9
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %40
31: ; preds = %25
%32 = load i8*, i8** %7
%33 = load i8*, i8** %7
%34 = getelementptr inbounds i8, i8* %33, i64 8
%35 = load i32, i32* %11
%36 = sub nsw i32 %35, 8
%37 = call i32 @memmove(i8* %32, i8* %34, i32 %36)
%38 = load i32, i32* %11
%39 = sub nsw i32 %38, 8
store i32 %39, i32* %5
br label %41
40: ; preds = %25
store i32 0, i32* %5
br label %41
41: ; preds = %40, %31, %24, %18
%42 = load i32, i32* %5
ret i32 %42
}

LLVM IR (-O2):
define i32 @remote_command(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
%7 = tail call i32 @write(i32 %0, i8* %1, i32 %2)
%8 = icmp slt i32 %7, %2
br i1 %8, label %20, label %9
9: ; preds = %4
%10 = tail call i32 @socket_read(i32 %0, i8* %1, i32 0)
%11 = icmp slt i32 %10, 1
br i1 %11, label %20, label %12
12: ; preds = %9
%13 = getelementptr inbounds i8, i8* %1, i64 4
store i8* %13, i8** %5
%14 = call i32 @get_netword(i8** %5)
%15 = icmp eq i32 %14, %3
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = getelementptr inbounds i8, i8* %1, i64 8
%18 = add nsw i32 %10, -8
%19 = call i32 @memmove(i8* %1, i8* %17, i32 %18)
br label %20
20: ; preds = %12, %9, %4, %16
%21 = phi i32 [ %18, %16 ], [ 0, %4 ], [ 0, %9 ], [ 0, %12 ]
ret i32 %21
}