#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*/ O_RDONLY;
int /*<<< orphan*/ R_OK;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int /*<<< orphan*/ _exit(int);
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ execlp(char *, char *, char *, char *, int /*<<< orphan*/ *);
scalar_t__ mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char *);
int vfork();
int exec_cmd(char *cmd, int *fd) {
  int pid;
  char buf[512 + 1];
  if (access("/var/log/lighttpd/sysinfo_fifo", R_OK) == -1)
    if (mkfifo("/var/log/lighttpd/sysinfo_fifo",
               S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) != 0)
      return -2;
  if ((pid = vfork()) == 0) {
    sprintf(buf, "%s > %s 2> %s", cmd, "/var/log/lighttpd/sysinfo_fifo",
            "/var/log/lighttpd/sysinfo_fifo");
    execlp("hush", "hush", "-c", buf, NULL);
    _exit(-1);
  }
  if ((*fd = open("/var/log/lighttpd/sysinfo_fifo", O_RDONLY)) < 0)
    return -3;
  return pid;
}


x86 assembly (clang, -O0):
<exec_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
lea    0xe6d(%rip),%rdi
call   1060 <access@plt>
cmp    $0xffffffff,%eax
jne    11fe <exec_cmd+0x8e>
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
mov    0x2e27(%rip),%rax
or     (%rax),%esi
mov    0x2e0e(%rip),%rax
or     (%rax),%esi
mov    0x2e1d(%rip),%rax
or     (%rax),%esi
mov    0x2df4(%rip),%rax
or     (%rax),%esi
mov    0x2dcb(%rip),%rax
or     (%rax),%esi
lea    0xe22(%rip),%rdi
call   1040 <mkfifo@plt>
cmp    $0x0,%rax
je     11f9 <exec_cmd+0x89>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1292 <exec_cmd+0x122>
jmp    11fe <exec_cmd+0x8e>
call   1070 <vfork@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    125c <exec_cmd+0xec>
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xdfe(%rip),%rsi
lea    0xdd8(%rip),%r8
mov    %r8,%rcx
call   1080 <sprintf@plt>
lea    -0x220(%rbp),%rcx
lea    0xdef(%rip),%rsi
lea    0xded(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rsi,%rdi
call   1090 <execlp@plt>
mov    $0xffffffff,%edi
call   1030 <_exit@plt>
mov    0x2d85(%rip),%rax
mov    (%rax),%esi
lea    0xd94(%rip),%rdi
call   1050 <open@plt>
mov    -0x18(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0x0,%eax
jge    128c <exec_cmd+0x11c>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1292 <exec_cmd+0x122>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exec_cmd>:
push   %rbp
push   %r14
push   %rbx
sub    $0x210,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
lea    0xe6f(%rip),%rdi
call   1060 <access@plt>
cmp    $0xffffffff,%eax
je     11cd <exec_cmd+0x5d>
call   1070 <vfork@plt>
test   %eax,%eax
je     1229 <exec_cmd+0xb9>
mov    %eax,%ebp
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
lea    0xe46(%rip),%rdi
call   1050 <open@plt>
mov    %eax,(%rbx)
test   %eax,%eax
mov    $0xfffffffd,%eax
cmovs  %eax,%ebp
jmp    121b <exec_cmd+0xab>
mov    0x2de4(%rip),%rax
mov    0x2dfd(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2de2(%rip),%rax
or     (%rax),%ecx
mov    0x2df1(%rip),%rax
or     (%rax),%ecx
mov    0x2dc8(%rip),%rax
or     (%rax),%ecx
mov    0x2d9f(%rip),%rax
mov    %ecx,%esi
or     (%rax),%esi
lea    0xdf4(%rip),%rdi
call   1040 <mkfifo@plt>
mov    $0xfffffffe,%ebp
test   %rax,%rax
je     119b <exec_cmd+0x2b>
mov    %ebp,%eax
add    $0x210,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdef(%rip),%rsi
lea    0xdc9(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %rcx,%r8
call   1080 <sprintf@plt>
lea    0xdde(%rip),%rdi
lea    0xddc(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rdi,%rsi
mov    %rbx,%rcx
call   1090 <execlp@plt>
mov    $0xffffffff,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"/var/log/lighttpd/sysinfo_fifo\00"
@R_OK = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@.str.1 = [14 x i8] c"%s > %s 2> %s\00"
@.str.2 = [5 x i8] c"hush\00"
@.str.3 = [3 x i8] c"-c\00"
@O_RDONLY = global i32 0
define i32 @exec_cmd(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca [513 x i8]
store i8* %0, i8** %4
store i32* %1, i32** %5
%8 = load i32, i32* @R_OK
%9 = call i32 @access(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %27
11: ; preds = %2
%12 = load i32, i32* @S_IRUSR
%13 = load i32, i32* @S_IWUSR
%14 = or i32 %12, %13
%15 = load i32, i32* @S_IRGRP
%16 = or i32 %14, %15
%17 = load i32, i32* @S_IWGRP
%18 = or i32 %16, %17
%19 = load i32, i32* @S_IROTH
%20 = or i32 %18, %19
%21 = load i32, i32* @S_IWOTH
%22 = or i32 %20, %21
%23 = call i64 @mkfifo(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %11
store i32 -2, i32* %3
br label %45
26: ; preds = %11
br label %27
27: ; preds = %26, %2
%28 = call i32 @vfork()
store i32 %28, i32* %6
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %27
%31 = getelementptr inbounds [513 x i8], [513 x i8]* %7, i64 0, i64 0
%32 = load i8*, i8** %4
%33 = call i32 @sprintf(i8* %31, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %32, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%34 = getelementptr inbounds [513 x i8], [513 x i8]* %7, i64 0, i64 0
%35 = call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %34, i32* null)
%36 = call i32 @_exit(i32 -1)
unreachable
37: ; preds = %27
%38 = load i32, i32* @O_RDONLY
%39 = call i32 @open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %38)
%40 = load i32*, i32** %5
store i32 %39, i32* %40
%41 = icmp slt i32 %39, 0
br i1 %41, label %42, label %43
42: ; preds = %37
store i32 -3, i32* %3
br label %45
43: ; preds = %37
%44 = load i32, i32* %6
store i32 %44, i32* %3
br label %45
45: ; preds = %43, %42, %25
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@.str = [31 x i8] c"/var/log/lighttpd/sysinfo_fifo\00"
@R_OK = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@.str.1 = [14 x i8] c"%s > %s 2> %s\00"
@.str.2 = [5 x i8] c"hush\00"
@.str.3 = [3 x i8] c"-c\00"
@O_RDONLY = global i32 0
define i32 @exec_cmd(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca [513 x i8]
%4 = getelementptr inbounds [513 x i8], [513 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @R_OK
%6 = call i32 @access(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %22
8: ; preds = %2
%9 = load i32, i32* @S_IRUSR
%10 = load i32, i32* @S_IWUSR
%11 = or i32 %10, %9
%12 = load i32, i32* @S_IRGRP
%13 = or i32 %11, %12
%14 = load i32, i32* @S_IWGRP
%15 = or i32 %13, %14
%16 = load i32, i32* @S_IROTH
%17 = or i32 %15, %16
%18 = load i32, i32* @S_IWOTH
%19 = or i32 %17, %18
%20 = call i64 @mkfifo(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %34
22: ; preds = %8, %2
%23 = call i32 @vfork()
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4, i32* null)
%28 = call i32 @_exit(i32 -1)
unreachable
29: ; preds = %22
%30 = load i32, i32* @O_RDONLY
%31 = call i32 @open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %30)
store i32 %31, i32* %1
%32 = icmp slt i32 %31, 0
%33 = select i1 %32, i32 -3, i32 %23
br label %34
34: ; preds = %29, %8
%35 = phi i32 [ -2, %8 ], [ %33, %29 ]
ret i32 %35
}