#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 /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ execl(char *, char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fatal(char *);
scalar_t__ fork();
int /*<<< orphan*/ setsid();
void spawn(char *cmd) {
  if (fork() != 0)
    return;
  setsid();
  execl("/bin/sh", "sh", "-c", cmd, NULL);
  fatal("exec failed");
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<spawn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
je     1173 <spawn+0x23>
add    $0x10,%rsp
pop    %rbp
ret
mov    $0x0,%al
call   1030 <setsid@plt>
mov    -0x8(%rbp),%rcx
lea    0xe7b(%rip),%rdi
lea    0xe79(%rip),%rsi
lea    0xe75(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   1050 <execl@plt>
lea    0xe67(%rip),%rdi
call   1060 <fatal@plt>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

x86 assembly (clang, -O2):
<spawn>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     1162 <spawn+0x12>
pop    %rbx
ret
xor    %eax,%eax
call   1030 <setsid@plt>
lea    0xe90(%rip),%rdi
lea    0xe8e(%rip),%rsi
lea    0xe8a(%rip),%rdx
mov    %rbx,%rcx
xor    %r8d,%r8d
call   1050 <execl@plt>
lea    0xe7b(%rip),%rdi
call   1060 <fatal@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"/bin/sh\00"
@.str.1 = [3 x i8] c"sh\00"
@.str.2 = [3 x i8] c"-c\00"
@.str.3 = [12 x i8] c"exec failed\00"
@EXIT_SUCCESS = global i32 0
define void @spawn(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = call i64 (...) @fork()
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %6
5: ; preds = %1
ret void
6: ; preds = %1
%7 = call i32 (...) @setsid()
%8 = load i8*, i8** %2
%9 = call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %8, i32* null)
%10 = call i32 @fatal(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%11 = load i32, i32* @EXIT_SUCCESS
%12 = call i32 @exit(i32 %11)
unreachable
}

LLVM IR (-O2):
@.str = [8 x i8] c"/bin/sh\00"
@.str.1 = [3 x i8] c"sh\00"
@.str.2 = [3 x i8] c"-c\00"
@.str.3 = [12 x i8] c"exec failed\00"
@EXIT_SUCCESS = global i32 0
define void @spawn(i8* %0) {
%2 = tail call i64 (...) @fork()
%3 = icmp eq i64 %2, 0
br i1 %3, label %5, label %4
4: ; preds = %1
ret void
5: ; preds = %1
%6 = tail call i32 (...) @setsid()
%7 = tail call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32* null)
%8 = tail call i32 @fatal(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%9 = load i32, i32* @EXIT_SUCCESS
%10 = tail call i32 @exit(i32 %9)
unreachable
}