#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
char *alloca(unsigned int);
int /*<<< orphan*/ execl(char *, char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(char *, void const *, unsigned int);
scalar_t__ vfork();
void *dispatch_shell(unsigned short msgid, const void *data, unsigned int len,
                     unsigned int *outLen) {
  char *databuf = alloca(len + 1);
  memcpy(databuf, data, len);
  databuf[len] = 0;
  pid_t pid = vfork();
  if (pid == 0) {
    execl("/bin/bash", (const char *)databuf, NULL);
    _exit(0);
  }
}


x86 assembly (clang, -O0):
<dispatch_shell>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %di,%ax
mov    %ax,-0xa(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1040 <alloca@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    $0x0,%al
call   1060 <vfork@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11c5 <dispatch_shell+0x75>
mov    -0x30(%rbp),%rsi
lea    0xe4b(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <execl@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dispatch_shell>:
push   %r15
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r15
lea    0x1(%rbx),%edi
call   1040 <alloca@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <memcpy@plt>
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
xor    %eax,%eax
call   1060 <vfork@plt>
test   %rax,%rax
je     118b <dispatch_shell+0x3b>
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe6e(%rip),%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1070 <execl@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/bin/bash\00"
define i8* @dispatch_shell(i16 zeroext %0, i8* %1, i32 %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i16
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i64
store i16 %0, i16* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32* %3, i32** %9
%12 = load i32, i32* %8
%13 = add i32 %12, 1
%14 = call i8* @alloca(i32 %13)
store i8* %14, i8** %10
%15 = load i8*, i8** %10
%16 = load i8*, i8** %7
%17 = load i32, i32* %8
%18 = call i32 @memcpy(i8* %15, i8* %16, i32 %17)
%19 = load i8*, i8** %10
%20 = load i32, i32* %8
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8 0, i8* %22
%23 = call i64 (...) @vfork()
store i64 %23, i64* %11
%24 = load i64, i64* %11
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %4
%27 = load i8*, i8** %10
%28 = call i32 @execl(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %27, i32* null)
%29 = call i32 @_exit(i32 0)
unreachable
30: ; preds = %4
%31 = load i8*, i8** %5
ret i8* %31
}

LLVM IR (-O2):
@.str = [10 x i8] c"/bin/bash\00"
define noalias i8* @dispatch_shell(i16 zeroext %0, i8* %1, i32 %2, i32* nocapture readnone %3) {
%5 = add i32 %2, 1
%6 = tail call i8* @alloca(i32 %5)
%7 = tail call i32 @memcpy(i8* %6, i8* %1, i32 %2)
%8 = zext i32 %2 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
store i8 0, i8* %9
%10 = tail call i64 (...) @vfork()
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %4
%13 = tail call i32 @execl(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %6, i32* null)
%14 = tail call i32 @_exit(i32 0)
unreachable
15: ; preds = %4
ret i8* undef
}