#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_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  FILE *infile, *outfile;
  char outfn[256], buf, key;
  int len;
  if (argc != 2)
    return 1;
  infile = fopen(argv[1], "rb");
  if (!infile)
    return 2;
  strcpy(outfn, argv[1]);
  strcat(outfn, ".txt");
  outfile = fopen(outfn, "wb");
  if (!outfile)
    return 3;
  fseek(infile, 0, SEEK_END);
  len = ftell(infile);
  fseek(infile, len / 2, SEEK_SET);
  fread(&key, 1, 1, infile);
  fseek(infile, 0, SEEK_SET);
  while (fread(&buf, 1, 1, infile) > 0) {
    if (buf != key)
      buf -= key;
    fwrite(&buf, 1, 1, outfile);
  }
  fclose(infile);
  fclose(outfile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11af <main+0x2f>
movl   $0x1,-0x4(%rbp)
jmp    1325 <main+0x1a5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe42(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11de <main+0x5e>
movl   $0x2,-0x4(%rbp)
jmp    1325 <main+0x1a5>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
lea    -0x120(%rbp),%rdi
lea    0xe03(%rip),%rsi
call   1090 <strcat@plt>
lea    -0x120(%rbp),%rdi
lea    0xdf5(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1233 <main+0xb3>
movl   $0x3,-0x4(%rbp)
jmp    1325 <main+0x1a5>
mov    -0x18(%rbp),%rdi
mov    0x2daa(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0x128(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x128(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    0x2d67(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
mov    -0x18(%rbp),%rcx
lea    -0x122(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d3e(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x18(%rbp),%rcx
lea    -0x121(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
cmp    $0x0,%rax
jle    130c <main+0x18c>
movsbl -0x121(%rbp),%eax
movsbl -0x122(%rbp),%ecx
cmp    %ecx,%eax
je     12f0 <main+0x170>
movsbl -0x122(%rbp),%ecx
movsbl -0x121(%rbp),%eax
sub    %ecx,%eax
mov    %al,-0x121(%rbp)
mov    -0x20(%rbp),%rcx
lea    -0x121(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   10a0 <fwrite@plt>
jmp    12a3 <main+0x123>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x110,%rsp
mov    $0x1,%r14d
cmp    $0x2,%edi
jne    12d8 <main+0x158>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe54(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12ca <main+0x14a>
mov    %rax,%rbp
mov    0x8(%rbx),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe2e(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
lea    0xe24(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     12d2 <main+0x152>
mov    %rax,%r12
mov    0x2de9(%rip),%rax
mov    (%rax),%edx
xor    %r14d,%r14d
mov    %rbp,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbp,%rdi
call   1070 <ftell@plt>
mov    %eax,%esi
shr    $0x1f,%esi
add    %eax,%esi
sar    %esi
mov    0x2db2(%rip),%rbx
mov    (%rbx),%edx
mov    %rbp,%rdi
call   1080 <fseek@plt>
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1040 <fread@plt>
mov    (%rbx),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
lea    0xe(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1040 <fread@plt>
test   %rax,%rax
jle    12b8 <main+0x138>
mov    0xf(%rsp),%bl
lea    0xe(%rsp),%r15
jmp    12a5 <main+0x125>
nopw   0x0(%rax,%rax,1)
movsbl %cl,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1040 <fread@plt>
test   %rax,%rax
jle    12b8 <main+0x138>
movzbl 0xe(%rsp),%eax
mov    %ebx,%ecx
sub    %bl,%al
je     1280 <main+0x100>
mov    %al,0xe(%rsp)
mov    %eax,%ecx
jmp    1280 <main+0x100>
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
jmp    12d8 <main+0x158>
mov    $0x2,%r14d
jmp    12d8 <main+0x158>
mov    $0x3,%r14d
mov    %r14d,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [5 x i8] c".txt\00"
@.str.2 = [3 x i8] c"wb\00"
@SEEK_END = global i32 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 i32*
%8 = alloca [256 x i8]
%9 = alloca i8
%10 = alloca i8
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 1, i32* %3
br label %77
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = icmp ne i32* %20, null
br i1 %21, label %23, label %22
22: ; preds = %15
store i32 2, i32* %3
br label %77
23: ; preds = %15
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @strcpy(i8* %24, i8* %27)
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%30 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %32, i32** %7
%33 = load i32*, i32** %7
%34 = icmp ne i32* %33, null
br i1 %34, label %36, label %35
35: ; preds = %23
store i32 3, i32* %3
br label %77
36: ; preds = %23
%37 = load i32*, i32** %6
%38 = load i32, i32* @SEEK_END
%39 = call i32 @fseek(i32* %37, i32 0, i32 %38)
%40 = load i32*, i32** %6
%41 = call i32 @ftell(i32* %40)
store i32 %41, i32* %11
%42 = load i32*, i32** %6
%43 = load i32, i32* %11
%44 = sdiv i32 %43, 2
%45 = load i32, i32* @SEEK_SET
%46 = call i32 @fseek(i32* %42, i32 %44, i32 %45)
%47 = load i32*, i32** %6
%48 = call i64 @fread(i8* %10, i32 1, i32 1, i32* %47)
%49 = load i32*, i32** %6
%50 = load i32, i32* @SEEK_SET
%51 = call i32 @fseek(i32* %49, i32 0, i32 %50)
br label %52
52: ; preds = %69, %36
%53 = load i32*, i32** %6
%54 = call i64 @fread(i8* %9, i32 1, i32 1, i32* %53)
%55 = icmp sgt i64 %54, 0
br i1 %55, label %56, label %72
56: ; preds = %52
%57 = load i8, i8* %9
%58 = sext i8 %57 to i32
%59 = load i8, i8* %10
%60 = sext i8 %59 to i32
%61 = icmp ne i32 %58, %60
br i1 %61, label %62, label %69
62: ; preds = %56
%63 = load i8, i8* %10
%64 = sext i8 %63 to i32
%65 = load i8, i8* %9
%66 = sext i8 %65 to i32
%67 = sub nsw i32 %66, %64
%68 = trunc i32 %67 to i8
store i8 %68, i8* %9
br label %69
69: ; preds = %62, %56
%70 = load i32*, i32** %7
%71 = call i32 @fwrite(i8* %9, i32 1, i32 1, i32* %70)
br label %52
72: ; preds = %52
%73 = load i32*, i32** %6
%74 = call i32 @fclose(i32* %73)
%75 = load i32*, i32** %7
%76 = call i32 @fclose(i32* %75)
store i32 0, i32* %3
br label %77
77: ; preds = %72, %35, %22, %14
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [5 x i8] c".txt\00"
@.str.2 = [3 x i8] c"wb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca i8
%5 = alloca i8
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = icmp eq i32 %0, 2
br i1 %7, label %8, label %47
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, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %47, label %13
13: ; preds = %8
%14 = load i8*, i8** %9
%15 = call i32 @strcpy(i8* %6, i8* %14)
%16 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %47, label %19
19: ; preds = %13
%20 = load i32, i32* @SEEK_END
%21 = call i32 @fseek(i32* %11, i32 0, i32 %20)
%22 = call i32 @ftell(i32* %11)
%23 = sdiv i32 %22, 2
%24 = load i32, i32* @SEEK_SET
%25 = call i32 @fseek(i32* %11, i32 %23, i32 %24)
%26 = call i64 @fread(i8* %5, i32 1, i32 1, i32* %11)
%27 = load i32, i32* @SEEK_SET
%28 = call i32 @fseek(i32* %11, i32 0, i32 %27)
%29 = call i64 @fread(i8* %4, i32 1, i32 1, i32* %11)
%30 = icmp sgt i64 %29, 0
br i1 %30, label %31, label %44
31: ; preds = %19
%32 = load i8, i8* %5
br label %33
33: ; preds = %31, %38
%34 = load i8, i8* %4
%35 = icmp eq i8 %34, %32
br i1 %35, label %38, label %36
36: ; preds = %33
%37 = sub i8 %34, %32
store i8 %37, i8* %4
br label %38
38: ; preds = %36, %33
%39 = phi i8 [ %37, %36 ], [ %32, %33 ]
%40 = sext i8 %39 to i32
%41 = call i32 @fputc(i32 %40, i32* %17)
%42 = call i64 @fread(i8* %4, i32 1, i32 1, i32* %11)
%43 = icmp sgt i64 %42, 0
br i1 %43, label %33, label %44
44: ; preds = %38, %19
%45 = call i32 @fclose(i32* %11)
%46 = call i32 @fclose(i32* %17)
br label %47
47: ; preds = %13, %8, %2, %44
%48 = phi i32 [ 0, %44 ], [ 1, %2 ], [ 2, %8 ], [ 3, %13 ]
ret i32 %48
}