#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(char);
int main() {
  FILE *fp = fopen("onetwo.txt", "r");
  char read;
  if (fp == NULL) {
    printf("ERROR: Could not open file.");
    return -1;
  }
  while ((read = getc(fp)) != EOF) {
    if (read == '\n')
      putchar(' ');
    else
      putchar(read);
  };
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1199 <main+0x49>
lea    0xe85(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <main+0xa9>
jmp    119e <main+0x4e>
mov    -0x10(%rbp),%rdi
call   1070 <getc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2e34(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11e9 <main+0x99>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
jne    11db <main+0x8b>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    11e4 <main+0x94>
movsbl -0x11(%rbp),%edi
call   1030 <putchar@plt>
jmp    119e <main+0x4e>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xea5(%rip),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b9 <main+0x69>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <getc@plt>
mov    0x2e6a(%rip),%r14
cmp    (%r14),%al
je     11ad <main+0x5d>
mov    $0x20,%ebp
nopl   0x0(%rax,%rax,1)
cmp    $0xa,%al
movzbl %al,%eax
cmove  %ebp,%eax
movsbl %al,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1070 <getc@plt>
cmp    (%r14),%al
jne    1190 <main+0x40>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    11ca <main+0x7a>
lea    0xe4d(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"onetwo.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [28 x i8] c"ERROR: Could not open file.\00"
@EOF = global i8 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8
store i32 0, i32* %1
%4 = 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* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %30
9: ; preds = %0
br label %10
10: ; preds = %26, %9
%11 = load i32*, i32** %2
%12 = call signext i8 @getc(i32* %11)
store i8 %12, i8* %3
%13 = sext i8 %12 to i32
%14 = load i8, i8* @EOF
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %13, %15
br i1 %16, label %17, label %27
17: ; preds = %10
%18 = load i8, i8* %3
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 10
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @putchar(i8 signext 32)
br label %26
23: ; preds = %17
%24 = load i8, i8* %3
%25 = call i32 @putchar(i8 signext %24)
br label %26
26: ; preds = %23, %21
br label %10
27: ; preds = %10
%28 = load i32*, i32** %2
%29 = call i32 @fclose(i32* %28)
store i32 0, i32* %1
br label %30
30: ; preds = %27, %7
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@.str = [11 x i8] c"onetwo.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [28 x i8] c"ERROR: Could not open file.\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 = icmp eq i32* %1, null
br i1 %2, label %7, label %3
3: ; preds = %0
%4 = tail call signext i8 @getc(i32* %1)
%5 = load i8, i8* @EOF
%6 = icmp eq i8 %4, %5
br i1 %6, label %17, label %9
7: ; preds = %0
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %19
9: ; preds = %3, %9
%10 = phi i8 [ %14, %9 ], [ %4, %3 ]
%11 = icmp eq i8 %10, 10
%12 = select i1 %11, i8 32, i8 %10
%13 = tail call i32 @putchar(i8 signext %12)
%14 = tail call signext i8 @getc(i32* %1)
%15 = load i8, i8* @EOF
%16 = icmp eq i8 %14, %15
br i1 %16, label %17, label %9
17: ; preds = %9, %3
%18 = tail call i32 @fclose(i32* %1)
br label %19
19: ; preds = %17, %7
%20 = phi i32 [ -1, %7 ], [ 0, %17 ]
ret i32 %20
}