#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 fork();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ wait(int *);
void next(int i, int n, int k) {
  int st, pid;
  if (i == k)
    return;
  if ((pid = fork()) == 0) {
    int j;
    for (j = i * n; j < i * n + n - 1; j++)
      printf("%d ", j);
    printf("\n");
    next(i + 1, n, k);
    if (i != k - 1)
      wait(&st);
  }
}


x86 assembly (clang, -O0):
<next>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    1162 <next+0x22>
jmp    11f4 <next+0xb4>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    11f4 <next+0xb4>
mov    -0x4(%rbp),%eax
imul   -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x4(%rbp),%ecx
imul   -0x8(%rbp),%ecx
add    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11b6 <next+0x76>
mov    -0x18(%rbp),%esi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    117f <next+0x3f>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1040 <next@plt>
mov    -0x4(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     11ef <next+0xaf>
lea    -0x10(%rbp),%rdi
call   1050 <wait@plt>
jmp    11f4 <next+0xb4>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    %edx,%edi
je     11d0 <next+0x80>
mov    %edx,%r12d
mov    %esi,%r15d
mov    %edi,%r14d
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
jne    11d0 <next+0x80>
mov    %r15d,%ebx
imul   %r14d,%ebx
lea    (%r15,%rbx,1),%eax
add    $0xffffffff,%eax
cmp    %eax,%ebx
jge    11a4 <next+0x54>
lea    -0x1(%r15),%ebp
lea    0xe70(%rip),%r13
mov    %r13,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
add    $0xffffffff,%ebp
jne    1190 <next+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x1(%r14),%edi
mov    %r15d,%esi
mov    %r12d,%edx
call   1050 <next@plt>
add    $0xffffffff,%r12d
cmp    %r14d,%r12d
je     11d0 <next+0x80>
lea    0x4(%rsp),%rdi
call   1060 <wait@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @next(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %4
%11 = load i32, i32* %6
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %3
br label %49
14: ; preds = %3
%15 = call i32 (...) @fork()
store i32 %15, i32* %8
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %49
17: ; preds = %14
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = mul nsw i32 %18, %19
store i32 %20, i32* %9
br label %21
21: ; preds = %33, %17
%22 = load i32, i32* %9
%23 = load i32, i32* %4
%24 = load i32, i32* %5
%25 = mul nsw i32 %23, %24
%26 = load i32, i32* %5
%27 = add nsw i32 %25, %26
%28 = sub nsw i32 %27, 1
%29 = icmp slt i32 %22, %28
br i1 %29, label %30, label %36
30: ; preds = %21
%31 = load i32, i32* %9
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %30
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 1
store i32 %35, i32* %9
br label %21
36: ; preds = %21
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
%40 = load i32, i32* %5
%41 = load i32, i32* %6
%42 = load i32, i32* %4
%43 = load i32, i32* %6
%44 = sub nsw i32 %43, 1
%45 = icmp ne i32 %42, %44
br i1 %45, label %46, label %48
46: ; preds = %36
%47 = call i32 @wait(i32* %7)
br label %48
48: ; preds = %46, %36
br label %49
49: ; preds = %13, %48, %14
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d \00"
define void @next(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = icmp eq i32 %0, %2
br i1 %6, label %27, label %7
7: ; preds = %3
%8 = tail call i32 (...) @fork()
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %27
10: ; preds = %7
%11 = mul nsw i32 %1, %0
%12 = add i32 %1, -1
%13 = add i32 %12, %11
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %20
15: ; preds = %10, %15
%16 = phi i32 [ %18, %15 ], [ %11, %10 ]
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = add i32 %16, 1
%19 = icmp eq i32 %18, %13
br i1 %19, label %20, label %15
20: ; preds = %15, %10
%21 = tail call i32 @putchar(i32 10)
%22 = add nsw i32 %0, 1
tail call void @next(i32 %22, i32 %1, i32 %2)
%23 = add nsw i32 %2, -1
%24 = icmp eq i32 %23, %0
br i1 %24, label %27, label %25
25: ; preds = %20
%26 = call i32 @wait(i32* %4)
br label %27
27: ; preds = %7, %25, %20, %3
ret void
}