#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 EOF;
int WEXITSTATUS(int);
int errno;
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
char *optarg;
int optind;
int /*<<< orphan*/ stderr;
int strlen(char *);
int system(char *);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  char *cmd = "";
  int c;
  while ((c = getopt(argc, argv, "c:")) != EOF) {
    switch (c) {
    case 'c':
      cmd = optarg;
      if (strlen(cmd) > 1024) {
        fprintf(stderr,
                "The length of CLASSPATH must be less than %d character", 1024);
        usage();
      }
      break;
    default:
      usage();
    }
  }
  if (optind < argc) {
    usage();
  }
  int cpid;
  if ((cpid = fork()) < 0) {
    fprintf(stderr, "%s: fork failed\n", argv[0]);
    exit(1);
  } else if (cpid == 0) {
    int status;
    status = system(cmd);
    if (status) {
      fprintf(stderr, "failed command -- %s\n status %d\n errno=%d\n", cmd,
              WEXITSTATUS(status), errno);
    }
    exit(status);
  } else {
    exit(0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xed8(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe51(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e22(%rip),%rcx
cmp    (%rcx),%eax
je     122d <main+0xad>
mov    -0x1c(%rbp),%eax
sub    $0x63,%eax
jne    1221 <main+0xa1>
jmp    11d7 <main+0x57>
mov    0x2e1a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x400,%eax
jle    121c <main+0x9c>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xdfa(%rip),%rsi
mov    $0x400,%edx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1060 <usage@plt>
jmp    1228 <main+0xa8>
mov    $0x0,%al
call   1060 <usage@plt>
jmp    11a1 <main+0x21>
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    1246 <main+0xc6>
mov    $0x0,%al
call   1060 <usage@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    1281 <main+0x101>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdca(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpl   $0x0,-0x20(%rbp)
jne    12e6 <main+0x166>
mov    -0x18(%rbp),%rdi
call   1040 <system@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     12de <main+0x15e>
mov    0x2d20(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%edi
call   1070 <WEXITSTATUS@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %eax,%ecx
mov    0x2cf3(%rip),%rax
mov    (%rax),%r8d
lea    0xd74(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%edi
call   1090 <exit@plt>
xor    %edi,%edi
call   1090 <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,%ebp
lea    0xe69(%rip),%rdx
call   1080 <getopt@plt>
mov    0x2e3d(%rip),%r13
cmp    0x0(%r13),%eax
jne    11f5 <main+0x75>
lea    0xec5(%rip),%r14
mov    0x2e21(%rip),%rax
cmp    %ebp,(%rax)
jge    11c2 <main+0x42>
xor    %eax,%eax
call   1060 <usage@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
jns    125f <main+0xdf>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe56(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xe79(%rip),%r14
mov    0x2df5(%rip),%r15
lea    0xdf6(%rip),%r12
jmp    122a <main+0xaa>
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <usage@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1080 <getopt@plt>
cmp    0x0(%r13),%eax
je     11b0 <main+0x30>
cmp    $0x63,%eax
jne    1210 <main+0x90>
mov    (%r15),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    $0x401,%eax
jl     1217 <main+0x97>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xdb2(%rip),%rsi
mov    $0x400,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1210 <main+0x90>
jne    12a5 <main+0x125>
mov    %r14,%rdi
call   1040 <system@plt>
mov    %eax,%ebx
test   %eax,%eax
je     129e <main+0x11e>
mov    0x2d52(%rip),%rax
mov    (%rax),%ebp
mov    %ebx,%edi
call   1070 <WEXITSTATUS@plt>
mov    0x2d3a(%rip),%rcx
mov    (%rcx),%r8d
lea    0xdbb(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebx,%edi
call   1090 <exit@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"c:\00"
@EOF = global i32 0
@optarg = global i8* null
@stderr = global i32 0
@.str.2 = [55 x i8] c"The length of CLASSPATH must be less than %d character\00"
@optind = global i32 0
@.str.3 = [17 x i8] c"%s: fork failed\0A\00"
@.str.4 = [43 x i8] c"failed command -- %s\0A status %d\0A errno=%d\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %6
br label %10
10: ; preds = %30, %2
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @getopt(i32 %11, i8** %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 %13, i32* %7
%14 = load i32, i32* @EOF
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %31
16: ; preds = %10
%17 = load i32, i32* %7
switch i32 %17, label %28 [
i32 99, label %18
]
18: ; preds = %16
%19 = load i8*, i8** @optarg
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = call i32 @strlen(i8* %20)
%22 = icmp sgt i32 %21, 1024
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i32 1024)
%26 = call i32 (...) @usage()
br label %27
27: ; preds = %23, %18
br label %30
28: ; preds = %16
%29 = call i32 (...) @usage()
br label %30
30: ; preds = %28, %27
br label %10
31: ; preds = %10
%32 = load i32, i32* @optind
%33 = load i32, i32* %4
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 (...) @usage()
br label %37
37: ; preds = %35, %31
%38 = call i32 (...) @fork()
store i32 %38, i32* %8
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %47
40: ; preds = %37
%41 = load i32, i32* @stderr
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %44)
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %37
%48 = load i32, i32* %8
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %65
50: ; preds = %47
%51 = load i8*, i8** %6
%52 = call i32 @system(i8* %51)
store i32 %52, i32* %9
%53 = load i32, i32* %9
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %62
55: ; preds = %50
%56 = load i32, i32* @stderr
%57 = load i8*, i8** %6
%58 = load i32, i32* %9
%59 = call i32 @WEXITSTATUS(i32 %58)
%60 = load i32, i32* @errno
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* %57, i32 %59, i32 %60)
br label %62
62: ; preds = %55, %50
%63 = load i32, i32* %9
%64 = call i32 @exit(i32 %63)
unreachable
65: ; preds = %47
%66 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"c:\00"
@EOF = global i32 0
@optarg = global i8* null
@stderr = global i32 0
@.str.2 = [55 x i8] c"The length of CLASSPATH must be less than %d character\00"
@optind = global i32 0
@.str.3 = [17 x i8] c"%s: fork failed\0A\00"
@.str.4 = [43 x i8] c"failed command -- %s\0A status %d\0A errno=%d\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %25, label %6
6: ; preds = %2, %20
%7 = phi i32 [ %22, %20 ], [ %3, %2 ]
%8 = phi i8* [ %21, %20 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %2 ]
%9 = icmp eq i32 %7, 99
br i1 %9, label %10, label %17
10: ; preds = %6
%11 = load i8*, i8** @optarg
%12 = tail call i32 @strlen(i8* %11)
%13 = icmp sgt i32 %12, 1024
br i1 %13, label %14, label %20
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i32 1024)
br label %17
17: ; preds = %6, %14
%18 = phi i8* [ %11, %14 ], [ %8, %6 ]
%19 = tail call i32 (...) @usage()
br label %20
20: ; preds = %17, %10
%21 = phi i8* [ %11, %10 ], [ %18, %17 ]
%22 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @EOF
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %6
25: ; preds = %20, %2
%26 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %2 ], [ %21, %20 ]
%27 = load i32, i32* @optind
%28 = icmp slt i32 %27, %0
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = tail call i32 (...) @usage()
br label %31
31: ; preds = %29, %25
%32 = tail call i32 (...) @fork()
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %1
%37 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %36)
%38 = tail call i32 @exit(i32 1)
unreachable
39: ; preds = %31
%40 = icmp eq i32 %32, 0
br i1 %40, label %41, label %51
41: ; preds = %39
%42 = tail call i32 @system(i8* %26)
%43 = icmp eq i32 %42, 0
br i1 %43, label %49, label %44
44: ; preds = %41
%45 = load i32, i32* @stderr
%46 = tail call i32 @WEXITSTATUS(i32 %42)
%47 = load i32, i32* @errno
%48 = tail call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* %26, i32 %46, i32 %47)
br label %49
49: ; preds = %44, %41
%50 = tail call i32 @exit(i32 %42)
unreachable
51: ; preds = %39
%52 = tail call i32 @exit(i32 0)
unreachable
}