#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 fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
int getpid();
int getppid();
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sscanf(int /*<<< orphan*/, char *, int *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wait(int *);
int main(int argc, char *argv[]) {
  int n = 0, opt = 0, i = 0;
  pid_t ppid = 0;
  char err = '\0';
  int err_w = 0;
  char help_msg[] =
      "Usage : -n create n process and print all information about\n";
  while ((opt = getopt(argc, argv, "n:")) != -1) {
    switch (opt) {
    case 'n':
      sscanf(optarg, "%d%c", &n, &err);
      if (err != '\0') {
        fprintf(stderr, help_msg);
        return 0;
      }
      break;
    default:
      fprintf(stderr, help_msg);
      return 1;
    }
  }
  if (optind > argc) {
    fprintf(stderr, "No argument after -n %d");
    return 2;
  }
  if (n <= 0) {
    fprintf(stderr, "Incorrect argument");
    return 3;
  }
  ppid = getpid();
  for (i = 0; i < n; ++i) {
    pid_t pid = 0;
    if ((pid = fork()) == 0) {
      pid = getpid();
      fprintf(stderr, "%d %d %d\n", i + 1, pid, getppid());
      return 0;
    }
    wait((int *)12345);
    perror("ds");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movb   $0x0,-0x21(%rbp)
movl   $0x0,-0x28(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xe25(%rip),%rsi
mov    $0x3d,%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe4a(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     1289 <main+0xf9>
mov    -0x18(%rbp),%eax
sub    $0x6e,%eax
jne    1264 <main+0xd4>
jmp    1215 <main+0x85>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
lea    0xe1b(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x21(%rbp),%rcx
call   1060 <sscanf@plt>
movsbl -0x21(%rbp),%eax
cmp    $0x0,%eax
je     125f <main+0xcf>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
lea    -0x70(%rbp),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    139f <main+0x20f>
jmp    1284 <main+0xf4>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
lea    -0x70(%rbp),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    139f <main+0x20f>
jmp    11e5 <main+0x55>
mov    0x2d50(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jle    12be <main+0x12e>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
lea    0xd9a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    139f <main+0x20f>
cmpl   $0x0,-0x14(%rbp)
jg     12eb <main+0x15b>
mov    0x2d01(%rip),%rax
mov    (%rax),%edi
lea    0xd85(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    139f <main+0x20f>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1398 <main+0x208>
movl   $0x0,-0x74(%rbp)
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x74(%rbp)
cmp    $0x0,%eax
jne    1374 <main+0x1e4>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x74(%rbp)
mov    0x2c9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x80(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
mov    -0x74(%rbp),%eax
mov    %eax,-0x78(%rbp)
mov    $0x0,%al
call   1090 <getppid@plt>
mov    -0x80(%rbp),%edi
mov    -0x7c(%rbp),%edx
mov    -0x78(%rbp),%ecx
mov    %eax,%r8d
lea    0xd0f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    139f <main+0x20f>
mov    $0x3039,%edi
call   10a0 <wait@plt>
lea    0xcf5(%rip),%rdi
call   1070 <perror@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12fc <main+0x16c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movl   $0x0,0xc(%rsp)
movb   $0x0,0xb(%rsp)
movups 0xe86(%rip),%xmm0
movups %xmm0,0x3d(%rsp)
movaps 0xe6d(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe51(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe35(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xe66(%rip),%r14
lea    0xe62(%rip),%r15
lea    0xc(%rsp),%r12
lea    0xb(%rsp),%r13
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1070 <getopt@plt>
cmp    $0x6e,%eax
jne    1239 <main+0xb9>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
call   1050 <sscanf@plt>
cmpb   $0x0,0xb(%rsp)
je     11f0 <main+0x70>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
xor    %ebx,%ebx
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1281 <main+0x101>
cmp    $0xffffffff,%eax
jne    1267 <main+0xe7>
mov    0x2d9b(%rip),%rax
cmp    %ebp,(%rax)
jle    1292 <main+0x112>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xdec(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x2,%ebx
jmp    1281 <main+0x101>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmpl   $0x0,0xc(%rsp)
jle    12e5 <main+0x165>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
cmpl   $0x0,0xc(%rsp)
jle    1281 <main+0x101>
mov    $0x1,%r14d
lea    0xdc4(%rip),%rbp
xor    %ebx,%ebx
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     1306 <main+0x186>
mov    $0x3039,%edi
call   1090 <wait@plt>
mov    %rbp,%rdi
call   1060 <perror@plt>
lea    0x1(%r14),%eax
cmp    0xc(%rsp),%r14d
mov    %eax,%r14d
jl     12b8 <main+0x138>
jmp    1281 <main+0x101>
mov    0x2ce4(%rip),%rax
mov    (%rax),%edi
lea    0xd68(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x3,%ebx
jmp    1281 <main+0x101>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%r15d
mov    0x2cb7(%rip),%rax
mov    (%rax),%ebp
xor    %eax,%eax
call   1080 <getppid@plt>
lea    0xd47(%rip),%rsi
mov    %ebp,%edi
mov    %r14d,%edx
mov    %r15d,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1281 <main+0x101>

LLVM IR (-O0):
@__const.main.help_msg = [61 x i8] c"Usage : -n create n process and print all information about\0A\00"
@.str = [3 x i8] c"n:\00"
@optarg = global i32 0
@.str.1 = [5 x i8] c"%d%c\00"
@stderr = global i32 0
@optind = global i32 0
@.str.2 = [24 x i8] c"No argument after -n %d\00"
@.str.3 = [19 x i8] c"Incorrect argument\00"
@.str.4 = [10 x i8] c"%d %d %d\0A\00"
@.str.5 = [3 x i8] c"ds\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 i32
%10 = alloca i8
%11 = alloca i32
%12 = alloca [61 x i8]
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i8 0, i8* %10
store i32 0, i32* %11
%14 = bitcast [61 x i8]* %12 to i8*
br label %15
15: ; preds = %37, %2
%16 = load i32, i32* %4
%17 = load i8**, i8*** %5
%18 = call i32 @getopt(i32 %16, i8** %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %18, i32* %7
%19 = icmp ne i32 %18, -1
br i1 %19, label %20, label %38
20: ; preds = %15
%21 = load i32, i32* %7
switch i32 %21, label %33 [
i32 110, label %22
]
22: ; preds = %20
%23 = load i32, i32* @optarg
%24 = call i32 @sscanf(i32 %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %6, i8* %10)
%25 = load i8, i8* %10
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %22
%29 = load i32, i32* @stderr
%30 = getelementptr inbounds [61 x i8], [61 x i8]* %12, i64 0, i64 0
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* %30)
store i32 0, i32* %3
br label %75
32: ; preds = %22
br label %37
33: ; preds = %20
%34 = load i32, i32* @stderr
%35 = getelementptr inbounds [61 x i8], [61 x i8]* %12, i64 0, i64 0
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* %35)
store i32 1, i32* %3
br label %75
37: ; preds = %32
br label %15
38: ; preds = %15
%39 = load i32, i32* @optind
%40 = load i32, i32* %4
%41 = icmp sgt i32 %39, %40
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %3
br label %75
45: ; preds = %38
%46 = load i32, i32* %6
%47 = icmp sle i32 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %45
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i32 3, i32* %3
br label %75
51: ; preds = %45
%52 = call i32 (...) @getpid()
store i32 %52, i32* %9
store i32 0, i32* %8
br label %53
53: ; preds = %71, %51
%54 = load i32, i32* %8
%55 = load i32, i32* %6
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %74
57: ; preds = %53
store i32 0, i32* %13
%58 = call i32 (...) @fork()
store i32 %58, i32* %13
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %68
60: ; preds = %57
%61 = call i32 (...) @getpid()
store i32 %61, i32* %13
%62 = load i32, i32* @stderr
%63 = load i32, i32* %8
%64 = add nsw i32 %63, 1
%65 = load i32, i32* %13
%66 = call i32 (...) @getppid()
%67 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %64, i32 %65, i32 %66)
store i32 0, i32* %3
br label %75
68: ; preds = %57
%69 = call i32 @wait(i32* inttoptr (i64 12345 to i32*))
%70 = call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %71
71: ; preds = %68
%72 = load i32, i32* %8
%73 = add nsw i32 %72, 1
store i32 %73, i32* %8
br label %53
74: ; preds = %53
store i32 0, i32* %3
br label %75
75: ; preds = %74, %60, %48, %42, %33, %28
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
@__const.main.help_msg = [61 x i8] c"Usage : -n create n process and print all information about\0A\00"
@.str = [3 x i8] c"n:\00"
@optarg = global i32 0
@.str.1 = [5 x i8] c"%d%c\00"
@stderr = global i32 0
@optind = global i32 0
@.str.2 = [24 x i8] c"No argument after -n %d\00"
@.str.3 = [19 x i8] c"Incorrect argument\00"
@.str.4 = [10 x i8] c"%d %d %d\0A\00"
@.str.5 = [3 x i8] c"ds\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca [61 x i8]
%6 = bitcast i32* %3 to i8*
store i32 0, i32* %3
store i8 0, i8* %4
%7 = getelementptr inbounds [61 x i8], [61 x i8]* %5, i64 0, i64 0
br label %8
8: ; preds = %10, %2
%9 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
switch i32 %9, label %18 [
i32 -1, label %21
i32 110, label %10
]
10: ; preds = %8
%11 = load i32, i32* @optarg
%12 = call i32 @sscanf(i32 %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %3, i8* %4)
%13 = load i8, i8* %4
%14 = icmp eq i8 %13, 0
br i1 %14, label %8, label %15
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* %7)
br label %53
18: ; preds = %8
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* %7)
br label %53
21: ; preds = %8
%22 = load i32, i32* @optind
%23 = icmp sgt i32 %22, %0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %53
27: ; preds = %21
%28 = load i32, i32* %3
%29 = icmp slt i32 %28, 1
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %53
33: ; preds = %27
%34 = call i32 (...) @getpid()
%35 = load i32, i32* %3
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %53
37: ; preds = %33, %47
%38 = phi i32 [ %50, %47 ], [ 0, %33 ]
%39 = call i32 (...) @fork()
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %37
%42 = call i32 (...) @getpid()
%43 = load i32, i32* @stderr
%44 = add nuw nsw i32 %38, 1
%45 = call i32 (...) @getppid()
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %44, i32 %42, i32 %45)
br label %53
47: ; preds = %37
%48 = call i32 @wait(i32* inttoptr (i64 12345 to i32*))
%49 = call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%50 = add nuw nsw i32 %38, 1
%51 = load i32, i32* %3
%52 = icmp slt i32 %50, %51
br i1 %52, label %37, label %53
53: ; preds = %47, %33, %41, %30, %24, %18, %15
%54 = phi i32 [ 0, %15 ], [ 1, %18 ], [ 2, %24 ], [ 3, %30 ], [ 0, %41 ], [ 0, %33 ], [ 0, %47 ]
ret i32 %54
}