#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 /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fread(unsigned char **, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(unsigned char **, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *file;
  unsigned char buf[256][4];
  int i;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s dir.ff\n", argv[0]);
    exit(1);
  }
  file = fopen(argv[1], "r+b");
  fseek(file, 54, SEEK_SET);
  fread(buf, 4, 256, file);
  for (i = 0; i < 256; i++) {
    int j;
    for (j = 0; j < 4; j++) {
      buf[i][j] = 255 - buf[i][j];
    }
  }
  fseek(file, 54, SEEK_SET);
  fwrite(buf, 4, 256, file);
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b9 <main+0x49>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe56(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2dfc(%rip),%rax
mov    (%rax),%edx
mov    $0x36,%esi
call   1060 <fseek@plt>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x4,%esi
mov    $0x100,%edx
call   1030 <fread@plt>
movl   $0x0,-0x424(%rbp)
cmpl   $0x100,-0x424(%rbp)
jge    12a8 <main+0x138>
movl   $0x0,-0x428(%rbp)
cmpl   $0x4,-0x428(%rbp)
jge    128f <main+0x11f>
movslq -0x424(%rbp),%rcx
lea    -0x420(%rbp),%rax
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x428(%rbp),%rcx
movzbl (%rax,%rcx,1),%ecx
mov    $0xff,%eax
sub    %ecx,%eax
mov    %al,%dl
movslq -0x424(%rbp),%rcx
lea    -0x420(%rbp),%rax
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x428(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x428(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x428(%rbp)
jmp    1226 <main+0xb6>
jmp    1294 <main+0x124>
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
jmp    120c <main+0x9c>
mov    -0x18(%rbp),%rdi
mov    0x2d25(%rip),%rax
mov    (%rax),%edx
mov    $0x36,%esi
call   1060 <fseek@plt>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x4,%esi
mov    $0x100,%edx
call   1090 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x408,%rsp
cmp    $0x2,%edi
jne    1225 <main+0xb5>
mov    0x8(%rsi),%rdi
lea    0xe84(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    0x2e3b(%rip),%r14
mov    (%r14),%edx
mov    %rax,%rdi
mov    $0x36,%esi
call   1060 <fseek@plt>
mov    %rsp,%rdi
mov    $0x4,%esi
mov    $0x100,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
notb   (%rsp,%rax,4)
notb   0x1(%rsp,%rax,4)
notb   0x2(%rsp,%rax,4)
notb   0x3(%rsp,%rax,4)
add    $0x1,%rax
cmp    $0x100,%rax
jne    11d0 <main+0x60>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x36,%esi
call   1060 <fseek@plt>
mov    %rsp,%rdi
mov    $0x4,%esi
mov    $0x100,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xdc8(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s dir.ff\0A\00"
@.str.1 = [4 x i8] c"r+b\00"
@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 [256 x [4 x 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 ne i32 %10, 2
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %6
%24 = load i32*, i32** %6
%25 = load i32, i32* @SEEK_SET
%26 = call i32 @fseek(i32* %24, i32 54, i32 %25)
%27 = getelementptr inbounds [256 x [4 x i8]], [256 x [4 x i8]]* %7, i64 0, i64 0
%28 = bitcast [4 x i8]* %27 to i8**
%29 = load i32*, i32** %6
%30 = call i32 @fread(i8** %28, i32 4, i32 256, i32* %29)
store i32 0, i32* %8
br label %31
31: ; preds = %59, %19
%32 = load i32, i32* %8
%33 = icmp slt i32 %32, 256
br i1 %33, label %34, label %62
34: ; preds = %31
store i32 0, i32* %9
br label %35
35: ; preds = %55, %34
%36 = load i32, i32* %9
%37 = icmp slt i32 %36, 4
br i1 %37, label %38, label %58
38: ; preds = %35
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [256 x [4 x i8]], [256 x [4 x i8]]* %7, i64 0, i64 %40
%42 = load i32, i32* %9
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [4 x i8], [4 x i8]* %41, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = sub nsw i32 255, %46
%48 = trunc i32 %47 to i8
%49 = load i32, i32* %8
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [256 x [4 x i8]], [256 x [4 x i8]]* %7, i64 0, i64 %50
%52 = load i32, i32* %9
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [4 x i8], [4 x i8]* %51, i64 0, i64 %53
store i8 %48, i8* %54
br label %55
55: ; preds = %38
%56 = load i32, i32* %9
%57 = add nsw i32 %56, 1
store i32 %57, i32* %9
br label %35
58: ; preds = %35
br label %59
59: ; preds = %58
%60 = load i32, i32* %8
%61 = add nsw i32 %60, 1
store i32 %61, i32* %8
br label %31
62: ; preds = %31
%63 = load i32*, i32** %6
%64 = load i32, i32* @SEEK_SET
%65 = call i32 @fseek(i32* %63, i32 54, i32 %64)
%66 = getelementptr inbounds [256 x [4 x i8]], [256 x [4 x i8]]* %7, i64 0, i64 0
%67 = bitcast [4 x i8]* %66 to i8**
%68 = load i32*, i32** %6
%69 = call i32 @fwrite(i8** %67, i32 4, i32 256, i32* %68)
%70 = load i32*, i32** %6
%71 = call i32 @fclose(i32* %70)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s dir.ff\0A\00"
@.str.1 = [4 x i8] c"r+b\00"
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x [4 x i8]]
%4 = getelementptr inbounds [256 x [4 x i8]], [256 x [4 x i8]]* %3, i64 0, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @SEEK_SET
%16 = tail call i32 @fseek(i32* %14, i32 54, i32 %15)
%17 = bitcast [256 x [4 x i8]]* %3 to i8**
%18 = call i32 @fread(i8** %17, i32 4, i32 256, i32* %14)
br label %19
19: ; preds = %11, %19
%20 = phi i64 [ 0, %11 ], [ %33, %19 ]
%21 = getelementptr inbounds [256 x [4 x i8]], [256 x [4 x i8]]* %3, i64 0, i64 %20, i64 0
%22 = load i8, i8* %21
%23 = xor i8 %22, -1
store i8 %23, i8* %21
%24 = getelementptr inbounds [256 x [4 x i8]], [256 x [4 x i8]]* %3, i64 0, i64 %20, i64 1
%25 = load i8, i8* %24
%26 = xor i8 %25, -1
store i8 %26, i8* %24
%27 = getelementptr inbounds [256 x [4 x i8]], [256 x [4 x i8]]* %3, i64 0, i64 %20, i64 2
%28 = load i8, i8* %27
%29 = xor i8 %28, -1
store i8 %29, i8* %27
%30 = getelementptr inbounds [256 x [4 x i8]], [256 x [4 x i8]]* %3, i64 0, i64 %20, i64 3
%31 = load i8, i8* %30
%32 = xor i8 %31, -1
store i8 %32, i8* %30
%33 = add nuw nsw i64 %20, 1
%34 = icmp eq i64 %33, 256
br i1 %34, label %35, label %19
35: ; preds = %19
%36 = load i32, i32* @SEEK_SET
%37 = tail call i32 @fseek(i32* %14, i32 54, i32 %36)
%38 = call i32 @fwrite(i8** %17, i32 4, i32 256, i32* %14)
%39 = tail call i32 @fclose(i32* %14)
ret i32 0
}