#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*/ execl(char const *, char const *, char *, char const *,
                         char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           char const *);
char *getenv(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ setsid();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wait(int /*<<< orphan*/);
void spawn(const char *arg) {
  static const char *shell = NULL;
  if (!shell && !(shell = getenv("SHELL")))
    shell = "/bin/sh";
  if (!arg)
    return;
  if (fork() == 0) {
    if (fork() == 0) {
      setsid();
      execl(shell, shell, "-c", arg, (char *)NULL);
      fprintf(stderr, "dzen: execl '%s -c %s'", shell, arg);
      perror(" failed");
    }
    exit(0);
  }
  wait(0);
}


x86 assembly (clang, -O0):
<spawn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,0x2ed4(%rip)
jne    11c5 <spawn+0x45>
lea    0xe5f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,0x2ebb(%rip)
cmp    $0x0,%rax
jne    11c5 <spawn+0x45>
lea    0xe48(%rip),%rax
mov    %rax,0x2ea3(%rip)
cmpq   $0x0,-0x8(%rbp)
jne    11d5 <spawn+0x55>
jmp    125b <spawn+0xdb>
mov    $0x0,%al
call   10a0 <fork@plt>
cmp    $0x0,%rax
jne    1254 <spawn+0xd4>
mov    $0x0,%al
call   10a0 <fork@plt>
cmp    $0x0,%rax
jne    124d <spawn+0xcd>
mov    $0x0,%al
call   1040 <setsid@plt>
mov    0x2e63(%rip),%rdi
mov    0x2e5c(%rip),%rsi
mov    -0x8(%rbp),%rcx
lea    0xdf7(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   1080 <execl@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
mov    0x2e37(%rip),%rdx
mov    -0x8(%rbp),%rcx
lea    0xdd5(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xde0(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1070 <exit@plt>
xor    %edi,%edi
call   1090 <wait@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spawn>:
push   %rbx
mov    %rdi,%rbx
cmpq   $0x0,0x2edc(%rip)
je     11a7 <spawn+0x27>
test   %rbx,%rbx
je     11cd <spawn+0x4d>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
je     11cf <spawn+0x4f>
xor    %edi,%edi
pop    %rbx
jmp    1090 <wait@plt>
lea    0xe52(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe49(%rip),%rcx
cmovne %rax,%rcx
mov    %rcx,0x2ea0(%rip)
test   %rbx,%rbx
jne    1193 <spawn+0x13>
pop    %rbx
ret
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
jne    1229 <spawn+0xa9>
xor    %eax,%eax
call   1040 <setsid@plt>
mov    0x2e7f(%rip),%rdi
lea    0xe1e(%rip),%rdx
mov    %rdi,%rsi
mov    %rbx,%rcx
xor    %r8d,%r8d
call   1080 <execl@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
mov    0x2e5a(%rip),%rdx
lea    0xdfc(%rip),%rsi
mov    %rbx,%rcx
call   1050 <fprintf@plt>
lea    0xe04(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@spawn.shell = internal global i8* null
@.str = [6 x i8] c"SHELL\00"
@.str.1 = [8 x i8] c"/bin/sh\00"
@.str.2 = [3 x i8] c"-c\00"
@stderr = global i32 0
@.str.3 = [23 x i8] c"dzen: execl '%s -c %s'\00"
@.str.4 = [8 x i8] c" failed\00"
define void @spawn(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i8*, i8** @spawn.shell
%4 = icmp ne i8* %3, null
br i1 %4, label %9, label %5
5: ; preds = %1
%6 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** @spawn.shell
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %5
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** @spawn.shell
br label %9
9: ; preds = %8, %5, %1
%10 = load i8*, i8** %2
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %9
br label %34
13: ; preds = %9
%14 = call i64 (...) @fork()
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %32
16: ; preds = %13
%17 = call i64 (...) @fork()
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %30
19: ; preds = %16
%20 = call i32 (...) @setsid()
%21 = load i8*, i8** @spawn.shell
%22 = load i8*, i8** @spawn.shell
%23 = load i8*, i8** %2
%24 = call i32 @execl(i8* %21, i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %23, i8* null)
%25 = load i32, i32* @stderr
%26 = load i8*, i8** @spawn.shell
%27 = load i8*, i8** %2
%28 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %26, i8* %27)
%29 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %30
30: ; preds = %19, %16
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %13
%33 = call i32 @wait(i32 0)
br label %34
34: ; preds = %32, %12
ret void
}

LLVM IR (-O2):
@spawn.shell = internal unnamed_addr global i8* null
@.str = [6 x i8] c"SHELL\00"
@.str.1 = [8 x i8] c"/bin/sh\00"
@.str.2 = [3 x i8] c"-c\00"
@stderr = global i32 0
@.str.3 = [23 x i8] c"dzen: execl '%s -c %s'\00"
@.str.4 = [8 x i8] c" failed\00"
define void @spawn(i8* %0) {
%2 = load i8*, i8** @spawn.shell
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
%7 = select i1 %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %5
store i8* %7, i8** @spawn.shell
br label %8
8: ; preds = %4, %1
%9 = icmp eq i8* %0, null
br i1 %9, label %28, label %10
10: ; preds = %8
%11 = tail call i64 (...) @fork()
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %26
13: ; preds = %10
%14 = tail call i64 (...) @fork()
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = tail call i32 (...) @setsid()
%18 = load i8*, i8** @spawn.shell
%19 = tail call i32 @execl(i8* %18, i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* null)
%20 = load i32, i32* @stderr
%21 = load i8*, i8** @spawn.shell
%22 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %21, i8* %0)
%23 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %24
24: ; preds = %16, %13
%25 = tail call i32 @exit(i32 0)
unreachable
26: ; preds = %10
%27 = tail call i32 @wait(i32 0)
br label %28
28: ; preds = %8, %26
ret void
}