#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 /*<<< orphan*/ exit(int);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("Usage: invert <infile>");
    printf("\nOutput will be sent to stdout");
    printf("\nTo use stdin as input, use - as the infile\n");
    exit(1);
  }
  FILE *input = stdin;
  if (argv[1][0] != '-') {
    input = fopen(argv[1], "rb");
    if (input == 0) {
      printf("Could not open provided infile");
      exit(1);
    }
  }
  while (1) {
    int in = fgetc(input);
    if (in == EOF) {
      exit(0);
    }
    char enc = in ^ 0xFF;
    fputc(enc, stdout);
  }
}


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)
jge    119e <main+0x4e>
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
lea    0xea7(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     11fe <main+0xae>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe94(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f9 <main+0xa9>
lea    0xe7c(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11fe <main+0xae>
jmp    1203 <main+0xb3>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2dc7(%rip),%rcx
cmp    (%rcx),%eax
jne    1228 <main+0xd8>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x1c(%rbp),%eax
xor    $0xff,%eax
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
mov    0x2d93(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1050 <fputc@plt>
jmp    1203 <main+0xb3>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x1,%edi
jg     1198 <main+0x38>
lea    0xe8f(%rip),%rdi
call   1040 <printf@plt>
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
lea    0xecf(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x8(%rsi),%rdi
cmpb   $0x2d,(%rdi)
jne    11ad <main+0x4d>
mov    0x2e40(%rip),%rax
mov    (%rax),%rbx
jmp    11d7 <main+0x77>
lea    0xe82(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11d7 <main+0x77>
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    0x2dfa(%rip),%r14
cmp    (%r14),%eax
je     121a <main+0xba>
mov    0x2dde(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
not    %al
mov    (%r15),%esi
movsbl %al,%edi
call   1060 <fputc@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r14),%eax
jne    1200 <main+0xa0>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"Usage: invert <infile>\00"
@.str.1 = [31 x i8] c"\0AOutput will be sent to stdout\00"
@.str.2 = [45 x i8] c"\0ATo use stdin as input, use - as the infile\0A\00"
@stdin = global i32* null
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [31 x i8] c"Could not open provided infile\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
%8 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i32*, i32** @stdin
store i32* %17, i32** %6
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 45
br i1 %24, label %25, label %36
25: ; preds = %16
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %29, i32** %6
%30 = load i32*, i32** %6
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %35
32: ; preds = %25
%33 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %25
br label %36
36: ; preds = %35, %16
br label %37
37: ; preds = %36, %45
%38 = load i32*, i32** %6
%39 = call i32 @fgetc(i32* %38)
store i32 %39, i32* %7
%40 = load i32, i32* %7
%41 = load i32, i32* @EOF
%42 = icmp eq i32 %40, %41
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = call i32 @exit(i32 0)
unreachable
45: ; preds = %37
%46 = load i32, i32* %7
%47 = xor i32 %46, 255
%48 = trunc i32 %47 to i8
store i8 %48, i8* %8
%49 = load i8, i8* %8
%50 = load i32, i32* @stdout
%51 = call i32 @fputc(i8 signext %49, i32 %50)
br label %37
}

LLVM IR (-O2):
@.str = [23 x i8] c"Usage: invert <infile>\00"
@.str.1 = [31 x i8] c"\0AOutput will be sent to stdout\00"
@stdin = global i32* null
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [31 x i8] c"Could not open provided infile\00"
@EOF = global i32 0
@stdout = global i32 0
@str = [44 x i8] c"\0ATo use stdin as input, use - as the infile\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = load i32*, i32** @stdin
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 45
br i1 %14, label %21, label %15
15: ; preds = %9
%16 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %15, %9
%22 = phi i32* [ %16, %15 ], [ %10, %9 ]
%23 = tail call i32 @fgetc(i32* %22)
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %28, %21
%27 = tail call i32 @exit(i32 0)
unreachable
28: ; preds = %21, %28
%29 = phi i32 [ %34, %28 ], [ %23, %21 ]
%30 = trunc i32 %29 to i8
%31 = xor i8 %30, -1
%32 = load i32, i32* @stdout
%33 = tail call i32 @fputc(i8 signext %31, i32 %32)
%34 = tail call i32 @fgetc(i32* %22)
%35 = load i32, i32* @EOF
%36 = icmp eq i32 %34, %35
br i1 %36, label %26, label %28
}