#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*/ close(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int main(void) {
  int i = 0;
  char c;
  FILE *p1 = NULL;
  FILE *p2 = NULL;
  p1 = fopen("chu", "r");
  p2 = fopen("ru", "w+");
  while (1) {
    if (fread(&c, 1, 1, p1) <= 0) {
      break;
    }
    if (c == '\n') {
      if (++i == 1)
        continue;
    }
    fwrite(&c, 1, 1, p2);
  }
  close(p1);
  close(p2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe93(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    0xe82(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rcx
lea    -0x9(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x0,%rax
jg     11b7 <main+0x77>
jmp    11f9 <main+0xb9>
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
jne    11e0 <main+0xa0>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x1,%eax
jne    11db <main+0x9b>
jmp    1194 <main+0x54>
jmp    11e0 <main+0xa0>
mov    -0x20(%rbp),%rcx
lea    -0x9(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1060 <fwrite@plt>
jmp    1194 <main+0x54>
mov    -0x18(%rbp),%rdi
call   1040 <close@plt>
mov    -0x20(%rbp),%rdi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xeb2(%rip),%rdi
lea    0xeaf(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xea2(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
lea    0x7(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
test   %rax,%rax
jle    11da <main+0x9a>
xor    %ebp,%ebp
lea    0x7(%rsp),%r15
jmp    11c5 <main+0x85>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
test   %rax,%rax
jle    11da <main+0x9a>
movsbl 0x7(%rsp),%edi
cmp    $0xa,%edi
jne    11a3 <main+0x63>
test   %ebp,%ebp
jne    11a0 <main+0x60>
mov    $0x1,%ebp
jmp    11ab <main+0x6b>
mov    %rbx,%rdi
call   1040 <close@plt>
mov    %r14,%rdi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"chu\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"ru\00"
@.str.3 = [3 x i8] c"w+\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
%4 = alloca i32*
%5 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %2
store i32* null, i32** %4
store i32* null, i32** %5
%6 = call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %4
%7 = call i32* @fopen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %7, i32** %5
br label %8
8: ; preds = %0, %21, %23
%9 = load i32*, i32** %4
%10 = call i64 @fread(i8* %3, i32 1, i32 1, i32* %9)
%11 = icmp sle i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %8
br label %26
13: ; preds = %8
%14 = load i8, i8* %3
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 10
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
store i32 %19, i32* %2
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %22
21: ; preds = %17
br label %8
22: ; preds = %17
br label %23
23: ; preds = %22, %13
%24 = load i32*, i32** %5
%25 = call i32 @fwrite(i8* %3, i32 1, i32 1, i32* %24)
br label %8
26: ; preds = %12
%27 = load i32*, i32** %4
%28 = call i32 @close(i32* %27)
%29 = load i32*, i32** %5
%30 = call i32 @close(i32* %29)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"chu\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"ru\00"
@.str.3 = [3 x i8] c"w+\00"
define i32 @main() {
%1 = alloca i8
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%4 = call i64 @fread(i8* %1, i32 1, i32 1, i32* %2)
%5 = icmp slt i64 %4, 1
br i1 %5, label %21, label %6
6: ; preds = %0, %17
%7 = phi i32 [ %18, %17 ], [ 0, %0 ]
%8 = load i8, i8* %1
%9 = icmp eq i8 %8, 10
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = add nsw i32 %7, 1
%12 = icmp eq i32 %7, 0
br i1 %12, label %17, label %13
13: ; preds = %10, %6
%14 = phi i32 [ %11, %10 ], [ %7, %6 ]
%15 = sext i8 %8 to i32
%16 = tail call i32 @fputc(i32 %15, i32* %3)
br label %17
17: ; preds = %13, %10
%18 = phi i32 [ 1, %10 ], [ %14, %13 ]
%19 = call i64 @fread(i8* %1, i32 1, i32 1, i32* %2)
%20 = icmp slt i64 %19, 1
br i1 %20, label %21, label %6
21: ; preds = %17, %0
%22 = tail call i32 @close(i32* %2)
%23 = tail call i32 @close(i32* %3)
ret i32 0
}