#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fork();
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char);
int read(int, char *, int);
int /*<<< orphan*/ wait(int *);
int main(int argc, char *argv[]) {
  char c;
  int read_count;
  for (int i = 2; i < argc; i++) {
    if (!fork()) {
      int n = argv[1][0] - '0';
      int fd = open(argv[i], O_RDONLY);
      char chars[10000];
      int counter = 0;
      while ((read_count = read(fd, &c, 1))) {
        chars[counter] = c;
        counter++;
        if (counter == n)
          break;
      }
      for (int j = 0; j < n; j++) {
        printf("%c", chars[j]);
      }
      close(fd);
    }
  }
  for (int i = 2; i < argc; i++) {
    int status;
    wait(&status);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2750,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x2,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    128d <main+0x12d>
mov    $0x0,%al
call   1080 <fork@plt>
cmp    $0x0,%eax
jne    127a <main+0x11a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x2744(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     122a <main+0xca>
mov    -0x11(%rbp),%cl
movslq -0x2744(%rbp),%rax
mov    %cl,-0x2740(%rbp,%rax,1)
mov    -0x2744(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2744(%rbp)
mov    -0x2744(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    1225 <main+0xc5>
jmp    122a <main+0xca>
jmp    11d4 <main+0x74>
movl   $0x0,-0x2748(%rbp)
mov    -0x2748(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1272 <main+0x112>
movslq -0x2748(%rbp),%rax
lea    0xdaf(%rip),%rdi
movsbl -0x2740(%rbp,%rax,1),%esi
ff
call   1030 <printf@plt>
mov    -0x2748(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2748(%rbp)
jmp    1234 <main+0xd4>
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
jmp    127f <main+0x11f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1180 <main+0x20>
movl   $0x2,-0x274c(%rbp)
mov    -0x274c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12c6 <main+0x166>
lea    -0x2750(%rbp),%rdi
call   1070 <wait@plt>
mov    -0x274c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x274c(%rbp)
jmp    1297 <main+0x137>
xor    %eax,%eax
add    $0x2750,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2738,%rsp
mov    %rsi,0x18(%rsp)
cmp    $0x3,%edi
jl     127d <main+0x11d>
mov    %edi,0x8(%rsp)
mov    %edi,%ebx
mov    $0x2,%r14d
lea    0x7(%rsp),%rbp
lea    0xe69(%rip),%r12
mov    %rbx,0x10(%rsp)
jmp    11bc <main+0x5c>
xchg   %ax,%ax
mov    %ebx,%edi
call   1040 <close@plt>
mov    0x10(%rsp),%rbx
mov    %r15,%rbp
add    $0x1,%r14
cmp    %rbx,%r14
je     125b <main+0xfb>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
jne    11af <main+0x4f>
mov    0x18(%rsp),%rcx
mov    0x8(%rcx),%rax
movsbl (%rax),%eax
mov    %eax,0xc(%rsp)
mov    %eax,%r13d
add    $0xffffffd0,%r13d
mov    (%rcx,%r14,8),%rdi
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,%ebx
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
test   %eax,%eax
je     1226 <main+0xc6>
movzbl 0x7(%rsp),%eax
mov    %al,0x20(%rsp,%r15,1)
add    $0x1,%r15
cmp    %r15,%r13
jne    1200 <main+0xa0>
mov    %rbp,%r15
cmpb   $0x31,0xc(%rsp)
jl     11a0 <main+0x40>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
movsbl 0x20(%rsp,%rbp,1),%esi
mov    %r12,%rdi
call   1030 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1240 <main+0xe0>
jmp    11a0 <main+0x40>
mov    0x8(%rsp),%ebp
cmp    $0x3,%ebp
jl     127d <main+0x11d>
add    $0xfffffffe,%ebp
lea    0x20(%rsp),%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1070 <wait@plt>
add    $0xffffffff,%ebp
jne    1270 <main+0x110>
xor    %eax,%eax
add    $0x2738,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [3 x i8] c"%c\00"
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
%10 = alloca i32
%11 = alloca [10000 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 2, i32* %8
br label %16
16: ; preds = %72, %2
%17 = load i32, i32* %8
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %75
20: ; preds = %16
%21 = call i32 (...) @fork()
%22 = icmp ne i32 %21, 0
br i1 %22, label %71, label %23
23: ; preds = %20
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = getelementptr inbounds i8, i8* %26, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = sub nsw i32 %29, 48
store i32 %30, i32* %9
%31 = load i8**, i8*** %5
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = load i32, i32* @O_RDONLY
%37 = call i32 @open(i8* %35, i32 %36)
store i32 %37, i32* %10
store i32 0, i32* %12
br label %38
38: ; preds = %53, %23
%39 = load i32, i32* %10
%40 = call i32 @read(i32 %39, i8* %6, i32 1)
store i32 %40, i32* %7
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %54
42: ; preds = %38
%43 = load i8, i8* %6
%44 = load i32, i32* %12
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [10000 x i8], [10000 x i8]* %11, i64 0, i64 %45
store i8 %43, i8* %46
%47 = load i32, i32* %12
%48 = add nsw i32 %47, 1
store i32 %48, i32* %12
%49 = load i32, i32* %12
%50 = load i32, i32* %9
%51 = icmp eq i32 %49, %50
br i1 %51, label %52, label %53
52: ; preds = %42
br label %54
53: ; preds = %42
br label %38
54: ; preds = %52, %38
store i32 0, i32* %13
br label %55
55: ; preds = %65, %54
%56 = load i32, i32* %13
%57 = load i32, i32* %9
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %68
59: ; preds = %55
%60 = load i32, i32* %13
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [10000 x i8], [10000 x i8]* %11, i64 0, i64 %61
%63 = load i8, i8* %62
%64 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %63)
br label %65
65: ; preds = %59
%66 = load i32, i32* %13
%67 = add nsw i32 %66, 1
store i32 %67, i32* %13
br label %55
68: ; preds = %55
%69 = load i32, i32* %10
%70 = call i32 @close(i32 %69)
br label %71
71: ; preds = %68, %20
br label %72
72: ; preds = %71
%73 = load i32, i32* %8
%74 = add nsw i32 %73, 1
store i32 %74, i32* %8
br label %16
75: ; preds = %16
store i32 2, i32* %14
br label %76
76: ; preds = %82, %75
%77 = load i32, i32* %14
%78 = load i32, i32* %4
%79 = icmp slt i32 %77, %78
br i1 %79, label %80, label %85
80: ; preds = %76
%81 = call i32 @wait(i32* %15)
br label %82
82: ; preds = %80
%83 = load i32, i32* %14
%84 = add nsw i32 %83, 1
store i32 %84, i32* %14
br label %76
85: ; preds = %76
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [3 x i8] c"%c\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = alloca [10000 x i8]
%5 = alloca i32
%6 = icmp sgt i32 %0, 2
br i1 %6, label %7, label %51
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 0
%10 = zext i32 %0 to i64
br label %14
11: ; preds = %48
br i1 %6, label %12, label %51
12: ; preds = %11
%13 = bitcast i32* %5 to i8*
br label %52
14: ; preds = %7, %48
%15 = phi i64 [ 2, %7 ], [ %49, %48 ]
%16 = tail call i32 (...) @fork()
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %48
18: ; preds = %14
%19 = load i8*, i8** %8
%20 = load i8, i8* %19
%21 = sext i8 %20 to i64
%22 = add nsw i64 %21, 4294967248
%23 = getelementptr inbounds i8*, i8** %1, i64 %15
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_RDONLY
%26 = tail call i32 @open(i8* %24, i32 %25)
%27 = and i64 %22, 4294967295
br label %28
28: ; preds = %32, %18
%29 = phi i64 [ %35, %32 ], [ 0, %18 ]
%30 = call i32 @read(i32 %26, i8* %3, i32 1)
%31 = icmp eq i32 %30, 0
br i1 %31, label %37, label %32
32: ; preds = %28
%33 = load i8, i8* %3
%34 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 %29
store i8 %33, i8* %34
%35 = add nuw nsw i64 %29, 1
%36 = icmp eq i64 %35, %27
br i1 %36, label %37, label %28
37: ; preds = %32, %28
%38 = icmp sgt i8 %20, 48
br i1 %38, label %41, label %39
39: ; preds = %41, %37
%40 = tail call i32 @close(i32 %26)
br label %48
41: ; preds = %37, %41
%42 = phi i64 [ %46, %41 ], [ 0, %37 ]
%43 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %44)
%46 = add nuw nsw i64 %42, 1
%47 = icmp eq i64 %46, %27
br i1 %47, label %39, label %41
48: ; preds = %14, %39
%49 = add nuw nsw i64 %15, 1
%50 = icmp eq i64 %49, %10
br i1 %50, label %11, label %14
51: ; preds = %52, %2, %11
ret i32 0
52: ; preds = %12, %52
%53 = phi i32 [ 2, %12 ], [ %55, %52 ]
%54 = call i32 @wait(i32* %5)
%55 = add nuw nsw i32 %53, 1
%56 = icmp eq i32 %55, %0
br i1 %56, label %51, label %52
}