#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 osal_snd_msg(int, char *);
int osal_valloc_msg_wait(int, void **, int, int);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
int shell_exec_async(const char *cmd) {
  int errno;
  if (strlen(cmd) > 255)
    return -1;
  char *msg;
  errno = osal_valloc_msg_wait(0x94020A, (void **)&msg,
                               sizeof(int) + strlen(cmd) + 1, 1);
  if (errno)
    return errno;
  ((int *)msg)[0] = 0x940005;
  strcpy(msg + sizeof(int), cmd);
  errno = osal_snd_msg(0x94020A, msg);
  if (errno)
    return errno;
  return 0;
}


x86 assembly (clang, -O0):
<shell_exec_async>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0xff,%eax
jle    116c <shell_exec_async+0x2c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f4 <shell_exec_async+0xb4>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cltq
add    $0x4,%rax
add    $0x1,%rax
mov    %eax,%edx
mov    $0x94020a,%edi
lea    -0x20(%rbp),%rsi
mov    $0x1,%ecx
call   1050 <osal_valloc_msg_wait@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11ac <shell_exec_async+0x6c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f4 <shell_exec_async+0xb4>
mov    -0x20(%rbp),%rax
movl   $0x940005,(%rax)
mov    -0x20(%rbp),%rdi
add    $0x4,%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rsi
mov    $0x94020a,%edi
call   1060 <osal_snd_msg@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11ed <shell_exec_async+0xad>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f4 <shell_exec_async+0xb4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shell_exec_async>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0xff,%ecx
jg     11a5 <shell_exec_async+0x65>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x5(%rax),%edx
lea    0x8(%rsp),%rsi
mov    $0x94020a,%edi
mov    $0x1,%ecx
call   1050 <osal_valloc_msg_wait@plt>
test   %eax,%eax
jne    11a5 <shell_exec_async+0x65>
mov    0x8(%rsp),%rdi
movl   $0x940005,(%rdi)
add    $0x4,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    0x8(%rsp),%rsi
mov    $0x94020a,%edi
call   1060 <osal_snd_msg@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @shell_exec_async(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
%8 = icmp sgt i32 %7, 255
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 -1, i32* %2
br label %37
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
%13 = sext i32 %12 to i64
%14 = add i64 4, %13
%15 = add i64 %14, 1
%16 = trunc i64 %15 to i32
%17 = call i32 @osal_valloc_msg_wait(i32 9699850, i8** %5, i32 %16, i32 1)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %10
%21 = load i32, i32* %4
store i32 %21, i32* %2
br label %37
22: ; preds = %10
%23 = load i8*, i8** %5
%24 = bitcast i8* %23 to i32*
%25 = getelementptr inbounds i32, i32* %24, i64 0
store i32 9699333, i32* %25
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i64 4
%28 = load i8*, i8** %3
%29 = call i32 @strcpy(i8* %27, i8* %28)
%30 = load i8*, i8** %5
%31 = call i32 @osal_snd_msg(i32 9699850, i8* %30)
store i32 %31, i32* %4
%32 = load i32, i32* %4
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %22
%35 = load i32, i32* %4
store i32 %35, i32* %2
br label %37
36: ; preds = %22
store i32 0, i32* %2
br label %37
37: ; preds = %36, %34, %20, %9
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
define i32 @shell_exec_async(i8* %0) {
%2 = alloca i8*
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %3, 255
br i1 %4, label %21, label %5
5: ; preds = %1
%6 = bitcast i8** %2 to i8*
%7 = tail call i32 @strlen(i8* %0)
%8 = add i32 %7, 5
%9 = call i32 @osal_valloc_msg_wait(i32 9699850, i8** %2, i32 %8, i32 1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %5
%12 = bitcast i8** %2 to i32**
%13 = load i32*, i32** %12
store i32 9699333, i32* %13
%14 = getelementptr inbounds i32, i32* %13, i64 1
%15 = bitcast i32* %14 to i8*
%16 = call i32 @strcpy(i8* %15, i8* %0)
%17 = load i8*, i8** %2
%18 = call i32 @osal_snd_msg(i32 9699850, i8* %17)
br label %19
19: ; preds = %11, %5
%20 = phi i32 [ %9, %5 ], [ %18, %11 ]
br label %21
21: ; preds = %1, %19
%22 = phi i32 [ %20, %19 ], [ -1, %1 ]
ret i32 %22
}