#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 EAGAIN;
int atoi(char *);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int itime = 300;
  int exit_code = 0;
  int i;
  char tbuf[1025];
  int save_errno;
  int j;
  if (1 < argc)
    itime = atoi(argv[1]);
  if (2 < argc)
    exit_code = atoi(argv[2]);
  if (2 < argc)
    fprintf(stdout, "%d %d\n", itime, exit_code);
  while (1) {
    int j;
    j = read(0, tbuf, 1024);
    if (-1 == j) {
      save_errno = errno;
      if (EAGAIN != save_errno)
        fprintf(stderr, "errno = %d ", save_errno);
      continue;
    }
    if (0 == j)
      break;
    tbuf[j] = '\0';
    fprintf(stdout, "%s", tbuf);
    fflush(stdout);
  }
  for (i = 0; i < itime; i++) {
    sleep(1);
  }
  exit(exit_code);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x12c,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x1,%eax
cmp    -0x8(%rbp),%eax
jge    11a5 <main+0x45>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
jge    11c3 <main+0x63>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
jge    11ee <main+0x8e>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11f3 <main+0x93>
lea    -0x420(%rbp),%rsi
xor    %edi,%edi
mov    $0x400,%edx
call   1030 <read@plt>
mov    %eax,-0x42c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x42c(%rbp),%eax
jne    1263 <main+0x103>
mov    0x2db4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x424(%rbp)
mov    0x2d8d(%rip),%rax
mov    (%rax),%eax
cmp    -0x424(%rbp),%eax
je     125e <main+0xfe>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
mov    -0x424(%rbp),%edx
lea    0xdb0(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11f3 <main+0x93>
xor    %eax,%eax
cmp    -0x42c(%rbp),%eax
jne    1276 <main+0x116>
jmp    12b6 <main+0x156>
movslq -0x42c(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rdx
lea    0xd77(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
jmp    11f3 <main+0x93>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12e1 <main+0x181>
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12bd <main+0x15d>
mov    -0x18(%rbp),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    $0x12c,%ebp
cmp    $0x2,%edi
jl     1190 <main+0x30>
mov    %rsi,%r15
mov    %edi,%ebx
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
cmp    $0x2,%ebx
jne    119a <main+0x3a>
movl   $0x0,0xc(%rsp)
jmp    11c2 <main+0x62>
mov    0x10(%r15),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
mov    %ebp,%edx
mov    %ecx,0xc(%rsp)
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0x10(%rsp),%rbx
mov    0x2e0a(%rip),%r13
mov    0x2deb(%rip),%r14
mov    0x2df4(%rip),%r15
lea    0xe30(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1030 <read@plt>
cmp    $0xffffffff,%eax
je     1230 <main+0xd0>
test   %eax,%eax
je     1252 <main+0xf2>
cltq
movb   $0x0,0x10(%rsp,%rax,1)
mov    (%r15),%edi
mov    %r12,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r15),%edi
call   1050 <fflush@plt>
jmp    11f0 <main+0x90>
nopl   0x0(%rax)
mov    0x0(%r13),%edx
cmp    %edx,(%r14)
je     11f0 <main+0x90>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
lea    0xdbe(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11f0 <main+0x90>
test   %ebp,%ebp
jle    126f <main+0x10f>
cs nopw 0x0(%rax,%rax,1)
mov    $0x1,%edi
call   1080 <sleep@plt>
add    $0xffffffff,%ebp
jne    1260 <main+0x100>
mov    0xc(%rsp),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [7 x i8] c"%d %d\0A\00"
@errno = global i32 0
@EAGAIN = global i32 0
@stderr = global i32 0
@.str.1 = [12 x i8] c"errno = %d \00"
@.str.2 = [3 x i8] c"%s\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 [1025 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 300, i32* %6
store i32 0, i32* %7
%13 = load i32, i32* %4
%14 = icmp slt i32 1, %13
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %6
br label %20
20: ; preds = %15, %2
%21 = load i32, i32* %4
%22 = icmp slt i32 2, %21
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %7
br label %28
28: ; preds = %23, %20
%29 = load i32, i32* %4
%30 = icmp slt i32 2, %29
br i1 %30, label %31, label %36
31: ; preds = %28
%32 = load i32, i32* @stdout
%33 = load i32, i32* %6
%34 = load i32, i32* %7
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %33, i32 %34)
br label %36
36: ; preds = %31, %28
br label %37
37: ; preds = %36, %51, %56
%38 = getelementptr inbounds [1025 x i8], [1025 x i8]* %9, i64 0, i64 0
%39 = call i32 @read(i32 0, i8* %38, i32 1024)
store i32 %39, i32* %12
%40 = load i32, i32* %12
%41 = icmp eq i32 -1, %40
br i1 %41, label %42, label %52
42: ; preds = %37
%43 = load i32, i32* @errno
store i32 %43, i32* %10
%44 = load i32, i32* @EAGAIN
%45 = load i32, i32* %10
%46 = icmp ne i32 %44, %45
br i1 %46, label %47, label %51
47: ; preds = %42
%48 = load i32, i32* @stderr
%49 = load i32, i32* %10
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %47, %42
br label %37
52: ; preds = %37
%53 = load i32, i32* %12
%54 = icmp eq i32 0, %53
br i1 %54, label %55, label %56
55: ; preds = %52
br label %65
56: ; preds = %52
%57 = load i32, i32* %12
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [1025 x i8], [1025 x i8]* %9, i64 0, i64 %58
store i8 0, i8* %59
%60 = load i32, i32* @stdout
%61 = getelementptr inbounds [1025 x i8], [1025 x i8]* %9, i64 0, i64 0
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %61)
%63 = load i32, i32* @stdout
%64 = call i32 @fflush(i32 %63)
br label %37
65: ; preds = %55
store i32 0, i32* %8
br label %66
66: ; preds = %72, %65
%67 = load i32, i32* %8
%68 = load i32, i32* %6
%69 = icmp slt i32 %67, %68
br i1 %69, label %70, label %75
70: ; preds = %66
%71 = call i32 @sleep(i32 1)
br label %72
72: ; preds = %70
%73 = load i32, i32* %8
%74 = add nsw i32 %73, 1
store i32 %74, i32* %8
br label %66
75: ; preds = %66
%76 = load i32, i32* %7
%77 = call i32 @exit(i32 %76)
unreachable
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [7 x i8] c"%d %d\0A\00"
@errno = global i32 0
@EAGAIN = global i32 0
@stderr = global i32 0
@.str.1 = [12 x i8] c"errno = %d \00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1025 x i8]
%4 = getelementptr inbounds [1025 x i8], [1025 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %17
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = icmp eq i32 %0, 2
br i1 %10, label %17, label %11
11: ; preds = %6
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = load i32, i32* @stdout
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %14)
br label %17
17: ; preds = %6, %2, %11
%18 = phi i32 [ %14, %11 ], [ 0, %2 ], [ 0, %6 ]
%19 = phi i32 [ %9, %11 ], [ 300, %2 ], [ %9, %6 ]
br label %20
20: ; preds = %28, %17
%21 = call i32 @read(i32 0, i8* %4, i32 1024)
switch i32 %21, label %32 [
i32 -1, label %24
i32 0, label %22
]
22: ; preds = %20
%23 = icmp sgt i32 %19, 0
br i1 %23, label %39, label %44
24: ; preds = %20
%25 = load i32, i32* @errno
%26 = load i32, i32* @EAGAIN
%27 = icmp eq i32 %26, %25
br i1 %27, label %28, label %29
28: ; preds = %24, %29, %32
br label %20
29: ; preds = %24
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %28
32: ; preds = %20
%33 = sext i32 %21 to i64
%34 = getelementptr inbounds [1025 x i8], [1025 x i8]* %3, i64 0, i64 %33
store i8 0, i8* %34
%35 = load i32, i32* @stdout
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%37 = load i32, i32* @stdout
%38 = call i32 @fflush(i32 %37)
br label %28
39: ; preds = %22, %39
%40 = phi i32 [ %42, %39 ], [ 0, %22 ]
%41 = call i32 @sleep(i32 1)
%42 = add nuw nsw i32 %40, 1
%43 = icmp eq i32 %42, %19
br i1 %43, label %44, label %39
44: ; preds = %39, %22
%45 = call i32 @exit(i32 %18)
unreachable
}