#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*/ LOG_DEBUG;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ execvp(char *, char **);
int fork();
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, ...);
void cmd_execute(char **args) {
  int pid;
  syslog(LOG_DEBUG, "Launcher: fork child.");
  if ((pid = fork()) < 0) {
    syslog(LOG_ERR, "Can't fork: %s", strerror(errno));
    return;
  }
  if (pid == 0) {
    execvp(*args, args);
    syslog(LOG_ERR, "Can't execvp: %s: %s", args[0], strerror(errno));
    _exit(1);
  }
  syslog(LOG_DEBUG, "Launcher: child exec done.");
}


x86 assembly (clang, -O0):
<cmd_execute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
lea    0xe94(%rip),%rsi
mov    $0x0,%al
call   1040 <syslog@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    11b8 <cmd_execute+0x68>
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x10(%rbp),%edi
mov    %eax,%edx
lea    0xe6a(%rip),%rsi
mov    $0x0,%al
call   1040 <syslog@plt>
jmp    122f <cmd_execute+0xdf>
cmpl   $0x0,-0xc(%rbp)
jne    1218 <cmd_execute+0xc8>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <execvp@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rdx
mov    %eax,%ecx
lea    0xe1e(%rip),%rsi
mov    $0x0,%al
call   1040 <syslog@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
lea    0xe12(%rip),%rsi
mov    $0x0,%al
call   1040 <syslog@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_execute>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e7b(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xe99(%rip),%rsi
xor    %eax,%eax
call   1040 <syslog@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
js     1192 <cmd_execute+0x42>
je     11c1 <cmd_execute+0x71>
mov    0x0(%rbp),%edi
lea    0xeb5(%rip),%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <syslog@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%ebx
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe66(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <syslog@plt>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1050 <execvp@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%rbx
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe38(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <syslog@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@LOG_DEBUG = global i32 0
@.str = [22 x i8] c"Launcher: fork child.\00"
@LOG_ERR = global i32 0
@.str.1 = [15 x i8] c"Can't fork: %s\00"
@errno = global i32 0
@.str.2 = [21 x i8] c"Can't execvp: %s: %s\00"
@.str.3 = [27 x i8] c"Launcher: child exec done.\00"
define void @cmd_execute(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
store i8** %0, i8*** %2
%4 = load i32, i32* @LOG_DEBUG
%5 = call i32 (i32, i8*, ...) @syslog(i32 %4, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (...) @fork()
store i32 %6, i32* %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = load i32, i32* @LOG_ERR
%10 = load i32, i32* @errno
%11 = call i32 @strerror(i32 %10)
%12 = call i32 (i32, i8*, ...) @syslog(i32 %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %11)
br label %32
13: ; preds = %1
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %29
16: ; preds = %13
%17 = load i8**, i8*** %2
%18 = load i8*, i8** %17
%19 = load i8**, i8*** %2
%20 = call i32 @execvp(i8* %18, i8** %19)
%21 = load i32, i32* @LOG_ERR
%22 = load i8**, i8*** %2
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = load i32, i32* @errno
%26 = call i32 @strerror(i32 %25)
%27 = call i32 (i32, i8*, ...) @syslog(i32 %21, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %24, i32 %26)
%28 = call i32 @_exit(i32 1)
unreachable
29: ; preds = %13
%30 = load i32, i32* @LOG_DEBUG
%31 = call i32 (i32, i8*, ...) @syslog(i32 %30, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %29, %8
ret void
}

LLVM IR (-O2):
@LOG_DEBUG = global i32 0
@.str = [22 x i8] c"Launcher: fork child.\00"
@LOG_ERR = global i32 0
@.str.1 = [15 x i8] c"Can't fork: %s\00"
@errno = global i32 0
@.str.2 = [21 x i8] c"Can't execvp: %s: %s\00"
@.str.3 = [27 x i8] c"Launcher: child exec done.\00"
define void @cmd_execute(i8** %0) {
%2 = load i32, i32* @LOG_DEBUG
%3 = tail call i32 (i32, i8*, ...) @syslog(i32 %2, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 (...) @fork()
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = load i32, i32* @LOG_ERR
%8 = load i32, i32* @errno
%9 = tail call i32 @strerror(i32 %8)
%10 = tail call i32 (i32, i8*, ...) @syslog(i32 %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %25
11: ; preds = %1
%12 = icmp eq i32 %4, 0
br i1 %12, label %13, label %22
13: ; preds = %11
%14 = load i8*, i8** %0
%15 = tail call i32 @execvp(i8* %14, i8** %0)
%16 = load i32, i32* @LOG_ERR
%17 = load i8*, i8** %0
%18 = load i32, i32* @errno
%19 = tail call i32 @strerror(i32 %18)
%20 = tail call i32 (i32, i8*, ...) @syslog(i32 %16, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %17, i32 %19)
%21 = tail call i32 @_exit(i32 1)
unreachable
22: ; preds = %11
%23 = load i32, i32* @LOG_DEBUG
%24 = tail call i32 (i32, i8*, ...) @syslog(i32 %23, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %22, %6
ret void
}