#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdout;
int main(int argc, char *argv[]) {
  char ch;
  char pch;
  FILE *in, *out;
  if (argc < 2) {
    fprintf(stderr, "Missing input file.\n");
    exit(1);
  }
  in = fopen(argv[1], "r");
  if (in == NULL) {
    perror(argv[1]);
    exit(1);
  }
  if (argc == 2) {
    out = stdout;
  } else {
    out = fopen(argv[2], "w");
    if (out == NULL) {
      perror(argv[2]);
      exit(1);
    }
  }
  ch = pch = 'a';
  while ((ch = fgetc(in)) != EOF) {
    if (ch != ' ') {
      fputc(ch, out);
      pch = ch;
    } else {
      if (pch == ' ') {
        continue;
      } else {
        fputc(' ', out);
      }
      pch = ' ';
    }
  }
  fclose(in);
  fclose(out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11af <main+0x3f>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe57(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e9 <main+0x79>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpl   $0x2,-0x8(%rbp)
jne    1206 <main+0x96>
mov    0x2dd6(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    1245 <main+0xd5>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe02(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1240 <main+0xd0>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1245 <main+0xd5>
movb   $0x61,-0x12(%rbp)
movb   $0x61,-0x11(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2d85(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     12be <main+0x14e>
movsbl -0x11(%rbp),%eax
cmp    $0x20,%eax
je     1295 <main+0x125>
mov    -0x11(%rbp),%al
mov    -0x28(%rbp),%rsi
movsbl %al,%edi
call   1050 <fputc@plt>
mov    -0x11(%rbp),%al
mov    %al,-0x12(%rbp)
jmp    12b9 <main+0x149>
movsbl -0x12(%rbp),%eax
cmp    $0x20,%eax
jne    12a7 <main+0x137>
jmp    124d <main+0xdd>
mov    -0x28(%rbp),%rsi
mov    $0x20,%edi
call   1050 <fputc@plt>
movb   $0x20,-0x12(%rbp)
jmp    124d <main+0xdd>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jle    1239 <main+0xc9>
mov    %rsi,%r15
mov    %edi,%ebx
mov    0x8(%rsi),%rdi
lea    0xe85(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1258 <main+0xe8>
mov    %rax,%rbp
cmp    $0x2,%ebx
jne    11b2 <main+0x42>
mov    0x2e23(%rip),%rax
mov    (%rax),%r14
jmp    11ce <main+0x5e>
mov    0x10(%r15),%rdi
lea    0xe5a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
je     125e <main+0xee>
mov    %rbp,%rdi
call   1040 <fgetc@plt>
mov    0x2e0b(%rip),%r15
cmp    (%r15),%al
jne    11ff <main+0x8f>
mov    %rbp,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x61,%cl
jmp    122a <main+0xba>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %rbp,%rdi
call   1040 <fgetc@plt>
mov    %ebx,%ecx
cmp    (%r15),%al
je     11e2 <main+0x72>
mov    %eax,%ebx
cmp    $0x20,%al
jne    1210 <main+0xa0>
mov    $0x20,%al
cmp    $0x20,%cl
jne    1210 <main+0xa0>
jmp    121b <main+0xab>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
lea    0xdb7(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x8(%r15),%rdi
jmp    1262 <main+0xf2>
mov    0x10(%r15),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [21 x i8] c"Missing input file.\0A\00"
@.str.1 = [2 x i8] c"r\00"
@stdout = global i32* null
@.str.2 = [2 x i8] c"w\00"
@EOF = global i8 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i8
%8 = alloca i32*
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %8
%21 = load i32*, i32** %8
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %29
23: ; preds = %16
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @perror(i8* %26)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %16
%30 = load i32, i32* %4
%31 = icmp eq i32 %30, 2
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = load i32*, i32** @stdout
store i32* %33, i32** %9
br label %48
34: ; preds = %29
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %38, i32** %9
%39 = load i32*, i32** %9
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %47
41: ; preds = %34
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = call i32 @perror(i8* %44)
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %34
br label %48
48: ; preds = %47, %32
store i8 97, i8* %7
store i8 97, i8* %6
br label %49
49: ; preds = %74, %69, %48
%50 = load i32*, i32** %8
%51 = call signext i8 @fgetc(i32* %50)
store i8 %51, i8* %6
%52 = sext i8 %51 to i32
%53 = load i8, i8* @EOF
%54 = sext i8 %53 to i32
%55 = icmp ne i32 %52, %54
br i1 %55, label %56, label %75
56: ; preds = %49
%57 = load i8, i8* %6
%58 = sext i8 %57 to i32
%59 = icmp ne i32 %58, 32
br i1 %59, label %60, label %65
60: ; preds = %56
%61 = load i8, i8* %6
%62 = load i32*, i32** %9
%63 = call i32 @fputc(i8 signext %61, i32* %62)
%64 = load i8, i8* %6
store i8 %64, i8* %7
br label %74
65: ; preds = %56
%66 = load i8, i8* %7
%67 = sext i8 %66 to i32
%68 = icmp eq i32 %67, 32
br i1 %68, label %69, label %70
69: ; preds = %65
br label %49
70: ; preds = %65
%71 = load i32*, i32** %9
%72 = call i32 @fputc(i8 signext 32, i32* %71)
br label %73
73: ; preds = %70
store i8 32, i8* %7
br label %74
74: ; preds = %73, %60
br label %49
75: ; preds = %49
%76 = load i32*, i32** %8
%77 = call i32 @fclose(i32* %76)
%78 = load i32*, i32** %9
%79 = call i32 @fclose(i32* %78)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"Missing input file.\0A\00"
@.str.1 = [2 x i8] c"r\00"
@stdout = global i32* null
@.str.2 = [2 x i8] c"w\00"
@EOF = global i8 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = load i8*, i8** %9
%15 = tail call i32 @perror(i8* %14)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %8
%18 = icmp eq i32 %0, 2
br i1 %18, label %19, label %21
19: ; preds = %17
%20 = load i32*, i32** @stdout
br label %30
21: ; preds = %17
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = tail call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = load i8*, i8** %22
%28 = tail call i32 @perror(i8* %27)
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %21, %19
%31 = phi i32* [ %20, %19 ], [ %24, %21 ]
%32 = tail call signext i8 @fgetc(i32* %11)
%33 = load i8, i8* @EOF
%34 = icmp eq i8 %32, %33
br i1 %34, label %48, label %35
35: ; preds = %30, %44
%36 = phi i8 [ %45, %44 ], [ %32, %30 ]
%37 = phi i8 [ %36, %44 ], [ 97, %30 ]
%38 = icmp eq i8 %36, 32
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = icmp eq i8 %37, 32
br i1 %40, label %44, label %41
41: ; preds = %39, %35
%42 = phi i8 [ %36, %35 ], [ 32, %39 ]
%43 = tail call i32 @fputc(i8 signext %42, i32* %31)
br label %44
44: ; preds = %41, %39
%45 = tail call signext i8 @fgetc(i32* %11)
%46 = load i8, i8* @EOF
%47 = icmp eq i8 %45, %46
br i1 %47, label %48, label %35
48: ; preds = %44, %30
%49 = tail call i32 @fclose(i32* %11)
%50 = tail call i32 @fclose(i32* %31)
ret i32 0
}