#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*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf("Usage: %s <file>\n", argv[0]);
    exit(1);
  }
  FILE *fp;
  if ((fp = fopen(argv[1], "r+")) == NULL) {
    printf("Unable to open \"%s\"\n", argv[1]);
    exit(1);
  }
  char ch;
  char flip;
  long int location;
  while ((ch = getc(fp)) != EOF) {
    location = ftell(fp);
    location--;
    fseek(fp, location, SEEK_SET);
    flip = ~ch;
    putc(flip, fp);
  }
}


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)
je     11ad <main+0x3d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe56(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11ed <main+0x7d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe37(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11f2 <main+0x82>
mov    -0x18(%rbp),%rdi
call   1090 <getc@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%eax
mov    0x2de0(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1260 <main+0xf0>
mov    -0x18(%rbp),%rdi
call   1050 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    0x2d9d(%rip),%rax
mov    (%rax),%edx
call   1060 <fseek@plt>
movsbl -0x19(%rbp),%eax
xor    $0xffffffff,%eax
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1040 <putc@plt>
jmp    11f2 <main+0x82>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1202 <main+0x92>
mov    0x8(%rbx),%rdi
lea    0xe83(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     120e <main+0x9e>
mov    %rax,%r14
mov    %rax,%rdi
call   1090 <getc@plt>
mov    0x2e3d(%rip),%r15
cmp    (%r15),%al
je     11f4 <main+0x84>
mov    %eax,%ebx
mov    0x2e1f(%rip),%r12
nopl   0x0(%rax)
mov    %r14,%rdi
call   1050 <ftell@plt>
lea    -0x1(%rax),%rsi
mov    (%r12),%edx
mov    %r14,%rdi
call   1060 <fseek@plt>
not    %bl
movsbl %bl,%edi
mov    %r14,%rsi
call   1040 <putc@plt>
mov    %r14,%rdi
call   1090 <getc@plt>
mov    %eax,%ebx
cmp    (%r15),%al
jne    11c0 <main+0x50>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    (%rbx),%rsi
lea    0xdf4(%rip),%rdi
jmp    1219 <main+0xa9>
mov    0x8(%rbx),%rsi
lea    0xdfc(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"Usage: %s <file>\0A\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [21 x i8] c"Unable to open \22%s\22\0A\00"
@EOF = global i8 0
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8
%8 = alloca i8
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %6
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %30
24: ; preds = %18
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %18
br label %31
31: ; preds = %38, %30
%32 = load i32*, i32** %6
%33 = call signext i8 @getc(i32* %32)
store i8 %33, i8* %7
%34 = sext i8 %33 to i32
%35 = load i8, i8* @EOF
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %34, %36
br i1 %37, label %38, label %54
38: ; preds = %31
%39 = load i32*, i32** %6
%40 = call i64 @ftell(i32* %39)
store i64 %40, i64* %9
%41 = load i64, i64* %9
%42 = add nsw i64 %41, -1
store i64 %42, i64* %9
%43 = load i32*, i32** %6
%44 = load i64, i64* %9
%45 = load i32, i32* @SEEK_SET
%46 = call i32 @fseek(i32* %43, i64 %44, i32 %45)
%47 = load i8, i8* %7
%48 = sext i8 %47 to i32
%49 = xor i32 %48, -1
%50 = trunc i32 %49 to i8
store i8 %50, i8* %8
%51 = load i8, i8* %8
%52 = load i32*, i32** %6
%53 = call i32 @putc(i8 signext %51, i32* %52)
br label %31
54: ; preds = %31
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str = [18 x i8] c"Usage: %s <file>\0A\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [21 x i8] c"Unable to open \22%s\22\0A\00"
@EOF = global i8 0
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %5)
%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 ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %17, label %13
13: ; preds = %8
%14 = tail call signext i8 @getc(i32* %11)
%15 = load i8, i8* @EOF
%16 = icmp eq i8 %14, %15
br i1 %16, label %32, label %21
17: ; preds = %8
%18 = load i8*, i8** %9
%19 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %13, %21
%22 = phi i8 [ %29, %21 ], [ %14, %13 ]
%23 = tail call i64 @ftell(i32* %11)
%24 = add nsw i64 %23, -1
%25 = load i32, i32* @SEEK_SET
%26 = tail call i32 @fseek(i32* %11, i64 %24, i32 %25)
%27 = xor i8 %22, -1
%28 = tail call i32 @putc(i8 signext %27, i32* %11)
%29 = tail call signext i8 @getc(i32* %11)
%30 = load i8, i8* @EOF
%31 = icmp eq i8 %29, %30
br i1 %31, label %32, label %21
32: ; preds = %21, %13
ret i32 0
}