#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ stdout;
void main(int argc, char *argv[]) {
  char s[1024];
  FILE *fp1;
  if (argc > 1)
    fp1 = fopen(argv[1], "r");
  else
    fp1 = stdin;
  while ((fgets(s, 1023, fp1)) != (char *)0) {
    if (s[0] == '\n')
      break;
    fputs(s, stdout);
  }
  if (fp1 != stdin)
    fclose(fp1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x4(%rbp)
jle    117c <main+0x3c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x418(%rbp)
jmp    118d <main+0x4d>
mov    0x2e65(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x418(%rbp)
jmp    1192 <main+0x52>
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rdx
mov    $0x3ff,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11e3 <main+0xa3>
movsbl -0x410(%rbp),%eax
cmp    $0xa,%eax
jne    11c9 <main+0x89>
jmp    11e3 <main+0xa3>
lea    -0x410(%rbp),%rdi
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
jmp    1192 <main+0x52>
mov    -0x418(%rbp),%rax
mov    0x2df7(%rip),%rcx
cmp    (%rcx),%rax
je     1206 <main+0xc6>
mov    -0x418(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
cmp    $0x2,%edi
jl     1166 <main+0x26>
mov    0x8(%rsi),%rdi
lea    0xea4(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
jmp    1170 <main+0x30>
mov    0x2e7b(%rip),%rax
mov    (%rax),%r14
mov    %rsp,%rdi
mov    $0x3ff,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11c6 <main+0x86>
cmpb   $0xa,(%rsp)
je     11c6 <main+0x86>
mov    0x2e46(%rip),%r15
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15),%esi
mov    %rbx,%rdi
call   1040 <fputs@plt>
mov    %rbx,%rdi
mov    $0x3ff,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11c6 <main+0x86>
cmpb   $0xa,(%rsp)
jne    11a0 <main+0x60>
mov    0x2e1b(%rip),%rax
cmp    (%rax),%r14
je     11da <main+0x9a>
mov    %r14,%rdi
call   1030 <fclose@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stdin = global i32* null
@stdout = global i32 0
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [1024 x i8]
%6 = alloca i32*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = load i32, i32* %3
%8 = icmp sgt i32 %7, 1
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i8**, i8*** %4
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %6
br label %16
14: ; preds = %2
%15 = load i32*, i32** @stdin
store i32* %15, i32** %6
br label %16
16: ; preds = %14, %9
br label %17
17: ; preds = %28, %16
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%19 = load i32*, i32** %6
%20 = call i8* @fgets(i8* %18, i32 1023, i32* %19)
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %32
22: ; preds = %17
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 10
br i1 %26, label %27, label %28
27: ; preds = %22
br label %32
28: ; preds = %22
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%30 = load i32, i32* @stdout
%31 = call i32 @fputs(i8* %29, i32 %30)
br label %17
32: ; preds = %27, %17
%33 = load i32*, i32** %6
%34 = load i32*, i32** @stdin
%35 = icmp ne i32* %33, %34
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = load i32*, i32** %6
%38 = call i32 @fclose(i32* %37)
br label %39
39: ; preds = %36, %32
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stdin = global i32* null
@stdout = global i32 0
define void @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %12
10: ; preds = %2
%11 = load i32*, i32** @stdin
br label %12
12: ; preds = %10, %6
%13 = phi i32* [ %9, %6 ], [ %11, %10 ]
%14 = call i8* @fgets(i8* %4, i32 1023, i32* %13)
%15 = icmp eq i8* %14, null
%16 = load i8, i8* %4
%17 = icmp eq i8 %16, 10
%18 = select i1 %15, i1 true, i1 %17
br i1 %18, label %27, label %19
19: ; preds = %12, %19
%20 = load i32, i32* @stdout
%21 = call i32 @fputs(i8* %4, i32 %20)
%22 = call i8* @fgets(i8* %4, i32 1023, i32* %13)
%23 = icmp eq i8* %22, null
%24 = load i8, i8* %4
%25 = icmp eq i8 %24, 10
%26 = select i1 %23, i1 true, i1 %25
br i1 %26, label %27, label %19
27: ; preds = %19, %12
%28 = load i32*, i32** @stdin
%29 = icmp eq i32* %13, %28
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = call i32 @fclose(i32* %13)
br label %32
32: ; preds = %30, %27
ret void
}