#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*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
scalar_t__ rename(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  int argi;
  int num_fail = 0;
  char *input_file_name;
  char temp_file_name[256];
  FILE *input_fp;
  FILE *temp_fp;
  int c;
  if (argc < 2)
    usage(argv[0]);
  for (argi = 1; argi < argc; argi++) {
    input_file_name = argv[argi];
    sprintf(temp_file_name, "%s.__binv__", input_file_name);
    input_fp = fopen(input_file_name, "rb");
    if (input_fp == 0) {
      fprintf(stderr, "Couldn't open input file \"%s\" for read.  Exiting.\n",
              input_file_name);
      num_fail++;
      continue;
    }
    temp_fp = fopen(temp_file_name, "wb");
    if (temp_fp == 0) {
      fprintf(stderr, "Couldn't open temp file \"%s\" for write.  Exiting.\n",
              temp_file_name);
      fclose(input_fp);
      num_fail++;
      continue;
    }
    while ((c = fgetc(input_fp)) != EOF)
      fputc(~c, temp_fp);
    fclose(input_fp);
    fclose(temp_fp);
    if (!unlink(input_file_name) < 0) {
      fprintf(stderr, "Could not unlink %s", input_file_name);
      perror(": ");
      num_fail++;
      continue;
    }
    if (rename(temp_file_name, input_file_name) < 0) {
      fprintf(stderr, "Could not rename %s to %s", temp_file_name,
              input_file_name);
      perror(": ");
      num_fail++;
    }
  }
  return num_fail;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11d6 <main+0x36>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <usage@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    13ce <main+0x22e>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xdf5(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xdf1(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    125e <main+0xbe>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xdc6(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    13c0 <main+0x220>
lea    -0x120(%rbp),%rdi
lea    0xdd6(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x130(%rbp)
cmpq   $0x0,-0x130(%rbp)
jne    12be <main+0x11e>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
lea    -0x120(%rbp),%rdx
lea    0xda8(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x128(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    13c0 <main+0x220>
jmp    12c3 <main+0x123>
mov    -0x128(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x134(%rbp)
mov    0x2d0c(%rip),%rcx
cmp    (%rcx),%eax
je     12fe <main+0x15e>
mov    -0x134(%rbp),%edi
xor    $0xffffffff,%edi
mov    -0x130(%rbp),%rsi
call   1060 <fputc@plt>
jmp    12c3 <main+0x123>
mov    -0x128(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x130(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
cmp    $0x0,%eax
jge    136a <main+0x1ca>
mov    0x2c9c(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xd2f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    0xd35(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    13c0 <main+0x220>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10b0 <rename@plt>
cmp    $0x0,%rax
jge    13bb <main+0x21b>
mov    0x2c4d(%rip),%rax
mov    (%rax),%edi
lea    -0x120(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xcf0(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    0xcdf(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    13c0 <main+0x220>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11dd <main+0x3d>
mov    -0x18(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     11df <main+0x3f>
mov    (%rbx),%rdi
call   1080 <usage@plt>
movl   $0x0,0xc(%rsp)
mov    0xc(%rsp),%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %edi,%eax
mov    %rax,0x18(%rsp)
mov    $0x1,%r15d
lea    0x20(%rsp),%r13
movl   $0x0,0xc(%rsp)
mov    %rbx,0x10(%rsp)
jmp    122a <main+0x8a>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xdff(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
addl   $0x1,0xc(%rsp)
add    $0x1,%r15
cmp    0x18(%rsp),%r15
je     11c9 <main+0x29>
mov    (%rbx,%r15,8),%rbp
mov    %r13,%rdi
lea    0xdc8(%rip),%rsi
mov    %rbp,%rdx
call   10c0 <sprintf@plt>
mov    %rbp,%rdi
lea    0xdc2(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1200 <main+0x60>
mov    %rax,%r14
mov    %r13,%rdi
lea    0xde1(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1300 <main+0x160>
mov    %rax,%r12
mov    %r13,%rbx
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    0x2d64(%rip),%r13
cmp    0x0(%r13),%eax
je     12aa <main+0x10a>
nopw   0x0(%rax,%rax,1)
not    %eax
mov    %eax,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
mov    %r14,%rdi
call   1050 <fgetc@plt>
cmp    0x0(%r13),%eax
jne    1290 <main+0xf0>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %rbp,%rdi
call   1030 <unlink@plt>
mov    %rbx,%r13
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10b0 <rename@plt>
test   %rax,%rax
jns    1327 <main+0x187>
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
lea    0xd96(%rip),%rsi
mov    %r13,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xd7f(%rip),%rdi
call   10a0 <perror@plt>
jmp    1322 <main+0x182>
mov    0x2cd1(%rip),%rax
mov    (%rax),%edi
lea    0xd35(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
addl   $0x1,0xc(%rsp)
mov    0x10(%rsp),%rbx
jmp    121f <main+0x7f>

LLVM IR (-O0):
@.str = [12 x i8] c"%s.__binv__\00"
@.str.1 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.2 = [51 x i8] c"Couldn't open input file \22%s\22 for read. Exiting.\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [51 x i8] c"Couldn't open temp file \22%s\22 for write. Exiting.\0A\00"
@EOF = global i32 0
@.str.5 = [20 x i8] c"Could not unlink %s\00"
@.str.6 = [3 x i8] c": \00"
@.str.7 = [26 x i8] c"Could not rename %s to %s\00"
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*
%9 = alloca [256 x i8]
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @usage(i8* %18)
br label %20
20: ; preds = %15, %2
store i32 1, i32* %6
br label %21
21: ; preds = %100, %20
%22 = load i32, i32* %6
%23 = load i32, i32* %4
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %103
25: ; preds = %21
%26 = load i8**, i8*** %5
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
store i8* %30, i8** %8
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%32 = load i8*, i8** %8
%33 = call i32 @sprintf(i8* %31, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %32)
%34 = load i8*, i8** %8
%35 = call i32* @fopen(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %35, i32** %10
%36 = load i32*, i32** %10
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %44
38: ; preds = %25
%39 = load i32, i32* @stderr
%40 = load i8*, i8** %8
%41 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i8* %40)
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
br label %100
44: ; preds = %25
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%46 = call i32* @fopen(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %46, i32** %11
%47 = load i32*, i32** %11
%48 = icmp eq i32* %47, null
br i1 %48, label %49, label %57
49: ; preds = %44
%50 = load i32, i32* @stderr
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%52 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i8* %51)
%53 = load i32*, i32** %10
%54 = call i32 @fclose(i32* %53)
%55 = load i32, i32* %7
%56 = add nsw i32 %55, 1
store i32 %56, i32* %7
br label %100
57: ; preds = %44
br label %58
58: ; preds = %63, %57
%59 = load i32*, i32** %10
%60 = call i32 @fgetc(i32* %59)
store i32 %60, i32* %12
%61 = load i32, i32* @EOF
%62 = icmp ne i32 %60, %61
br i1 %62, label %63, label %68
63: ; preds = %58
%64 = load i32, i32* %12
%65 = xor i32 %64, -1
%66 = load i32*, i32** %11
%67 = call i32 @fputc(i32 %65, i32* %66)
br label %58
68: ; preds = %58
%69 = load i32*, i32** %10
%70 = call i32 @fclose(i32* %69)
%71 = load i32*, i32** %11
%72 = call i32 @fclose(i32* %71)
%73 = load i8*, i8** %8
%74 = call i32 @unlink(i8* %73)
%75 = icmp ne i32 %74, 0
%76 = xor i1 %75, true
%77 = zext i1 %76 to i32
%78 = icmp slt i32 %77, 0
br i1 %78, label %79, label %86
79: ; preds = %68
%80 = load i32, i32* @stderr
%81 = load i8*, i8** %8
%82 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %81)
%83 = call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%84 = load i32, i32* %7
%85 = add nsw i32 %84, 1
store i32 %85, i32* %7
br label %100
86: ; preds = %68
%87 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%88 = load i8*, i8** %8
%89 = call i64 @rename(i8* %87, i8* %88)
%90 = icmp slt i64 %89, 0
br i1 %90, label %91, label %99
91: ; preds = %86
%92 = load i32, i32* @stderr
%93 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%94 = load i8*, i8** %8
%95 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %92, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %93, i8* %94)
%96 = call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%97 = load i32, i32* %7
%98 = add nsw i32 %97, 1
store i32 %98, i32* %7
br label %99
99: ; preds = %91, %86
br label %100
100: ; preds = %99, %79, %49, %38
%101 = load i32, i32* %6
%102 = add nsw i32 %101, 1
store i32 %102, i32* %6
br label %21
103: ; preds = %21
%104 = load i32, i32* %7
ret i32 %104
}

LLVM IR (-O2):
@.str = [12 x i8] c"%s.__binv__\00"
@.str.1 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.2 = [51 x i8] c"Couldn't open input file \22%s\22 for read. Exiting.\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [51 x i8] c"Couldn't open temp file \22%s\22 for write. Exiting.\0A\00"
@EOF = global i32 0
@.str.6 = [3 x i8] c": \00"
@.str.7 = [26 x i8] c"Could not rename %s to %s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @usage(i8* %7)
br label %57
9: ; preds = %2
%10 = zext i32 %0 to i64
br label %11
11: ; preds = %9, %53
%12 = phi i64 [ 1, %9 ], [ %55, %53 ]
%13 = phi i32 [ 0, %9 ], [ %54, %53 ]
%14 = getelementptr inbounds i8*, i8** %1, i64 %12
%15 = load i8*, i8** %14
%16 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %23
19: ; preds = %11
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%22 = add nsw i32 %13, 1
br label %53
23: ; preds = %11
%24 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %30, label %26
26: ; preds = %23
%27 = call i32 @fgetc(i32* %17)
%28 = load i32, i32* @EOF
%29 = icmp eq i32 %27, %28
br i1 %29, label %42, label %35
30: ; preds = %23
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%33 = call i32 @fclose(i32* %17)
%34 = add nsw i32 %13, 1
br label %53
35: ; preds = %26, %35
%36 = phi i32 [ %39, %35 ], [ %27, %26 ]
%37 = xor i32 %36, -1
%38 = call i32 @fputc(i32 %37, i32* %24)
%39 = call i32 @fgetc(i32* %17)
%40 = load i32, i32* @EOF
%41 = icmp eq i32 %39, %40
br i1 %41, label %42, label %35
42: ; preds = %35, %26
%43 = call i32 @fclose(i32* %17)
%44 = call i32 @fclose(i32* %24)
%45 = call i32 @unlink(i8* %15)
%46 = call i64 @rename(i8* %4, i8* %15)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %53
48: ; preds = %42
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %4, i8* %15)
%51 = call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%52 = add nsw i32 %13, 1
br label %53
53: ; preds = %42, %48, %30, %19
%54 = phi i32 [ %22, %19 ], [ %34, %30 ], [ %52, %48 ], [ %13, %42 ]
%55 = add nuw nsw i64 %12, 1
%56 = icmp eq i64 %55, %10
br i1 %56, label %57, label %11
57: ; preds = %53, %6
%58 = phi i32 [ 0, %6 ], [ %54, %53 ]
ret i32 %58
}