#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*/ __u_char;

/* Variables and functions */
int cbmarch_listen(int, int /*<<< orphan*/, int);
scalar_t__ cbmarch_raw_write(int, void const *, size_t);
int /*<<< orphan*/ cbmarch_unlisten(int);
scalar_t__ strlen(void const *);
int cbm_exec_command(int HandleDevice, __u_char DeviceAddress,
                     const void *Command, size_t Size) {
  int rv;
  ;
  rv = cbmarch_listen(HandleDevice, DeviceAddress, 15);
  if (rv == 0) {
    if (Size == 0) {
      Size = (size_t)strlen(Command);
    }
    rv = (size_t)cbmarch_raw_write(HandleDevice, Command, Size) != Size;
    cbmarch_unlisten(HandleDevice);
  }
  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    %rcx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    $0xf,%edx
call   1040 <cbmarch_listen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11b2 <cbm_exec_command+0x72>
cmpq   $0x0,-0x18(%rbp)
jne    118b <cbm_exec_command+0x4b>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <cbmarch_raw_write@plt>
cmp    -0x18(%rbp),%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <cbmarch_unlisten@plt>
mov    -0x1c(%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    %rcx,%r14
mov    %rdx,%r15
mov    %edi,%ebx
mov    $0xf,%edx
call   1040 <cbmarch_listen@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    118c <cbm_exec_command+0x4c>
test   %r14,%r14
jne    116f <cbm_exec_command+0x2f>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rax,%r14
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1060 <cbmarch_raw_write@plt>
xor    %ebp,%ebp
cmp    %r14,%rax
setne  %bpl
mov    %ebx,%edi
call   1050 <cbmarch_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, i64 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = call i32 @cbmarch_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 i64, i64* %8
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i8*, i8** %7
%20 = call i64 @strlen(i8* %19)
store i64 %20, i64* %8
br label %21
21: ; preds = %18, %15
%22 = load i32, i32* %5
%23 = load i8*, i8** %7
%24 = load i64, i64* %8
%25 = call i64 @cbmarch_raw_write(i32 %22, i8* %23, i64 %24)
%26 = load i64, i64* %8
%27 = icmp ne i64 %25, %26
%28 = zext i1 %27 to i32
store i32 %28, i32* %9
%29 = load i32, i32* %5
%30 = call i32 @cbmarch_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, i64 %3) {
%5 = tail call i32 @cbmarch_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 i64 %3, 0
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i64 @strlen(i8* dereferenceable(1) %2)
br label %11
11: ; preds = %9, %7
%12 = phi i64 [ %10, %9 ], [ %3, %7 ]
%13 = tail call i64 @cbmarch_raw_write(i32 %0, i8* %2, i64 %12)
%14 = icmp ne i64 %13, %12
%15 = zext i1 %14 to i32
%16 = tail call i32 @cbmarch_unlisten(i32 %0)
br label %17
17: ; preds = %11, %4
%18 = phi i32 [ %15, %11 ], [ %5, %4 ]
ret i32 %18
}