#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*/ SIGINT;
int /*<<< orphan*/ SIGUSR1;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ getppid();
int /*<<< orphan*/ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int main(int argc, char *argv[]) {
  int fd, max, i;
  char buffer[45];
  if ((fd = open(argv[1], O_RDONLY)) < 0)
    perror("child:open error");
  max = *argv[2];
  printf("%d", max);
  for (i = 1; i <= 200; i++) {
    read(fd, buffer, 45);
    printf("%s\n", buffer);
    if (i == 200)
      kill(getppid(), SIGINT);
    else
      kill(getppid(), SIGUSR1);
  }
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11b4 <main+0x44>
lea    0xe51(%rip),%rdi
call   1080 <perror@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsbl (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x1c(%rbp)
cmpl   $0xc8,-0x1c(%rbp)
jg     125d <main+0xed>
mov    -0x14(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x2d,%edx
call   1050 <read@plt>
lea    -0x50(%rbp),%rsi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0xc8,-0x1c(%rbp)
jne    1233 <main+0xc3>
mov    $0x0,%al
call   1090 <getppid@plt>
mov    %eax,%edi
mov    0x2db9(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
jmp    124a <main+0xda>
mov    $0x0,%al
call   1090 <getppid@plt>
mov    %eax,%edi
mov    0x2da5(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
jmp    124f <main+0xdf>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11da <main+0x6a>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
js     1243 <main+0xc3>
mov    0x10(%rbx),%rax
movsbl (%rax),%esi
lea    0xe59(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rbx
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x2d,%edx
call   1060 <read@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   10a0 <getppid@plt>
mov    $0xc7,%ebp
mov    0x2dfb(%rip),%r15
nopl   (%rax)
mov    (%r15),%esi
mov    %eax,%edi
call   1070 <kill@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x2d,%edx
call   1060 <read@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   10a0 <getppid@plt>
add    $0xffffffff,%ebp
jne    11f0 <main+0x70>
mov    0x2dbb(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1070 <kill@plt>
mov    %r14d,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdb6(%rip),%rdi
call   1090 <perror@plt>
jmp    11aa <main+0x2a>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [17 x i8] c"child:open error\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@SIGINT = global i32 0
@SIGUSR1 = global i32 0
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 [45 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = call i32 @open(i8* %12, i32 %13)
store i32 %14, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %24)
store i32 1, i32* %8
br label %26
26: ; preds = %46, %18
%27 = load i32, i32* %8
%28 = icmp sle i32 %27, 200
br i1 %28, label %29, label %49
29: ; preds = %26
%30 = load i32, i32* %6
%31 = getelementptr inbounds [45 x i8], [45 x i8]* %9, i64 0, i64 0
%32 = call i32 @read(i32 %30, i8* %31, i32 45)
%33 = getelementptr inbounds [45 x i8], [45 x i8]* %9, i64 0, i64 0
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = load i32, i32* %8
%36 = icmp eq i32 %35, 200
br i1 %36, label %37, label %41
37: ; preds = %29
%38 = call i32 (...) @getppid()
%39 = load i32, i32* @SIGINT
%40 = call i32 @kill(i32 %38, i32 %39)
br label %45
41: ; preds = %29
%42 = call i32 (...) @getppid()
%43 = load i32, i32* @SIGUSR1
%44 = call i32 @kill(i32 %42, i32 %43)
br label %45
45: ; preds = %41, %37
br label %46
46: ; preds = %45
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %26
49: ; preds = %26
%50 = load i32, i32* %6
%51 = call i32 @close(i32 %50)
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [17 x i8] c"child:open error\00"
@.str.1 = [3 x i8] c"%d\00"
@SIGINT = global i32 0
@SIGUSR1 = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [45 x i8]
%4 = getelementptr inbounds [45 x i8], [45 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* %6, i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = call i32 @read(i32 %8, i8* %4, i32 45)
%19 = call i32 @puts(i8* %4)
%20 = tail call i32 (...) @getppid()
br label %21
21: ; preds = %12, %21
%22 = phi i32 [ %20, %12 ], [ %30, %21 ]
%23 = phi i32 [ 1, %12 ], [ %26, %21 ]
%24 = load i32, i32* @SIGUSR1
%25 = tail call i32 @kill(i32 %22, i32 %24)
%26 = add nuw nsw i32 %23, 1
%27 = call i32 @read(i32 %8, i8* %4, i32 45)
%28 = call i32 @puts(i8* %4)
%29 = icmp eq i32 %26, 200
%30 = tail call i32 (...) @getppid()
br i1 %29, label %31, label %21
31: ; preds = %21
%32 = load i32, i32* @SIGINT
%33 = tail call i32 @kill(i32 %30, i32 %32)
%34 = tail call i32 @close(i32 %8)
ret i32 0
}