#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 cbm_listen(int, int, int);
int /*<<< orphan*/ cbm_unlisten(int);
int strlen(char *);
int write(int, char *, int);
int cbm_exec_command(int f, int drv, char *cmd, int len) {
  int rv;
  rv = cbm_listen(f, drv, 15);
  if (rv == 0) {
    if (len == 0) {
      len = strlen(cmd);
    }
    rv = write(f, cmd, len) != len;
    cbm_unlisten(f);
  }
  return rv;
}


x86 assembly (clang, -O0):
<cbm_exec_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    $0xf,%edx
call   1060 <cbm_listen@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11ad <cbm_exec_command+0x6d>
cmpl   $0x0,-0x14(%rbp)
jne    1188 <cbm_exec_command+0x48>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
cmp    -0x14(%rbp),%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <cbm_unlisten@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cbm_exec_command>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %edi,%ebx
mov    $0xf,%edx
call   1060 <cbm_listen@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    118c <cbm_exec_command+0x4c>
test   %r15d,%r15d
jne    116f <cbm_exec_command+0x2f>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15d,%edx
call   1030 <write@plt>
xor    %ebp,%ebp
cmp    %r15d,%eax
setne  %bpl
mov    %ebx,%edi
call   1050 <cbm_unlisten@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @cbm_exec_command(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = call i32 @cbm_listen(i32 %10, i32 %11, i32 15)
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %31
15: ; preds = %4
%16 = load i32, i32* %8
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i8*, i8** %7
%20 = call i32 @strlen(i8* %19)
store i32 %20, i32* %8
br label %21
21: ; preds = %18, %15
%22 = load i32, i32* %5
%23 = load i8*, i8** %7
%24 = load i32, i32* %8
%25 = call i32 @write(i32 %22, i8* %23, i32 %24)
%26 = load i32, i32* %8
%27 = icmp ne i32 %25, %26
%28 = zext i1 %27 to i32
store i32 %28, i32* %9
%29 = load i32, i32* %5
%30 = call i32 @cbm_unlisten(i32 %29)
br label %31
31: ; preds = %21, %4
%32 = load i32, i32* %9
ret i32 %32
}

LLVM IR (-O2):
define i32 @cbm_exec_command(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = tail call i32 @cbm_listen(i32 %0, i32 %1, i32 15)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %17
7: ; preds = %4
%8 = icmp eq i32 %3, 0
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 @strlen(i8* %2)
br label %11
11: ; preds = %9, %7
%12 = phi i32 [ %10, %9 ], [ %3, %7 ]
%13 = tail call i32 @write(i32 %0, i8* %2, i32 %12)
%14 = icmp ne i32 %13, %12
%15 = zext i1 %14 to i32
%16 = tail call i32 @cbm_unlisten(i32 %0)
br label %17
17: ; preds = %11, %4
%18 = phi i32 [ %15, %11 ], [ %5, %4 ]
ret i32 %18
}