#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 /*<<< orphan*/ get_random(int);
int /*<<< orphan*/ inband_close(unsigned int);
unsigned int inband_open(char *, char *, int, int /*<<< orphan*/);
scalar_t__ inband_write(unsigned int, int /*<<< orphan*/, int, unsigned char *,
                        int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strlen(unsigned char *);
int inband_remote_cmd(unsigned char *cmd) {
  unsigned char *buf;
  unsigned int channel = -1;
  channel = inband_open("br-lan0", ("001234567899"), 0x8899, 0);
  if (channel < 0 ||
      inband_write(channel, get_random(65535), 0x04, cmd, strlen(cmd), 0) < 0) {
    printf("inband sent remote command failed\n");
  }
  inband_close(channel);
}


x86 assembly (clang, -O0):
<inband_remote_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
lea    0xe86(%rip),%rdi
lea    0xe87(%rip),%rsi
mov    $0x8899,%edx
xor    %ecx,%ecx
call   1070 <inband_open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jb     11e2 <inband_remote_cmd+0x82>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    $0xffff,%edi
call   1040 <get_random@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%rcx
mov    %eax,%r8d
mov    $0x4,%edx
xor    %r9d,%r9d
call   1080 <inband_write@plt>
cmp    $0x0,%rax
jge    11ee <inband_remote_cmd+0x8e>
lea    0xe2c(%rip),%rdi
call   1060 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1030 <inband_close@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inband_remote_cmd>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    0xe92(%rip),%rdi
lea    0xe93(%rip),%rsi
mov    $0x8899,%edx
xor    %ecx,%ecx
call   1070 <inband_open@plt>
mov    %eax,%r14d
mov    $0xffff,%edi
call   1050 <get_random@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r14d,%edi
mov    %ebp,%esi
mov    $0x4,%edx
mov    %rbx,%rcx
mov    %eax,%r8d
xor    %r9d,%r9d
call   1080 <inband_write@plt>
test   %rax,%rax
jns    11c1 <inband_remote_cmd+0x61>
lea    0xe59(%rip),%rdi
call   1040 <puts@plt>
mov    %r14d,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <inband_close@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"br-lan0\00"
@.str.1 = [13 x i8] c"001234567899\00"
@.str.2 = [35 x i8] c"inband sent remote command failed\0A\00"
define i32 @inband_remote_cmd(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i32 -1, i32* %5
%6 = call i32 @inband_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 34969, i32 0)
store i32 %6, i32* %5
%7 = load i32, i32* %5
%8 = icmp ult i32 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %1
%10 = load i32, i32* %5
%11 = call i32 @get_random(i32 65535)
%12 = load i8*, i8** %3
%13 = load i8*, i8** %3
%14 = call i32 @strlen(i8* %13)
%15 = call i64 @inband_write(i32 %10, i32 %11, i32 4, i8* %12, i32 %14, i32 0)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %9, %1
%18 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %17, %9
%20 = load i32, i32* %5
%21 = call i32 @inband_close(i32 %20)
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@.str = [8 x i8] c"br-lan0\00"
@.str.1 = [13 x i8] c"001234567899\00"
@str = [34 x i8] c"inband sent remote command failed\00"
define i32 @inband_remote_cmd(i8* %0) {
%2 = tail call i32 @inband_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 34969, i32 0)
%3 = tail call i32 @get_random(i32 65535)
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i64 @inband_write(i32 %2, i32 %3, i32 4, i8* %0, i32 %4, i32 0)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
%10 = tail call i32 @inband_close(i32 %2)
ret i32 undef
}