#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ putchar(char);
int main(int argc, char **argv) {
  FILE *fin;
  char *buf;
  if (argc != 2)
    return 1;
  buf = malloc(10);
  fin = fopen(argv[1], "r");
  if (fin) {
    while (fread(buf, 1, 1, fin)) {
      putchar(buf[0] ^ '1');
      if (!fread(buf, 1, 1, fin))
        break;
      putchar(buf[0]);
    }
    fclose(fin);
  }
  putchar('\n');
  free(buf);
  return 0;
}


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)
je     118c <main+0x2c>
movl   $0x1,-0x4(%rbp)
jmp    1249 <main+0xe9>
mov    $0xa,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe57(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     122f <main+0xcf>
jmp    11c2 <main+0x62>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1050 <fread@plt>
cmp    $0x0,%rax
je     1226 <main+0xc6>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
xor    $0x31,%eax
movsbl %al,%edi
call   1040 <putchar@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1050 <fread@plt>
cmp    $0x0,%rax
jne    1215 <main+0xb5>
jmp    1226 <main+0xc6>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1040 <putchar@plt>
jmp    11c2 <main+0x62>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
mov    $0x1,%eax
cmp    $0x2,%edi
jne    120c <main+0xac>
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    $0xa,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    0x8(%r14),%rdi
lea    0xe73(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11f1 <main+0x91>
mov    %rax,%r14
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1050 <fread@plt>
test   %rax,%rax
je     11e9 <main+0x89>
movsbl (%rbx),%edi
xor    $0x31,%edi
call   1040 <putchar@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1050 <fread@plt>
test   %rax,%rax
je     11e9 <main+0x89>
movsbl (%rbx),%edi
call   1040 <putchar@plt>
jmp    11a0 <main+0x40>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 1, i32* %3
br label %50
11: ; preds = %2
%12 = call i8* @malloc(i32 10)
store i8* %12, i8** %7
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %6
%17 = load i32*, i32** %6
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %46
19: ; preds = %11
br label %20
20: ; preds = %38, %19
%21 = load i8*, i8** %7
%22 = load i32*, i32** %6
%23 = call i64 @fread(i8* %21, i32 1, i32 1, i32* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %43
25: ; preds = %20
%26 = load i8*, i8** %7
%27 = getelementptr inbounds i8, i8* %26, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = xor i32 %29, 49
%31 = trunc i32 %30 to i8
%32 = call i32 @putchar(i8 signext %31)
%33 = load i8*, i8** %7
%34 = load i32*, i32** %6
%35 = call i64 @fread(i8* %33, i32 1, i32 1, i32* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %38, label %37
37: ; preds = %25
br label %43
38: ; preds = %25
%39 = load i8*, i8** %7
%40 = getelementptr inbounds i8, i8* %39, i64 0
%41 = load i8, i8* %40
%42 = call i32 @putchar(i8 signext %41)
br label %20
43: ; preds = %37, %20
%44 = load i32*, i32** %6
%45 = call i32 @fclose(i32* %44)
br label %46
46: ; preds = %43, %11
%47 = call i32 @putchar(i8 signext 10)
%48 = load i8*, i8** %7
%49 = call i32 @free(i8* %48)
store i32 0, i32* %3
br label %50
50: ; preds = %46, %10
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %29
4: ; preds = %2
%5 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %26, label %10
10: ; preds = %4
%11 = tail call i64 @fread(i8* %5, i32 1, i32 1, i32* %8)
%12 = icmp eq i64 %11, 0
br i1 %12, label %24, label %13
13: ; preds = %10, %19
%14 = load i8, i8* %5
%15 = xor i8 %14, 49
%16 = tail call i32 @putchar(i8 signext %15)
%17 = tail call i64 @fread(i8* %5, i32 1, i32 1, i32* %8)
%18 = icmp eq i64 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %13
%20 = load i8, i8* %5
%21 = tail call i32 @putchar(i8 signext %20)
%22 = tail call i64 @fread(i8* %5, i32 1, i32 1, i32* %8)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %13
24: ; preds = %19, %13, %10
%25 = tail call i32 @fclose(i32* %8)
br label %26
26: ; preds = %24, %4
%27 = tail call i32 @putchar(i8 signext 10)
%28 = tail call i32 @free(i8* %5)
br label %29
29: ; preds = %2, %26
%30 = phi i32 [ 0, %26 ], [ 1, %2 ]
ret i32 %30
}