#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 EOF;
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int c;
  FILE *fd;
  if (argc > 2) {
    fprintf(stderr, "usage: %s [file]\n", argv[0]);
    return -1;
  }
  if (argc == 1)
    fd = stdin;
  else if (!(fd = fopen(argv[1], "r"))) {
    fprintf(stderr, "%s: unable to open file %s\n", argv[0], argv[1]);
    return -2;
  }
  while ((c = fgetc(fd)) != EOF)
    if (c == '\n')
      fputc(' ', stdout);
    else
      fputc(c, stdout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    118a <main+0x4a>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe89(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125f <main+0x11f>
cmpl   $0x1,-0x8(%rbp)
jne    11a7 <main+0x67>
mov    0x2e4d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1200 <main+0xc0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11fb <main+0xbb>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    125f <main+0x11f>
jmp    1200 <main+0xc0>
jmp    1205 <main+0xc5>
mov    -0x20(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dc8(%rip),%rcx
cmp    (%rcx),%eax
je     1258 <main+0x118>
cmpl   $0xa,-0x14(%rbp)
jne    1242 <main+0x102>
mov    0x2d97(%rip),%rax
mov    (%rax),%esi
mov    $0x20,%edi
call   1040 <fputc@plt>
jmp    1253 <main+0x113>
mov    -0x14(%rbp),%edi
mov    0x2d7c(%rip),%rax
mov    (%rax),%esi
call   1040 <fputc@plt>
jmp    1205 <main+0xc5>
movl   $0x0,-0x4(%rbp)
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
mov    %rsi,%rbp
cmp    $0x3,%edi
jl     1176 <main+0x36>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xe9c(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%r14d
jmp    1215 <main+0xd5>
cmp    $0x1,%edi
jne    1187 <main+0x47>
mov    0x2e66(%rip),%rax
mov    (%rax),%rbx
jmp    119f <main+0x5f>
mov    0x8(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11f0 <main+0xb0>
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    0x2e32(%rip),%r15
xor    %r14d,%r14d
cmp    (%r15),%eax
je     1215 <main+0xd5>
mov    0x2e0b(%rip),%r12
mov    $0x20,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0xa,%eax
mov    (%r12),%esi
cmove  %ebp,%eax
mov    %eax,%edi
call   1040 <fputc@plt>
mov    %rbx,%rdi
call   1030 <fgetc@plt>
cmp    (%r15),%eax
jne    11d0 <main+0x90>
jmp    1215 <main+0xd5>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
mov    0x8(%rbp),%rcx
lea    0xe0c(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xfffffffe,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"usage: %s [file]\0A\00"
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [28 x i8] c"%s: unable to open file %s\0A\00"
@EOF = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 -1, i32* %3
br label %55
16: ; preds = %2
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = load i32*, i32** @stdin
store i32* %20, i32** %7
br label %37
21: ; preds = %16
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %7
%26 = icmp ne i32* %25, null
br i1 %26, label %36, label %27
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %31, i8* %34)
store i32 -2, i32* %3
br label %55
36: ; preds = %21
br label %37
37: ; preds = %36, %19
br label %38
38: ; preds = %53, %37
%39 = load i32*, i32** %7
%40 = call i32 @fgetc(i32* %39)
store i32 %40, i32* %6
%41 = load i32, i32* @EOF
%42 = icmp ne i32 %40, %41
br i1 %42, label %43, label %54
43: ; preds = %38
%44 = load i32, i32* %6
%45 = icmp eq i32 %44, 10
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i32, i32* @stdout
%48 = call i32 @fputc(i32 32, i32 %47)
br label %53
49: ; preds = %43
%50 = load i32, i32* %6
%51 = load i32, i32* @stdout
%52 = call i32 @fputc(i32 %50, i32 %51)
br label %53
53: ; preds = %49, %46
br label %38
54: ; preds = %38
store i32 0, i32* %3
br label %55
55: ; preds = %54, %27, %10
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"usage: %s [file]\0A\00"
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [28 x i8] c"%s: unable to open file %s\0A\00"
@EOF = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %36
8: ; preds = %2
%9 = icmp eq i32 %0, 1
br i1 %9, label %10, label %12
10: ; preds = %8
%11 = load i32*, i32** @stdin
br label %22
12: ; preds = %8
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %1
%20 = load i8*, i8** %13
%21 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %19, i8* %20)
br label %36
22: ; preds = %12, %10
%23 = phi i32* [ %11, %10 ], [ %15, %12 ]
%24 = tail call i32 @fgetc(i32* %23)
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %36, label %27
27: ; preds = %22, %27
%28 = phi i32 [ %33, %27 ], [ %24, %22 ]
%29 = icmp eq i32 %28, 10
%30 = load i32, i32* @stdout
%31 = select i1 %29, i32 32, i32 %28
%32 = tail call i32 @fputc(i32 %31, i32 %30)
%33 = tail call i32 @fgetc(i32* %23)
%34 = load i32, i32* @EOF
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %27
36: ; preds = %27, %22, %17, %4
%37 = phi i32 [ -1, %4 ], [ -2, %17 ], [ 0, %22 ], [ 0, %27 ]
ret i32 %37
}