#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;

/* Variables and functions */
scalar_t__ fork();
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int runfork(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("Usage : %s <command>\n", argv[0]);
    return 0;
  }
  if (!strcmp("-v", argv[1])) {
    printf("Version 1.0\n");
    return 0;
  }
  if (!strcmp("-h", argv[1])) {
    printf("Usage : %s <command>\n", argv[0]);
    return 0;
  }
  pid_t self;
  self = fork();
  if (self < 0) {
    printf("Error!\n");
    return 1;
  } else if (self > 0) {
    return 0;
  } else {
    int i;
    int len = 0;
    for (i = 1; i < argc; i++) {
      len = len + strlen(argv[i]);
    }
    char *cmd = malloc(sizeof(char) * (len + (argc - 1)));
    for (i = 1; i < argc; i++) {
      strcat(cmd, argv[i]);
      if (i != argc - 1) {
        strcat(cmd, " ");
      }
    }
    return runfork(cmd);
  }
  return 0;
}


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)
cmpl   $0x2,-0x8(%rbp)
jge    11b1 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    133a <main+0x1ca>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe56(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11e8 <main+0x78>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    133a <main+0x1ca>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe2f(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1226 <main+0xb6>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    133a <main+0x1ca>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1256 <main+0xe6>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    133a <main+0x1ca>
cmpq   $0x0,-0x18(%rbp)
jle    126d <main+0xfd>
movl   $0x0,-0x4(%rbp)
jmp    133a <main+0x1ca>
movl   $0x0,-0x20(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12b6 <main+0x146>
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    127b <main+0x10b>
mov    -0x20(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
add    %ecx,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    132e <main+0x1be>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1080 <strcat@plt>
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     131b <main+0x1ab>
mov    -0x28(%rbp),%rdi
lea    0xd1b(%rip),%rsi
call   1080 <strcat@plt>
jmp    1320 <main+0x1b0>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12d9 <main+0x169>
mov    -0x28(%rbp),%rdi
call   1070 <runfork@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
cmp    $0x1,%edi
jg     11ac <main+0x2c>
mov    0x0(%r13),%rsi
lea    0xe62(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1289 <main+0x109>
mov    %edi,%r14d
mov    0x8(%r13),%rbp
lea    0xe5c(%rip),%rdi
mov    %rbp,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     1268 <main+0xe8>
lea    0xe48(%rip),%rdi
mov    %rbp,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     1193 <main+0x13>
xor    %ebp,%ebp
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
js     1278 <main+0xf8>
jne    1289 <main+0x109>
mov    %r14d,%r15d
xor    %ebp,%ebp
mov    $0x1,%ebx
nop
mov    0x0(%r13,%rbx,8),%rdi
call   1040 <strlen@plt>
add    %eax,%ebp
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1200 <main+0x80>
mov    %r14d,%r12d
add    $0xffffffff,%r12d
lea    (%r14,%rbp,1),%edi
add    $0xffffffff,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
mov    $0x1,%ebx
lea    0xde5(%rip),%r14
jmp    1249 <main+0xc9>
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %rbx,%r15
je     129a <main+0x11a>
mov    0x0(%r13,%rbx,8),%rsi
mov    %rbp,%rdi
call   1090 <strcat@plt>
cmp    %rbx,%r12
je     1240 <main+0xc0>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1090 <strcat@plt>
jmp    1240 <main+0xc0>
lea    0xdaf(%rip),%rdi
call   1030 <puts@plt>
xor    %ebp,%ebp
jmp    1289 <main+0x109>
lea    0xdab(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <runfork@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Usage : %s <command>\0A\00"
@.str.1 = [3 x i8] c"-v\00"
@.str.2 = [13 x i8] c"Version 1.0\0A\00"
@.str.3 = [3 x i8] c"-h\00"
@.str.4 = [8 x i8] c"Error!\0A\00"
@.str.5 = [2 x i8] c" \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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 0, i32* %3
br label %98
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %17
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %98
25: ; preds = %17
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %36, label %31
31: ; preds = %25
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 0
%34 = load i8*, i8** %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %34)
store i32 0, i32* %3
br label %98
36: ; preds = %25
%37 = call i64 (...) @fork()
store i64 %37, i64* %6
%38 = load i64, i64* %6
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %98
42: ; preds = %36
%43 = load i64, i64* %6
%44 = icmp sgt i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %42
store i32 0, i32* %3
br label %98
46: ; preds = %42
store i32 0, i32* %8
store i32 1, i32* %7
br label %47
47: ; preds = %60, %46
%48 = load i32, i32* %7
%49 = load i32, i32* %4
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %63
51: ; preds = %47
%52 = load i32, i32* %8
%53 = load i8**, i8*** %5
%54 = load i32, i32* %7
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %53, i64 %55
%57 = load i8*, i8** %56
%58 = call i32 @strlen(i8* %57)
%59 = add nsw i32 %52, %58
store i32 %59, i32* %8
br label %60
60: ; preds = %51
%61 = load i32, i32* %7
%62 = add nsw i32 %61, 1
store i32 %62, i32* %7
br label %47
63: ; preds = %47
%64 = load i32, i32* %8
%65 = load i32, i32* %4
%66 = sub nsw i32 %65, 1
%67 = add nsw i32 %64, %66
%68 = sext i32 %67 to i64
%69 = mul i64 1, %68
%70 = trunc i64 %69 to i32
%71 = call i8* @malloc(i32 %70)
store i8* %71, i8** %9
store i32 1, i32* %7
br label %72
72: ; preds = %92, %63
%73 = load i32, i32* %7
%74 = load i32, i32* %4
%75 = icmp slt i32 %73, %74
br i1 %75, label %76, label %95
76: ; preds = %72
%77 = load i8*, i8** %9
%78 = load i8**, i8*** %5
%79 = load i32, i32* %7
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8*, i8** %78, i64 %80
%82 = load i8*, i8** %81
%83 = call i32 @strcat(i8* %77, i8* %82)
%84 = load i32, i32* %7
%85 = load i32, i32* %4
%86 = sub nsw i32 %85, 1
%87 = icmp ne i32 %84, %86
br i1 %87, label %88, label %91
88: ; preds = %76
%89 = load i8*, i8** %9
%90 = call i32 @strcat(i8* %89, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %91
91: ; preds = %88, %76
br label %92
92: ; preds = %91
%93 = load i32, i32* %7
%94 = add nsw i32 %93, 1
store i32 %94, i32* %7
br label %72
95: ; preds = %72
%96 = load i8*, i8** %9
%97 = call i32 @runfork(i8* %96)
store i32 %97, i32* %3
br label %98
98: ; preds = %95, %45, %40, %31, %23, %12
%99 = load i32, i32* %3
ret i32 %99
}

LLVM IR (-O2):
@.str = [22 x i8] c"Usage : %s <command>\0A\00"
@.str.1 = [3 x i8] c"-v\00"
@.str.3 = [3 x i8] c"-h\00"
@.str.5 = [2 x i8] c" \00"
@str = [12 x i8] c"Version 1.0\00"
@str.6 = [7 x i8] c"Error!\00"
define i32 @main(i32 %0, i8** nocapture %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 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %57
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @strcmp(i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* dereferenceable(1) %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %57
14: ; preds = %7
%15 = tail call i32 @strcmp(i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* dereferenceable(1) %9)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i8*, i8** %1
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %57
20: ; preds = %14
%21 = tail call i64 (...) @fork()
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.6, i64 0, i64 0))
br label %57
25: ; preds = %20
%26 = icmp eq i64 %21, 0
br i1 %26, label %27, label %57
27: ; preds = %25
%28 = zext i32 %0 to i64
br label %29
29: ; preds = %27, %29
%30 = phi i64 [ 1, %27 ], [ %36, %29 ]
%31 = phi i32 [ 0, %27 ], [ %35, %29 ]
%32 = getelementptr inbounds i8*, i8** %1, i64 %30
%33 = load i8*, i8** %32
%34 = tail call i32 @strlen(i8* %33)
%35 = add nsw i32 %34, %31
%36 = add nuw nsw i64 %30, 1
%37 = icmp eq i64 %36, %28
br i1 %37, label %38, label %29
38: ; preds = %29
%39 = add nsw i32 %0, -1
%40 = add nsw i32 %35, %39
%41 = tail call i8* @malloc(i32 %40)
%42 = zext i32 %39 to i64
%43 = zext i32 %0 to i64
br label %44
44: ; preds = %38, %52
%45 = phi i64 [ 1, %38 ], [ %53, %52 ]
%46 = getelementptr inbounds i8*, i8** %1, i64 %45
%47 = load i8*, i8** %46
%48 = tail call i32 @strcat(i8* %41, i8* %47)
%49 = icmp eq i64 %45, %42
br i1 %49, label %52, label %50
50: ; preds = %44
%51 = tail call i32 @strcat(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %52
52: ; preds = %44, %50
%53 = add nuw nsw i64 %45, 1
%54 = icmp eq i64 %53, %43
br i1 %54, label %55, label %44
55: ; preds = %52
%56 = tail call i32 @runfork(i8* %41)
br label %57
57: ; preds = %23, %55, %25, %17, %12, %4
%58 = phi i32 [ 0, %4 ], [ 0, %17 ], [ 0, %12 ], [ 1, %23 ], [ %56, %55 ], [ 0, %25 ]
ret i32 %58
}