#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 */
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
int getpid();
char **malloc(int);
int /*<<< orphan*/ print_usage_info_and_exit(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ redirect(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
char *strdup(char *);
int main(int argc, char **argv) {
  pid_t pid = getpid();
  printf("%d\n", pid);
  fflush(NULL);
  if (argc <= 1) {
    print_usage_info_and_exit(argv[0], EXIT_SUCCESS);
  }
  int aargc = 0;
  char **aargv;
  aargv = malloc(sizeof(char *) * (argc + 1));
  if (NULL == aargv) {
    exit(901);
  }
  int i = 1;
  int testargs = 1;
  while (i < argc) {
    if (testargs && (0 == strcmp("-out", argv[i]))) {
      redirect(fileno(stdout), argv[i + 1]);
      i += 2;
    } else if (testargs && (0 == strcmp("-err", argv[i]))) {
      redirect(fileno(stderr), argv[i + 1]);
      i += 2;
    } else if (testargs && (0 == strcmp("--", argv[i]))) {
      testargs = 0;
      i += 1;
    } else {
      aargv[aargc] = strdup(argv[i]);
      aargc += 1;
      i += 1;
    }
  }
  if (aargc == 0) {
    print_usage_info_and_exit(argv[0], EXIT_SUCCESS);
  }
  aargv[aargc] = (char *)NULL;
  execvp(aargv[0], aargv);
  exit(902);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe26(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <fflush@plt>
cmpl   $0x1,-0x8(%rbp)
jg     1207 <main+0x57>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2dd0(%rip),%rax
mov    (%rax),%esi
call   1070 <print_usage_info_and_exit@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    123b <main+0x8b>
mov    $0x385,%edi
call   10c0 <exit@plt>
movl   $0x1,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    13a3 <main+0x1f3>
cmpl   $0x0,-0x28(%rbp)
je     12b9 <main+0x109>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd92(%rip),%rdi
call   1060 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12b9 <main+0x109>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
call   1080 <fileno@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <redirect@plt>
mov    -0x24(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x24(%rbp)
jmp    139e <main+0x1ee>
cmpl   $0x0,-0x28(%rbp)
je     131d <main+0x16d>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd33(%rip),%rdi
call   1060 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    131d <main+0x16d>
mov    0x2cf0(%rip),%rax
mov    (%rax),%edi
call   1080 <fileno@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <redirect@plt>
mov    -0x24(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x24(%rbp)
jmp    1399 <main+0x1e9>
cmpl   $0x0,-0x28(%rbp)
je     1362 <main+0x1b2>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xcd4(%rip),%rdi
call   1060 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1362 <main+0x1b2>
movl   $0x0,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1394 <main+0x1e4>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   10d0 <strdup@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1399 <main+0x1e9>
jmp    139e <main+0x1ee>
jmp    1249 <main+0x99>
cmpl   $0x0,-0x18(%rbp)
jne    13c2 <main+0x212>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2c15(%rip),%rax
mov    (%rax),%esi
call   1070 <print_usage_info_and_exit@plt>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
call   10b0 <execvp@plt>
mov    $0x386,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%r14d
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe31(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <fflush@plt>
cmp    $0x1,%r14d
jg     11f4 <main+0x44>
mov    (%rbx),%rdi
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
call   1070 <print_usage_info_and_exit@plt>
lea    0x8(,%r14,8),%edi
call   1090 <malloc@plt>
test   %rax,%rax
jne    1210 <main+0x60>
mov    $0x385,%edi
call   10c0 <exit@plt>
mov    %rax,%r15
cmp    $0x2,%r14d
jl     12d3 <main+0x123>
xor    %ebp,%ebp
mov    $0x1,%r12d
mov    $0x1,%r13d
jmp    125d <main+0xad>
nopl   (%rax)
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
call   1080 <fileno@plt>
mov    0x8(%rbx,%r13,8),%rsi
mov    %eax,%edi
call   1030 <redirect@plt>
mov    $0x1,%r12d
mov    $0x2,%eax
add    %eax,%r13d
cmp    %r14d,%r13d
jge    12cf <main+0x11f>
mov    %r13d,%r13d
test   %r12d,%r12d
je     12a4 <main+0xf4>
mov    (%rbx,%r13,8),%rsi
lea    0xd94(%rip),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1230 <main+0x80>
mov    (%rbx,%r13,8),%rsi
lea    0xd84(%rip),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     12be <main+0x10e>
mov    (%rbx,%r13,8),%rsi
lea    0xd74(%rip),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     12ca <main+0x11a>
mov    (%rbx,%r13,8),%rdi
call   10d0 <strdup@plt>
movslq %ebp,%rbp
mov    %rax,(%r15,%rbp,8)
add    $0x1,%ebp
mov    $0x1,%eax
jmp    1255 <main+0xa5>
mov    0x2d1b(%rip),%rax
jmp    1237 <main+0x87>
xor    %r12d,%r12d
jmp    12b7 <main+0x107>
test   %ebp,%ebp
jne    12e6 <main+0x136>
mov    (%rbx),%rdi
mov    0x2cf3(%rip),%rax
mov    (%rax),%esi
call   1070 <print_usage_info_and_exit@plt>
xor    %ebp,%ebp
movslq %ebp,%rax
movq   $0x0,(%r15,%rax,8)
mov    (%r15),%rdi
mov    %r15,%rsi
call   10b0 <execvp@plt>
mov    $0x386,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [5 x i8] c"-out\00"
@stdout = global i32 0
@.str.2 = [5 x i8] c"-err\00"
@stderr = global i32 0
@.str.3 = [3 x i8] c"--\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 (...) @getpid()
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = call i32 @fflush(i32* null)
%15 = load i32, i32* %4
%16 = icmp sle i32 %15, 1
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = load i32, i32* @EXIT_SUCCESS
%22 = call i32 @print_usage_info_and_exit(i8* %20, i32 %21)
br label %23
23: ; preds = %17, %2
store i32 0, i32* %7
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = mul i64 8, %26
%28 = trunc i64 %27 to i32
%29 = call i8** @malloc(i32 %28)
store i8** %29, i8*** %8
%30 = load i8**, i8*** %8
%31 = icmp eq i8** null, %30
br i1 %31, label %32, label %34
32: ; preds = %23
%33 = call i32 @exit(i32 901)
unreachable
34: ; preds = %23
store i32 1, i32* %9
store i32 1, i32* %10
br label %35
35: ; preds = %116, %34
%36 = load i32, i32* %9
%37 = load i32, i32* %4
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %117
39: ; preds = %35
%40 = load i32, i32* %10
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %62
42: ; preds = %39
%43 = load i8**, i8*** %5
%44 = load i32, i32* %9
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %43, i64 %45
%47 = load i8*, i8** %46
%48 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %47)
%49 = icmp eq i64 0, %48
br i1 %49, label %50, label %62
50: ; preds = %42
%51 = load i32, i32* @stdout
%52 = call i32 @fileno(i32 %51)
%53 = load i8**, i8*** %5
%54 = load i32, i32* %9
%55 = add nsw i32 %54, 1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8*, i8** %53, i64 %56
%58 = load i8*, i8** %57
%59 = call i32 @redirect(i32 %52, i8* %58)
%60 = load i32, i32* %9
%61 = add nsw i32 %60, 2
store i32 %61, i32* %9
br label %116
62: ; preds = %42, %39
%63 = load i32, i32* %10
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %85
65: ; preds = %62
%66 = load i8**, i8*** %5
%67 = load i32, i32* %9
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8*, i8** %66, i64 %68
%70 = load i8*, i8** %69
%71 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %70)
%72 = icmp eq i64 0, %71
br i1 %72, label %73, label %85
73: ; preds = %65
%74 = load i32, i32* @stderr
%75 = call i32 @fileno(i32 %74)
%76 = load i8**, i8*** %5
%77 = load i32, i32* %9
%78 = add nsw i32 %77, 1
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8*, i8** %76, i64 %79
%81 = load i8*, i8** %80
%82 = call i32 @redirect(i32 %75, i8* %81)
%83 = load i32, i32* %9
%84 = add nsw i32 %83, 2
store i32 %84, i32* %9
br label %115
85: ; preds = %65, %62
%86 = load i32, i32* %10
%87 = icmp ne i32 %86, 0
br i1 %87, label %88, label %99
88: ; preds = %85
%89 = load i8**, i8*** %5
%90 = load i32, i32* %9
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds i8*, i8** %89, i64 %91
%93 = load i8*, i8** %92
%94 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %93)
%95 = icmp eq i64 0, %94
br i1 %95, label %96, label %99
96: ; preds = %88
store i32 0, i32* %10
%97 = load i32, i32* %9
%98 = add nsw i32 %97, 1
store i32 %98, i32* %9
br label %114
99: ; preds = %88, %85
%100 = load i8**, i8*** %5
%101 = load i32, i32* %9
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds i8*, i8** %100, i64 %102
%104 = load i8*, i8** %103
%105 = call i8* @strdup(i8* %104)
%106 = load i8**, i8*** %8
%107 = load i32, i32* %7
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds i8*, i8** %106, i64 %108
store i8* %105, i8** %109
%110 = load i32, i32* %7
%111 = add nsw i32 %110, 1
store i32 %111, i32* %7
%112 = load i32, i32* %9
%113 = add nsw i32 %112, 1
store i32 %113, i32* %9
br label %114
114: ; preds = %99, %96
br label %115
115: ; preds = %114, %73
br label %116
116: ; preds = %115, %50
br label %35
117: ; preds = %35
%118 = load i32, i32* %7
%119 = icmp eq i32 %118, 0
br i1 %119, label %120, label %126
120: ; preds = %117
%121 = load i8**, i8*** %5
%122 = getelementptr inbounds i8*, i8** %121, i64 0
%123 = load i8*, i8** %122
%124 = load i32, i32* @EXIT_SUCCESS
%125 = call i32 @print_usage_info_and_exit(i8* %123, i32 %124)
br label %126
126: ; preds = %120, %117
%127 = load i8**, i8*** %8
%128 = load i32, i32* %7
%129 = sext i32 %128 to i64
%130 = getelementptr inbounds i8*, i8** %127, i64 %129
store i8* null, i8** %130
%131 = load i8**, i8*** %8
%132 = getelementptr inbounds i8*, i8** %131, i64 0
%133 = load i8*, i8** %132
%134 = load i8**, i8*** %8
%135 = call i32 @execvp(i8* %133, i8** %134)
%136 = call i32 @exit(i32 902)
unreachable
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [5 x i8] c"-out\00"
@stdout = global i32 0
@.str.2 = [5 x i8] c"-err\00"
@stderr = global i32 0
@.str.3 = [3 x i8] c"--\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (...) @getpid()
%4 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32 @fflush(i32* null)
%6 = icmp slt i32 %0, 2
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = load i32, i32* @EXIT_SUCCESS
%10 = tail call i32 @print_usage_info_and_exit(i8* %8, i32 %9)
br label %11
11: ; preds = %7, %2
%12 = shl i32 %0, 3
%13 = add i32 %12, 8
%14 = tail call i8** @malloc(i32 %13)
%15 = icmp eq i8** %14, null
br i1 %15, label %18, label %16
16: ; preds = %11
%17 = icmp sgt i32 %0, 1
br i1 %17, label %20, label %70
18: ; preds = %11
%19 = tail call i32 @exit(i32 901)
unreachable
20: ; preds = %16, %62
%21 = phi i32 [ %65, %62 ], [ 1, %16 ]
%22 = phi i32 [ %66, %62 ], [ 1, %16 ]
%23 = phi i32 [ %64, %62 ], [ 0, %16 ]
%24 = icmp eq i32 %21, 0
%25 = zext i32 %22 to i64
br i1 %24, label %55, label %26
26: ; preds = %20
%27 = getelementptr inbounds i8*, i8** %1, i64 %25
%28 = load i8*, i8** %27
%29 = tail call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %39
31: ; preds = %26
%32 = load i32, i32* @stdout
%33 = tail call i32 @fileno(i32 %32)
%34 = add nuw nsw i32 %22, 1
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %1, i64 %35
%37 = load i8*, i8** %36
%38 = tail call i32 @redirect(i32 %33, i8* %37)
br label %62
39: ; preds = %26
%40 = load i8*, i8** %27
%41 = tail call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %40)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %51
43: ; preds = %39
%44 = load i32, i32* @stderr
%45 = tail call i32 @fileno(i32 %44)
%46 = add nuw nsw i32 %22, 1
%47 = zext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %1, i64 %47
%49 = load i8*, i8** %48
%50 = tail call i32 @redirect(i32 %45, i8* %49)
br label %62
51: ; preds = %39
%52 = load i8*, i8** %27
%53 = tail call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %52)
%54 = icmp eq i64 %53, 0
br i1 %54, label %62, label %55
55: ; preds = %20, %51
%56 = getelementptr inbounds i8*, i8** %1, i64 %25
%57 = load i8*, i8** %56
%58 = tail call i8* @strdup(i8* %57)
%59 = sext i32 %23 to i64
%60 = getelementptr inbounds i8*, i8** %14, i64 %59
store i8* %58, i8** %60
%61 = add nsw i32 %23, 1
br label %62
62: ; preds = %51, %43, %55, %31
%63 = phi i32 [ 2, %43 ], [ 1, %55 ], [ 2, %31 ], [ 1, %51 ]
%64 = phi i32 [ %23, %43 ], [ %61, %55 ], [ %23, %31 ], [ %23, %51 ]
%65 = phi i32 [ 1, %43 ], [ %21, %55 ], [ 1, %31 ], [ 0, %51 ]
%66 = add nuw nsw i32 %22, %63
%67 = icmp slt i32 %66, %0
br i1 %67, label %20, label %68
68: ; preds = %62
%69 = icmp eq i32 %64, 0
br i1 %69, label %70, label %74
70: ; preds = %16, %68
%71 = load i8*, i8** %1
%72 = load i32, i32* @EXIT_SUCCESS
%73 = tail call i32 @print_usage_info_and_exit(i8* %71, i32 %72)
br label %74
74: ; preds = %70, %68
%75 = phi i32 [ 0, %70 ], [ %64, %68 ]
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8*, i8** %14, i64 %76
store i8* null, i8** %77
%78 = load i8*, i8** %14
%79 = tail call i32 @execvp(i8* %78, i8** %14)
%80 = tail call i32 @exit(i32 902)
unreachable
}