#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 atoi(char *);
int /*<<< orphan*/ cleanup(char **);
int /*<<< orphan*/ do_child(int, int, char **, int, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int wait(int *);
int main(int argc, char **argv) {
  int i, start = 0, max;
  char script[150];
  max = 9;
  if (!strcmp(argv[1], "-processes")) {
    max = atoi(argv[2]);
    start = 2;
  }
  if (!strcmp(argv[1], "-script")) {
    strcpy(script, "/home/julia/coccinelle/tools/distributed/");
    strcat(script, argv[2]);
    start = 2;
  } else
    strcpy(script, "/home/julia/coccinelle/tools/distributed/"
                   "spatch_linux_script");
  if (!strcmp(argv[1], "--help")) {
    printf("spatch_linux [-processes n] foo.cocci ...\n");
    exit(0);
  }
  int pid;
  for (i = 0; i != max; i++) {
    if (!(pid = fork())) {
      do_child(i, argc - start, &argv[start], max, script);
    } else if (pid > 0) {
    } else
      printf("*** forking error ***\n");
  }
  int status;
  for (i = 0; i != max; i++) {
    pid = wait(&status);
  }
  cleanup(&argv[start]);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x9,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2a(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11fb <main+0x5b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x2,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe01(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    124b <main+0xab>
lea    -0xc0(%rbp),%rdi
lea    0xded(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0xc0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1090 <strcat@plt>
movl   $0x2,-0x18(%rbp)
jmp    125e <main+0xbe>
lea    -0xc0(%rbp),%rdi
lea    0xde4(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe0d(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    128e <main+0xee>
lea    0xdff(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     1319 <main+0x179>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,-0xc4(%rbp)
cmp    $0x0,%eax
jne    12e3 <main+0x143>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%esi
sub    -0x18(%rbp),%esi
mov    -0x10(%rbp),%rdx
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x1c(%rbp),%ecx
lea    -0xc0(%rbp),%r8
call   1030 <do_child@plt>
jmp    1306 <main+0x166>
cmpl   $0x0,-0xc4(%rbp)
jle    12f5 <main+0x155>
jmp    1301 <main+0x161>
lea    0xdb0(%rip),%rdi
call   1050 <printf@plt>
jmp    1306 <main+0x166>
jmp    130b <main+0x16b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1295 <main+0xf5>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     134c <main+0x1ac>
lea    -0xc8(%rbp),%rdi
call   10b0 <wait@plt>
mov    %eax,-0xc4(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1320 <main+0x180>
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
call   1070 <cleanup@plt>
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
mov    %rsi,%r12
mov    %edi,%r15d
mov    0x8(%rsi),%rbp
lea    0xe3e(%rip),%rsi
mov    %rbp,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     11d8 <main+0x38>
mov    $0x9,%ebx
xor    %r14d,%r14d
jmp    11ea <main+0x4a>
mov    0x10(%r12),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebx
mov    $0x2,%r14d
lea    0xe1a(%rip),%rsi
mov    %rbp,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     1210 <main+0x70>
lea    0xe39(%rip),%rsi
lea    0x20(%rsp),%rdi
call   1040 <strcpy@plt>
jmp    1237 <main+0x97>
lea    0xdfc(%rip),%rsi
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <strcpy@plt>
mov    0x10(%r12),%rsi
mov    %rbp,%rdi
call   1090 <strcat@plt>
mov    $0x2,%r14d
mov    0x8(%r12),%rdi
lea    0xe37(%rip),%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     12fa <main+0x15a>
mov    %r14d,%r13d
test   %ebx,%ebx
je     12dd <main+0x13d>
sub    %r14d,%r15d
mov    %r12,0x10(%rsp)
mov    %r13,0x8(%rsp)
lea    (%r12,%r13,8),%rbp
lea    0x20(%rsp),%r12
lea    0xe33(%rip),%r13
xor    %r14d,%r14d
jmp    129c <main+0xfc>
nopl   (%rax)
mov    %r14d,%edi
mov    %r15d,%esi
mov    %rbp,%rdx
mov    %ebx,%ecx
mov    %r12,%r8
call   1030 <do_child@plt>
add    $0x1,%r14d
cmp    %r14d,%ebx
je     12b3 <main+0x113>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %eax,%eax
je     1280 <main+0xe0>
jg     1293 <main+0xf3>
mov    %r13,%rdi
call   1050 <puts@plt>
jmp    1293 <main+0xf3>
test   %ebx,%ebx
mov    0x10(%rsp),%r12
mov    0x8(%rsp),%r13
je     12dd <main+0x13d>
lea    0x1c(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   10b0 <wait@plt>
add    $0xffffffff,%ebx
jne    12d0 <main+0x130>
lea    (%r12,%r13,8),%rdi
call   1070 <cleanup@plt>
xor    %eax,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd80(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"-processes\00"
@.str.1 = [8 x i8] c"-script\00"
@.str.2 = [42 x i8] c"/home/julia/coccinelle/tools/distributed/\00"
@.str.3 = [61 x i8] c"/home/julia/coccinelle/tools/distributed/spatch_linux_script\00"
@.str.4 = [7 x i8] c"--help\00"
@.str.5 = [43 x i8] c"spatch_linux [-processes n] foo.cocci ...\0A\00"
@.str.6 = [23 x i8] c"*** forking error ***\0A\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 i32
%9 = alloca [150 x i8]
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 9, i32* %8
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @strcmp(i8* %14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%16 = icmp ne i32 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %8
store i32 2, i32* %7
br label %22
22: ; preds = %17, %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @strcmp(i8* %25, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp ne i32 %26, 0
br i1 %27, label %36, label %28
28: ; preds = %22
%29 = getelementptr inbounds [150 x i8], [150 x i8]* %9, i64 0, i64 0
%30 = call i32 @strcpy(i8* %29, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%31 = getelementptr inbounds [150 x i8], [150 x i8]* %9, i64 0, i64 0
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i32 @strcat(i8* %31, i8* %34)
store i32 2, i32* %7
br label %39
36: ; preds = %22
%37 = getelementptr inbounds [150 x i8], [150 x i8]* %9, i64 0, i64 0
%38 = call i32 @strcpy(i8* %37, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0))
br label %39
39: ; preds = %36, %28
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i32 @strcmp(i8* %42, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%44 = icmp ne i32 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %39
%46 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
%47 = call i32 @exit(i32 0)
unreachable
48: ; preds = %39
store i32 0, i32* %6
br label %49
49: ; preds = %76, %48
%50 = load i32, i32* %6
%51 = load i32, i32* %8
%52 = icmp ne i32 %50, %51
br i1 %52, label %53, label %79
53: ; preds = %49
%54 = call i32 (...) @fork()
store i32 %54, i32* %10
%55 = icmp ne i32 %54, 0
br i1 %55, label %68, label %56
56: ; preds = %53
%57 = load i32, i32* %6
%58 = load i32, i32* %4
%59 = load i32, i32* %7
%60 = sub nsw i32 %58, %59
%61 = load i8**, i8*** %5
%62 = load i32, i32* %7
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8*, i8** %61, i64 %63
%65 = load i32, i32* %8
%66 = getelementptr inbounds [150 x i8], [150 x i8]* %9, i64 0, i64 0
%67 = call i32 @do_child(i32 %57, i32 %60, i8** %64, i32 %65, i8* %66)
br label %75
68: ; preds = %53
%69 = load i32, i32* %10
%70 = icmp sgt i32 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %68
br label %74
72: ; preds = %68
%73 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
br label %74
74: ; preds = %72, %71
br label %75
75: ; preds = %74, %56
br label %76
76: ; preds = %75
%77 = load i32, i32* %6
%78 = add nsw i32 %77, 1
store i32 %78, i32* %6
br label %49
79: ; preds = %49
store i32 0, i32* %6
br label %80
80: ; preds = %86, %79
%81 = load i32, i32* %6
%82 = load i32, i32* %8
%83 = icmp ne i32 %81, %82
br i1 %83, label %84, label %89
84: ; preds = %80
%85 = call i32 @wait(i32* %11)
store i32 %85, i32* %10
br label %86
86: ; preds = %84
%87 = load i32, i32* %6
%88 = add nsw i32 %87, 1
store i32 %88, i32* %6
br label %80
89: ; preds = %80
%90 = load i8**, i8*** %5
%91 = load i32, i32* %7
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i8*, i8** %90, i64 %92
%94 = call i32 @cleanup(i8** %93)
%95 = load i32, i32* %3
ret i32 %95
}

LLVM IR (-O2):
@.str = [11 x i8] c"-processes\00"
@.str.1 = [8 x i8] c"-script\00"
@.str.2 = [42 x i8] c"/home/julia/coccinelle/tools/distributed/\00"
@.str.3 = [61 x i8] c"/home/julia/coccinelle/tools/distributed/spatch_linux_script\00"
@.str.4 = [7 x i8] c"--help\00"
@str = [42 x i8] c"spatch_linux [-processes n] foo.cocci ...\00"
@str.7 = [22 x i8] c"*** forking error ***\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [150 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [150 x i8], [150 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @strcmp(i8* dereferenceable(1) %7, i8* dereferenceable(11) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
br label %14
14: ; preds = %10, %2
%15 = phi i32 [ 0, %2 ], [ 2, %10 ]
%16 = phi i32 [ 9, %2 ], [ %13, %10 ]
%17 = tail call i32 @strcmp(i8* dereferenceable(1) %7, i8* dereferenceable(8) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @strcat(i8* %5, i8* %22)
br label %26
24: ; preds = %14
%25 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0))
br label %26
26: ; preds = %24, %19
%27 = phi i32 [ %15, %24 ], [ 2, %19 ]
%28 = load i8*, i8** %6
%29 = call i32 @strcmp(i8* dereferenceable(1) %28, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%30 = icmp eq i32 %29, 0
br i1 %30, label %39, label %31
31: ; preds = %26
%32 = icmp eq i32 %16, 0
br i1 %32, label %33, label %35
33: ; preds = %31
%34 = bitcast i32* %4 to i8*
br label %62
35: ; preds = %31
%36 = sub nsw i32 %0, %27
%37 = zext i32 %27 to i64
%38 = getelementptr inbounds i8*, i8** %1, i64 %37
br label %42
39: ; preds = %26
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
%41 = call i32 @exit(i32 0)
unreachable
42: ; preds = %35, %52
%43 = phi i32 [ 0, %35 ], [ %53, %52 ]
%44 = call i32 (...) @fork()
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 @do_child(i32 %43, i32 %36, i8** %38, i32 %16, i8* %5)
br label %52
48: ; preds = %42
%49 = icmp sgt i32 %44, 0
br i1 %49, label %52, label %50
50: ; preds = %48
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.7, i64 0, i64 0))
br label %52
52: ; preds = %46, %48, %50
%53 = add nuw nsw i32 %43, 1
%54 = icmp eq i32 %53, %16
br i1 %54, label %55, label %42
55: ; preds = %52
%56 = bitcast i32* %4 to i8*
br i1 %32, label %62, label %57
57: ; preds = %55, %57
%58 = phi i32 [ %60, %57 ], [ 0, %55 ]
%59 = call i32 @wait(i32* %4)
%60 = add nuw nsw i32 %58, 1
%61 = icmp eq i32 %60, %16
br i1 %61, label %62, label %57
62: ; preds = %57, %33, %55
%63 = bitcast i32* %4 to i8*
%64 = zext i32 %27 to i64
%65 = getelementptr inbounds i8*, i8** %1, i64 %64
%66 = call i32 @cleanup(i8** %65)
ret i32 0
}