#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 */
char EOF;
int /*<<< orphan*/ fcloseall();
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int main() {
  FILE *f1, *f2;
  char c;
  int n;
  f1 = fopen("source.txt", "r");
  f2 = fopen("dest.txt", "w");
  n = 0;
  while ((c = fgetc(f1)) != EOF) {
    if ((n == 0 || c != '\n')) {
      fputc(c, f2);
      n = 0;
    }
    if (c == '\n') {
      n++;
    }
  }
  fcloseall();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xeae(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xea0(%rip),%rdi
lea    0xea2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%eax
mov    0x2e4e(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11ed <main+0xad>
cmpl   $0x0,-0x20(%rbp)
je     11bc <main+0x7c>
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
je     11d2 <main+0x92>
mov    -0x19(%rbp),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
movl   $0x0,-0x20(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
jne    11e8 <main+0xa8>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1184 <main+0x44>
mov    $0x0,%al
call   1060 <fcloseall@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xeb1(%rip),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r15
lea    0xea8(%rip),%rdi
lea    0xeaa(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1030 <fgetc@plt>
mov    0x2e65(%rip),%r12
cmp    (%r12),%al
jne    119b <main+0x5b>
xor    %eax,%eax
call   1060 <fcloseall@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebx
xor    %ebp,%ebp
jmp    11d7 <main+0x97>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %bl,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
xor    %ebp,%ebp
xor    %eax,%eax
cmp    $0xa,%bl
sete   %al
add    %eax,%ebp
mov    %r15,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebx
cmp    (%r12),%al
je     1189 <main+0x49>
test   %ebp,%ebp
je     11b0 <main+0x70>
cmp    $0xa,%bl
je     11bd <main+0x7d>
jmp    11b0 <main+0x70>

LLVM IR (-O0):
@.str = [11 x i8] c"source.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"dest.txt\00"
@.str.3 = [2 x i8] c"w\00"
@EOF = global i8 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i8
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 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** %2
%7 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %7, i32** %3
store i32 0, i32* %5
br label %8
8: ; preds = %33, %0
%9 = load i32*, i32** %2
%10 = call signext i8 @fgetc(i32* %9)
store i8 %10, i8* %4
%11 = sext i8 %10 to i32
%12 = load i8, i8* @EOF
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %11, %13
br i1 %14, label %15, label %34
15: ; preds = %8
%16 = load i32, i32* %5
%17 = icmp eq i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = load i8, i8* %4
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 10
br i1 %21, label %22, label %26
22: ; preds = %18, %15
%23 = load i8, i8* %4
%24 = load i32*, i32** %3
%25 = call i32 @fputc(i8 signext %23, i32* %24)
store i32 0, i32* %5
br label %26
26: ; preds = %22, %18
%27 = load i8, i8* %4
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 10
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %33
33: ; preds = %30, %26
br label %8
34: ; preds = %8
%35 = call i32 (...) @fcloseall()
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
@.str = [11 x i8] c"source.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"dest.txt\00"
@.str.3 = [2 x i8] c"w\00"
@EOF = global i8 0
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%3 = tail call signext i8 @fgetc(i32* %1)
%4 = load i8, i8* @EOF
%5 = icmp eq i8 %3, %4
br i1 %5, label %22, label %6
6: ; preds = %0, %14
%7 = phi i8 [ %19, %14 ], [ %3, %0 ]
%8 = phi i32 [ %18, %14 ], [ 0, %0 ]
%9 = icmp eq i32 %8, 0
%10 = icmp ne i8 %7, 10
%11 = or i1 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = tail call i32 @fputc(i8 signext %7, i32* %2)
br label %14
14: ; preds = %6, %12
%15 = phi i32 [ 0, %12 ], [ %8, %6 ]
%16 = icmp eq i8 %7, 10
%17 = zext i1 %16 to i32
%18 = add nsw i32 %15, %17
%19 = tail call signext i8 @fgetc(i32* %1)
%20 = load i8, i8* @EOF
%21 = icmp eq i8 %19, %20
br i1 %21, label %22, label %6
22: ; preds = %14, %0
%23 = tail call i32 (...) @fcloseall()
ret i32 0
}