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

/* Variables and functions */
int strlen(char const *);
size_t write_all(int, ...);
int mpath_send_cmd(int fd, const char *cmd) {
  size_t len;
  if (cmd != NULL)
    len = strlen(cmd) + 1;
  else
    len = 0;
  if (write_all(fd, &len, sizeof(len)) != sizeof(len))
    return -1;
  if (len && write_all(fd, cmd, len) != len)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<mpath_send_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1151 <mpath_send_cmd+0x31>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x18(%rbp)
jmp    1159 <mpath_send_cmd+0x39>
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1040 <write_all@plt>
cmp    $0x8,%rax
je     1182 <mpath_send_cmd+0x62>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bc <mpath_send_cmd+0x9c>
cmpq   $0x0,-0x18(%rbp)
je     11b5 <mpath_send_cmd+0x95>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1040 <write_all@plt>
cmp    -0x18(%rbp),%rax
je     11b5 <mpath_send_cmd+0x95>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bc <mpath_send_cmd+0x9c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpath_send_cmd>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
test   %rsi,%rsi
je     1142 <mpath_send_cmd+0x22>
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
jmp    1144 <mpath_send_cmd+0x24>
xor    %eax,%eax
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    $0x8,%edx
mov    %r14d,%edi
xor    %eax,%eax
call   1040 <write_all@plt>
mov    $0xffffffff,%ebp
cmp    $0x8,%rax
jne    1188 <mpath_send_cmd+0x68>
mov    0x8(%rsp),%rdx
test   %rdx,%rdx
je     1186 <mpath_send_cmd+0x66>
mov    %r14d,%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <write_all@plt>
cmp    0x8(%rsp),%rax
jne    1188 <mpath_send_cmd+0x68>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @mpath_send_cmd(i32 %0, i8* %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = icmp eq i8* %1, null
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = tail call i32 @strlen(i8* %1)
%8 = add nsw i32 %7, 1
%9 = sext i32 %8 to i64
br label %10
10: ; preds = %2, %6
%11 = phi i64 [ %9, %6 ], [ 0, %2 ]
store i64 %11, i64* %3
%12 = call i64 (i32, ...) @write_all(i32 %0, i64* %3, i64 8)
%13 = icmp eq i64 %12, 8
br i1 %13, label %14, label %22
14: ; preds = %10
%15 = load i64, i64* %3
%16 = icmp eq i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = call i64 (i32, ...) @write_all(i32 %0, i8* %1, i64 %15)
%19 = load i64, i64* %3
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %17, %14
br label %22
22: ; preds = %17, %10, %21
%23 = phi i32 [ 0, %21 ], [ -1, %10 ], [ -1, %17 ]
ret i32 %23
}