#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*/ execvp(char *, char **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int redirect_fd(char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int err;
  if (4 > argc) {
    fprintf(stderr,
            "usage: %s <stdout_cmd> <stderr_cmd> <cmd> <cmd args...>\n"
            "example: %s \"logger -p daemon.info\" \"logger -p daemon.err\" "
            "./some_server --param --param2 param2_value\n",
            argv[0], argv[0]);
    return -1;
  }
  err = redirect_fd(argv[1], 1);
  if (err) {
    return err;
  }
  err = redirect_fd(argv[2], 2);
  if (err) {
    return err;
  }
  execvp(argv[3], &argv[3]);
  return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x4,%eax
cmp    -0x8(%rbp),%eax
jle    1183 <main+0x53>
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xe8e(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f3 <main+0xc3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x1,%esi
call   1040 <redirect_fd@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11ad <main+0x7d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f3 <main+0xc3>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    $0x2,%esi
call   1040 <redirect_fd@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11d7 <main+0xa7>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f3 <main+0xc3>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x18,%rsi
call   1050 <execvp@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x3,%edi
jg     115b <main+0x2b>
mov    0x2ea0(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rcx
lea    0xeb4(%rip),%rsi
mov    %rcx,%rdx
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    117f <main+0x4f>
mov    0x8(%rbx),%rdi
mov    $0x1,%esi
call   1040 <redirect_fd@plt>
test   %eax,%eax
jne    117f <main+0x4f>
mov    0x10(%rbx),%rdi
mov    $0x2,%esi
call   1040 <redirect_fd@plt>
test   %eax,%eax
je     1181 <main+0x51>
pop    %rbx
ret
mov    0x18(%rbx),%rdi
add    $0x18,%rbx
mov    %rbx,%rsi
call   1050 <execvp@plt>
jmp    1154 <main+0x24>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [160 x i8] c"usage: %s <stdout_cmd> <stderr_cmd> <cmd> <cmd args...>\0Aexample: %s \22logger -p daemon.info\22 \22logger -p daemon.err\22 ./some_server --param --param2 param2_value\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp sgt i32 4, %7
br i1 %8, label %9, label %18
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str, i64 0, i64 0), i8* %13, i8* %16)
store i32 -1, i32* %3
br label %43
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @redirect_fd(i8* %21, i32 1)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %18
%26 = load i32, i32* %6
store i32 %26, i32* %3
br label %43
27: ; preds = %18
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @redirect_fd(i8* %30, i32 2)
store i32 %31, i32* %6
%32 = load i32, i32* %6
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %27
%35 = load i32, i32* %6
store i32 %35, i32* %3
br label %43
36: ; preds = %27
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 3
%39 = load i8*, i8** %38
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 3
%42 = call i32 @execvp(i8* %39, i8** %41)
store i32 -1, i32* %3
br label %43
43: ; preds = %36, %34, %25, %9
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [160 x i8] c"usage: %s <stdout_cmd> <stderr_cmd> <cmd> <cmd args...>\0Aexample: %s \22logger -p daemon.info\22 \22logger -p daemon.err\22 ./some_server --param --param2 param2_value\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 4
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str, i64 0, i64 0), i8* %6, i8* %6)
br label %22
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @redirect_fd(i8* %10, i32 1)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %22
13: ; preds = %8
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @redirect_fd(i8* %15, i32 2)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = getelementptr inbounds i8*, i8** %1, i64 3
%20 = load i8*, i8** %19
%21 = tail call i32 @execvp(i8* %20, i8** %19)
br label %22
22: ; preds = %13, %8, %18, %4
%23 = phi i32 [ -1, %4 ], [ -1, %18 ], [ %11, %8 ], [ %16, %13 ]
ret i32 %23
}