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

/* Variables and functions */
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, scalar_t__, ...);
char *mygetenv(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, scalar_t__);
int /*<<< orphan*/ redirect_stdouterr(char const *);
int setenv(char *, char *, int);
int /*<<< orphan*/ *stderr;
scalar_t__ strcmp(char *, char *);
int usage(char *);
int main(int argc, char *argv[]) {
  pid_t child;
  int rc;
  int arg_offs = 1;
  const char *outfile = NULL;
  const char *pidfile = NULL;
  if (argc < 2) {
    return usage(argv[0]);
  }
  while (argv[arg_offs][0] == '-') {
    if (strcmp(argv[arg_offs], "-env") == 0) {
      if (argc <= arg_offs + 2)
        return usage(argv[0]);
      rc = setenv(argv[arg_offs + 1], argv[arg_offs + 2], 1);
      if (rc != 0 ||
          strcmp(mygetenv(argv[arg_offs + 1]), argv[arg_offs + 2]) != 0) {
        fprintf(stderr, "error in setenv of \"%s\" to \"%s\"\n",
                argv[arg_offs + 1], argv[arg_offs + 2]);
        fprintf(stderr, "setenv returned %d\n", rc);
        fprintf(stderr, "env var \"%s\" is now \"%s\"\n", argv[arg_offs + 1],
                mygetenv(argv[arg_offs + 1]));
        exit(1);
      }
      arg_offs += 3;
    } else if (strcmp(argv[arg_offs], "-out") == 0) {
      if (argc <= arg_offs + 1)
        return usage(argv[0]);
      outfile = argv[arg_offs + 1];
      arg_offs += 2;
    } else if (strcmp(argv[arg_offs], "-pid") == 0) {
      if (argc <= arg_offs + 1)
        return usage(argv[0]);
      pidfile = argv[arg_offs + 1];
      arg_offs += 2;
    } else {
      return usage(argv[0]);
    }
    if (argc - arg_offs < 1)
      return usage(argv[0]);
  }
  child = fork();
  if (child < 0) {
    perror("ERROR on fork");
  } else if (child == 0) {
    redirect_stdouterr(outfile);
    execv(argv[arg_offs], argv + arg_offs);
    fprintf(stderr, "execv of %s FAILED", argv[arg_offs]);
    exit(1);
  }
  if (pidfile == NULL)
    printf("%d\n", child);
  if (pidfile != NULL) {
    FILE *f = fopen(pidfile, "w");
    if (f == NULL) {
      perror("open pidfile failed");
      exit(1);
    }
    fprintf(f, "%d\n", child);
    fclose(f);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    121b <main+0x4b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <usage@plt>
mov    %eax,-0x4(%rbp)
jmp    15da <main+0x40a>
jmp    1220 <main+0x50>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    14cb <main+0x2fb>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdb5(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    13b1 <main+0x1e1>
mov    -0x8(%rbp),%eax
mov    -0x20(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jg     127f <main+0xaf>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <usage@plt>
mov    %eax,-0x4(%rbp)
jmp    15da <main+0x40a>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    12f1 <main+0x121>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   10d0 <mygetenv@plt>
mov    %rax,%rdi
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     13a3 <main+0x1d3>
mov    0x2ce8(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xce1(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2cae(%rip),%rax
mov    (%rax),%rdi
movslq -0x1c(%rbp),%rdx
lea    0xce6(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2c92(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   10d0 <mygetenv@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    %rax,%rcx
lea    0xca8(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x20(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x20(%rbp)
jmp    14a3 <main+0x2d3>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xc90(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    141b <main+0x24b>
mov    -0x8(%rbp),%eax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jg     13f8 <main+0x228>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <usage@plt>
mov    %eax,-0x4(%rbp)
jmp    15da <main+0x40a>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
jmp    149e <main+0x2ce>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xc2b(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1485 <main+0x2b5>
mov    -0x8(%rbp),%eax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jg     1462 <main+0x292>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <usage@plt>
mov    %eax,-0x4(%rbp)
jmp    15da <main+0x40a>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
jmp    1499 <main+0x2c9>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <usage@plt>
mov    %eax,-0x4(%rbp)
jmp    15da <main+0x40a>
jmp    149e <main+0x2ce>
jmp    14a3 <main+0x2d3>
mov    -0x8(%rbp),%eax
sub    -0x20(%rbp),%eax
cmp    $0x1,%eax
jge    14c6 <main+0x2f6>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <usage@plt>
mov    %eax,-0x4(%rbp)
jmp    15da <main+0x40a>
jmp    1220 <main+0x50>
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    14f2 <main+0x322>
lea    0xb76(%rip),%rdi
call   10b0 <perror@plt>
jmp    1559 <main+0x389>
cmpq   $0x0,-0x18(%rbp)
jne    1554 <main+0x384>
mov    -0x28(%rbp),%rdi
call   1030 <redirect_stdouterr@plt>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
call   10e0 <execv@plt>
mov    0x2ab3(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xb29(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    1559 <main+0x389>
cmpq   $0x0,-0x30(%rbp)
jne    1574 <main+0x3a4>
mov    -0x18(%rbp),%rsi
lea    0xac7(%rip),%rdi
call   1060 <printf@plt>
cmpq   $0x0,-0x30(%rbp)
je     15d3 <main+0x403>
mov    -0x30(%rbp),%rdi
lea    0xaf5(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    15b4 <main+0x3e4>
lea    0xadc(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xa73(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jge    11fc <main+0x2c>
mov    (%rbx),%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <usage@plt>
mov    %edi,%r13d
mov    $0x1,%r15d
xor    %eax,%eax
mov    %rax,0x8(%rsp)
xor    %eax,%eax
mov    %rax,0x10(%rsp)
jmp    122d <main+0x5d>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x2,%ecx
add    %ecx,%r15d
cmp    %r13d,%r15d
jge    11e6 <main+0x16>
mov    %r15d,%r12d
lea    (%rbx,%r12,8),%r14
mov    (%rbx,%r12,8),%rdi
cmpb   $0x2d,(%rdi)
jne    131d <main+0x14d>
lea    0xdb8(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12a0 <main+0xd0>
mov    (%r14),%rdi
lea    0xdf8(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1300 <main+0x130>
mov    (%r14),%rdi
lea    0xde5(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    11e6 <main+0x16>
lea    0x1(%r15),%eax
cmp    %r13d,%eax
jge    11e6 <main+0x16>
mov    %eax,%eax
mov    (%rbx,%rax,8),%rax
mov    %rax,0x10(%rsp)
jmp    1220 <main+0x50>
nopl   0x0(%rax)
lea    0x2(%r15),%eax
cmp    %r13d,%eax
jge    11e6 <main+0x16>
mov    0x8(%rbx,%r12,8),%rdi
add    $0x1,%r12
mov    %eax,%ebp
mov    (%rbx,%rbp,8),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
mov    %eax,%r14d
test   %eax,%eax
jne    13a0 <main+0x1d0>
mov    (%rbx,%r12,8),%rdi
call   10d0 <mygetenv@plt>
mov    (%rbx,%rbp,8),%rsi
mov    %rax,%rdi
call   1070 <strcmp@plt>
mov    $0x3,%ecx
test   %rax,%rax
je     1225 <main+0x55>
jmp    13a0 <main+0x1d0>
nopl   0x0(%rax)
lea    0x1(%r15),%eax
cmp    %r13d,%eax
jge    11e6 <main+0x16>
mov    %eax,%eax
mov    (%rbx,%rax,8),%rax
mov    %rax,0x8(%rsp)
jmp    1220 <main+0x50>
xor    %eax,%eax
call   10f0 <fork@plt>
mov    %rax,%rbx
test   %rax,%rax
js     1392 <main+0x1c2>
je     1404 <main+0x234>
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
je     1372 <main+0x1a2>
lea    0xd3c(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     143e <main+0x26e>
mov    %rax,%rbp
lea    0xcdb(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
jmp    1381 <main+0x1b1>
lea    0xcbd(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcc5(%rip),%rdi
call   10b0 <perror@plt>
jmp    1332 <main+0x162>
mov    0x2c39(%rip),%r15
mov    (%r15),%rdi
mov    (%rbx,%r12,8),%rdx
mov    (%rbx,%rbp,8),%rcx
lea    0xc4c(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%r15),%rdi
movslq %r14d,%rdx
lea    0xc59(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%r15),%rbp
mov    (%rbx,%r12,8),%rbx
mov    %rbx,%rdi
call   10d0 <mygetenv@plt>
lea    0xc50(%rip),%rsi
mov    %rbp,%rdi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x8(%rsp),%rdi
call   1030 <redirect_stdouterr@plt>
mov    (%r14),%rdi
mov    %r14,%rsi
call   10e0 <execv@plt>
mov    0x2bc0(%rip),%rax
mov    (%rax),%rdi
mov    (%r14),%rdx
lea    0xc3f(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    0xc3c(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"-env\00"
@stderr = global i32* null
@.str.1 = [33 x i8] c"error in setenv of \22%s\22 to \22%s\22\0A\00"
@.str.2 = [20 x i8] c"setenv returned %d\0A\00"
@.str.3 = [26 x i8] c"env var \22%s\22 is now \22%s\22\0A\00"
@.str.4 = [5 x i8] c"-out\00"
@.str.5 = [5 x i8] c"-pid\00"
@.str.6 = [14 x i8] c"ERROR on fork\00"
@.str.7 = [19 x i8] c"execv of %s FAILED\00"
@.str.8 = [4 x i8] c"%d\0A\00"
@.str.9 = [2 x i8] c"w\00"
@.str.10 = [20 x i8] c"open pidfile failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %8
store i8* null, i8** %9
store i8* null, i8** %10
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @usage(i8* %17)
store i32 %18, i32* %3
br label %248
19: ; preds = %2
br label %20
20: ; preds = %191, %19
%21 = load i8**, i8*** %5
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
%25 = load i8*, i8** %24
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 45
br i1 %29, label %30, label %192
30: ; preds = %20
%31 = load i8**, i8*** %5
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %120
38: ; preds = %30
%39 = load i32, i32* %4
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 2
%42 = icmp sle i32 %39, %41
br i1 %42, label %43, label %48
43: ; preds = %38
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 0
%46 = load i8*, i8** %45
%47 = call i32 @usage(i8* %46)
store i32 %47, i32* %3
br label %248
48: ; preds = %38
%49 = load i8**, i8*** %5
%50 = load i32, i32* %8
%51 = add nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %49, i64 %52
%54 = load i8*, i8** %53
%55 = load i8**, i8*** %5
%56 = load i32, i32* %8
%57 = add nsw i32 %56, 2
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8*, i8** %55, i64 %58
%60 = load i8*, i8** %59
%61 = call i32 @setenv(i8* %54, i8* %60, i32 1)
store i32 %61, i32* %7
%62 = load i32, i32* %7
%63 = icmp ne i32 %62, 0
br i1 %63, label %80, label %64
64: ; preds = %48
%65 = load i8**, i8*** %5
%66 = load i32, i32* %8
%67 = add nsw i32 %66, 1
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8*, i8** %65, i64 %68
%70 = load i8*, i8** %69
%71 = call i8* @mygetenv(i8* %70)
%72 = load i8**, i8*** %5
%73 = load i32, i32* %8
%74 = add nsw i32 %73, 2
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8*, i8** %72, i64 %75
%77 = load i8*, i8** %76
%78 = call i64 @strcmp(i8* %71, i8* %77)
%79 = icmp ne i64 %78, 0
br i1 %79, label %80, label %117
80: ; preds = %64, %48
%81 = load i32*, i32** @stderr
%82 = load i8**, i8*** %5
%83 = load i32, i32* %8
%84 = add nsw i32 %83, 1
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8*, i8** %82, i64 %85
%87 = load i8*, i8** %86
%88 = ptrtoint i8* %87 to i64
%89 = load i8**, i8*** %5
%90 = load i32, i32* %8
%91 = add nsw i32 %90, 2
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i8*, i8** %89, i64 %92
%94 = load i8*, i8** %93
%95 = call i32 (i32*, i8*, i64, ...) @fprintf(i32* %81, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i64 %88, i8* %94)
%96 = load i32*, i32** @stderr
%97 = load i32, i32* %7
%98 = sext i32 %97 to i64
%99 = call i32 (i32*, i8*, i64, ...) @fprintf(i32* %96, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 %98)
%100 = load i32*, i32** @stderr
%101 = load i8**, i8*** %5
%102 = load i32, i32* %8
%103 = add nsw i32 %102, 1
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds i8*, i8** %101, i64 %104
%106 = load i8*, i8** %105
%107 = ptrtoint i8* %106 to i64
%108 = load i8**, i8*** %5
%109 = load i32, i32* %8
%110 = add nsw i32 %109, 1
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds i8*, i8** %108, i64 %111
%113 = load i8*, i8** %112
%114 = call i8* @mygetenv(i8* %113)
%115 = call i32 (i32*, i8*, i64, ...) @fprintf(i32* %100, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i64 %107, i8* %114)
%116 = call i32 @exit(i32 1)
unreachable
117: ; preds = %64
%118 = load i32, i32* %8
%119 = add nsw i32 %118, 3
store i32 %119, i32* %8
br label %181
120: ; preds = %30
%121 = load i8**, i8*** %5
%122 = load i32, i32* %8
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds i8*, i8** %121, i64 %123
%125 = load i8*, i8** %124
%126 = call i64 @strcmp(i8* %125, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%127 = icmp eq i64 %126, 0
br i1 %127, label %128, label %147
128: ; preds = %120
%129 = load i32, i32* %4
%130 = load i32, i32* %8
%131 = add nsw i32 %130, 1
%132 = icmp sle i32 %129, %131
br i1 %132, label %133, label %138
133: ; preds = %128
%134 = load i8**, i8*** %5
%135 = getelementptr inbounds i8*, i8** %134, i64 0
%136 = load i8*, i8** %135
%137 = call i32 @usage(i8* %136)
store i32 %137, i32* %3
br label %248
138: ; preds = %128
%139 = load i8**, i8*** %5
%140 = load i32, i32* %8
%141 = add nsw i32 %140, 1
%142 = sext i32 %141 to i64
%143 = getelementptr inbounds i8*, i8** %139, i64 %142
%144 = load i8*, i8** %143
store i8* %144, i8** %9
%145 = load i32, i32* %8
%146 = add nsw i32 %145, 2
store i32 %146, i32* %8
br label %180
147: ; preds = %120
%148 = load i8**, i8*** %5
%149 = load i32, i32* %8
%150 = sext i32 %149 to i64
%151 = getelementptr inbounds i8*, i8** %148, i64 %150
%152 = load i8*, i8** %151
%153 = call i64 @strcmp(i8* %152, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%154 = icmp eq i64 %153, 0
br i1 %154, label %155, label %174
155: ; preds = %147
%156 = load i32, i32* %4
%157 = load i32, i32* %8
%158 = add nsw i32 %157, 1
%159 = icmp sle i32 %156, %158
br i1 %159, label %160, label %165
160: ; preds = %155
%161 = load i8**, i8*** %5
%162 = getelementptr inbounds i8*, i8** %161, i64 0
%163 = load i8*, i8** %162
%164 = call i32 @usage(i8* %163)
store i32 %164, i32* %3
br label %248
165: ; preds = %155
%166 = load i8**, i8*** %5
%167 = load i32, i32* %8
%168 = add nsw i32 %167, 1
%169 = sext i32 %168 to i64
%170 = getelementptr inbounds i8*, i8** %166, i64 %169
%171 = load i8*, i8** %170
store i8* %171, i8** %10
%172 = load i32, i32* %8
%173 = add nsw i32 %172, 2
store i32 %173, i32* %8
br label %179
174: ; preds = %147
%175 = load i8**, i8*** %5
%176 = getelementptr inbounds i8*, i8** %175, i64 0
%177 = load i8*, i8** %176
%178 = call i32 @usage(i8* %177)
store i32 %178, i32* %3
br label %248
179: ; preds = %165
br label %180
180: ; preds = %179, %138
br label %181
181: ; preds = %180, %117
%182 = load i32, i32* %4
%183 = load i32, i32* %8
%184 = sub nsw i32 %182, %183
%185 = icmp slt i32 %184, 1
br i1 %185, label %186, label %191
186: ; preds = %181
%187 = load i8**, i8*** %5
%188 = getelementptr inbounds i8*, i8** %187, i64 0
%189 = load i8*, i8** %188
%190 = call i32 @usage(i8* %189)
store i32 %190, i32* %3
br label %248
191: ; preds = %181
br label %20
192: ; preds = %20
%193 = call i64 (...) @fork()
store i64 %193, i64* %6
%194 = load i64, i64* %6
%195 = icmp slt i64 %194, 0
br i1 %195, label %196, label %198
196: ; preds = %192
%197 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
br label %224
198: ; preds = %192
%199 = load i64, i64* %6
%200 = icmp eq i64 %199, 0
br i1 %200, label %201, label %223
201: ; preds = %198
%202 = load i8*, i8** %9
%203 = call i32 @redirect_stdouterr(i8* %202)
%204 = load i8**, i8*** %5
%205 = load i32, i32* %8
%206 = sext i32 %205 to i64
%207 = getelementptr inbounds i8*, i8** %204, i64 %206
%208 = load i8*, i8** %207
%209 = load i8**, i8*** %5
%210 = load i32, i32* %8
%211 = sext i32 %210 to i64
%212 = getelementptr inbounds i8*, i8** %209, i64 %211
%213 = call i32 @execv(i8* %208, i8** %212)
%214 = load i32*, i32** @stderr
%215 = load i8**, i8*** %5
%216 = load i32, i32* %8
%217 = sext i32 %216 to i64
%218 = getelementptr inbounds i8*, i8** %215, i64 %217
%219 = load i8*, i8** %218
%220 = ptrtoint i8* %219 to i64
%221 = call i32 (i32*, i8*, i64, ...) @fprintf(i32* %214, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i64 %220)
%222 = call i32 @exit(i32 1)
unreachable
223: ; preds = %198
br label %224
224: ; preds = %223, %196
%225 = load i8*, i8** %10
%226 = icmp eq i8* %225, null
br i1 %226, label %227, label %230
227: ; preds = %224
%228 = load i64, i64* %6
%229 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64 %228)
br label %230
230: ; preds = %227, %224
%231 = load i8*, i8** %10
%232 = icmp ne i8* %231, null
br i1 %232, label %233, label %247
233: ; preds = %230
%234 = load i8*, i8** %10
%235 = call i32* @fopen(i8* %234, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i32* %235, i32** %11
%236 = load i32*, i32** %11
%237 = icmp eq i32* %236, null
br i1 %237, label %238, label %241
238: ; preds = %233
%239 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0))
%240 = call i32 @exit(i32 1)
unreachable
241: ; preds = %233
%242 = load i32*, i32** %11
%243 = load i64, i64* %6
%244 = call i32 (i32*, i8*, i64, ...) @fprintf(i32* %242, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64 %243)
%245 = load i32*, i32** %11
%246 = call i32 @fclose(i32* %245)
br label %247
247: ; preds = %241, %230
store i32 0, i32* %3
br label %248
248: ; preds = %247, %186, %174, %160, %133, %43, %14
%249 = load i32, i32* %3
ret i32 %249
}

LLVM IR (-O2):
@.str = [5 x i8] c"-env\00"
@stderr = global i32* null
@.str.1 = [33 x i8] c"error in setenv of \22%s\22 to \22%s\22\0A\00"
@.str.2 = [20 x i8] c"setenv returned %d\0A\00"
@.str.3 = [26 x i8] c"env var \22%s\22 is now \22%s\22\0A\00"
@.str.4 = [5 x i8] c"-out\00"
@.str.5 = [5 x i8] c"-pid\00"
@.str.6 = [14 x i8] c"ERROR on fork\00"
@.str.7 = [19 x i8] c"execv of %s FAILED\00"
@.str.8 = [4 x i8] c"%d\0A\00"
@.str.9 = [2 x i8] c"w\00"
@.str.10 = [20 x i8] c"open pidfile failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @usage(i8* %5)
br label %125
7: ; preds = %2, %87
%8 = phi i32 [ %91, %87 ], [ 1, %2 ]
%9 = phi i8* [ %89, %87 ], [ null, %2 ]
%10 = phi i8* [ %90, %87 ], [ null, %2 ]
%11 = zext i32 %8 to i64
%12 = getelementptr inbounds i8*, i8** %1, i64 %11
%13 = load i8*, i8** %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 45
br i1 %15, label %16, label %96
16: ; preds = %7
%17 = tail call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %56
19: ; preds = %16
%20 = add nuw nsw i32 %8, 2
%21 = icmp slt i32 %20, %0
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i8*, i8** %1
%24 = tail call i32 @usage(i8* %23)
br label %125
25: ; preds = %19
%26 = add nuw nsw i32 %8, 1
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %1, i64 %27
%29 = load i8*, i8** %28
%30 = zext i32 %20 to i64
%31 = getelementptr inbounds i8*, i8** %1, i64 %30
%32 = load i8*, i8** %31
%33 = tail call i32 @setenv(i8* %29, i8* %32, i32 1)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %25
%36 = load i8*, i8** %28
%37 = tail call i8* @mygetenv(i8* %36)
%38 = load i8*, i8** %31
%39 = tail call i64 @strcmp(i8* %37, i8* %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %87, label %41
41: ; preds = %35, %25
%42 = load i32*, i32** @stderr
%43 = load i8*, i8** %28
%44 = ptrtoint i8* %43 to i64
%45 = load i8*, i8** %31
%46 = tail call i32 (i32*, i8*, i64, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i64 %44, i8* %45)
%47 = load i32*, i32** @stderr
%48 = sext i32 %33 to i64
%49 = tail call i32 (i32*, i8*, i64, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 %48)
%50 = load i32*, i32** @stderr
%51 = load i8*, i8** %28
%52 = ptrtoint i8* %51 to i64
%53 = tail call i8* @mygetenv(i8* %51)
%54 = tail call i32 (i32*, i8*, i64, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i64 %52, i8* %53)
%55 = tail call i32 @exit(i32 1)
unreachable
56: ; preds = %16
%57 = load i8*, i8** %12
%58 = tail call i64 @strcmp(i8* %57, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %70
60: ; preds = %56
%61 = add nuw nsw i32 %8, 1
%62 = icmp slt i32 %61, %0
br i1 %62, label %66, label %63
63: ; preds = %60
%64 = load i8*, i8** %1
%65 = tail call i32 @usage(i8* %64)
br label %125
66: ; preds = %60
%67 = zext i32 %61 to i64
%68 = getelementptr inbounds i8*, i8** %1, i64 %67
%69 = load i8*, i8** %68
br label %87
70: ; preds = %56
%71 = load i8*, i8** %12
%72 = tail call i64 @strcmp(i8* %71, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%73 = icmp eq i64 %72, 0
br i1 %73, label %74, label %84
74: ; preds = %70
%75 = add nuw nsw i32 %8, 1
%76 = icmp slt i32 %75, %0
br i1 %76, label %80, label %77
77: ; preds = %74
%78 = load i8*, i8** %1
%79 = tail call i32 @usage(i8* %78)
br label %125
80: ; preds = %74
%81 = zext i32 %75 to i64
%82 = getelementptr inbounds i8*, i8** %1, i64 %81
%83 = load i8*, i8** %82
br label %87
84: ; preds = %70
%85 = load i8*, i8** %1
%86 = tail call i32 @usage(i8* %85)
br label %125
87: ; preds = %35, %66, %80
%88 = phi i32 [ 2, %66 ], [ 2, %80 ], [ 3, %35 ]
%89 = phi i8* [ %69, %66 ], [ %9, %80 ], [ %9, %35 ]
%90 = phi i8* [ %10, %66 ], [ %83, %80 ], [ %10, %35 ]
%91 = add nuw nsw i32 %8, %88
%92 = icmp slt i32 %91, %0
br i1 %92, label %7, label %93
93: ; preds = %87
%94 = load i8*, i8** %1
%95 = tail call i32 @usage(i8* %94)
br label %125
96: ; preds = %7
%97 = tail call i64 (...) @fork()
%98 = icmp slt i64 %97, 0
br i1 %98, label %99, label %101
99: ; preds = %96
%100 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
br label %112
101: ; preds = %96
%102 = icmp eq i64 %97, 0
br i1 %102, label %103, label %112
103: ; preds = %101
%104 = tail call i32 @redirect_stdouterr(i8* %9)
%105 = load i8*, i8** %12
%106 = tail call i32 @execv(i8* %105, i8** %12)
%107 = load i32*, i32** @stderr
%108 = load i8*, i8** %12
%109 = ptrtoint i8* %108 to i64
%110 = tail call i32 (i32*, i8*, i64, ...) @fprintf(i32* %107, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i64 %109)
%111 = tail call i32 @exit(i32 1)
unreachable
112: ; preds = %101, %99
%113 = icmp eq i8* %10, null
br i1 %113, label %114, label %116
114: ; preds = %112
%115 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64 %97)
br label %125
116: ; preds = %112
%117 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%118 = icmp eq i32* %117, null
br i1 %118, label %119, label %122
119: ; preds = %116
%120 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0))
%121 = tail call i32 @exit(i32 1)
unreachable
122: ; preds = %116
%123 = tail call i32 (i32*, i8*, i64, ...) @fprintf(i32* %117, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64 %97)
%124 = tail call i32 @fclose(i32* %117)
br label %125
125: ; preds = %114, %122, %93, %84, %77, %63, %22, %4
%126 = phi i32 [ %6, %4 ], [ %24, %22 ], [ %95, %93 ], [ %65, %63 ], [ %79, %77 ], [ %86, %84 ], [ 0, %122 ], [ 0, %114 ]
ret i32 %126
}