#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int getc(int /*<<< orphan*/ *const);
int putc_unlocked(int, int /*<<< orphan*/);
int scramble_char(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int scramble_stream(FILE *const stream) {
  size_t n_chars;
  int c;
  for (n_chars = 0;; n_chars++) {
    c = getc(stream);
    if (c == EOF)
      break;
    c = scramble_char(c);
    if (c != putc_unlocked(c, stdout)) {
      fprintf(stderr, "Failed writing to standard output\n");
      return -1;
    }
  }
  fprintf(stderr, "Read %zu characters\n", n_chars);
  return 0;
}


x86 assembly (clang, -O0):
<scramble_stream>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <getc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e7e(%rip),%rcx
cmp    (%rcx),%eax
jne    1177 <scramble_stream+0x37>
jmp    11df <scramble_stream+0x9f>
mov    -0x1c(%rbp),%edi
call   1030 <scramble_char@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
call   1050 <putc_unlocked@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
je     11c9 <scramble_stream+0x89>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1201 <scramble_stream+0xc1>
jmp    11ce <scramble_stream+0x8e>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1154 <scramble_stream+0x14>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe30(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scramble_stream>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1060 <getc@plt>
mov    0x2e8e(%rip),%r12
xor    %r14d,%r14d
cmp    (%r12),%eax
jne    1167 <scramble_stream+0x27>
xor    %ebx,%ebx
jmp    119a <scramble_stream+0x5a>
xor    %ebx,%ebx
mov    0x2e60(%rip),%r13
mov    %eax,%edi
call   1030 <scramble_char@plt>
mov    %eax,%ebp
mov    0x0(%r13),%esi
mov    %eax,%edi
call   1050 <putc_unlocked@plt>
cmp    %eax,%ebp
jne    11b6 <scramble_stream+0x76>
add    $0x1,%rbx
mov    %r15,%rdi
call   1060 <getc@plt>
cmp    (%r12),%eax
jne    1170 <scramble_stream+0x30>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe79(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11d3 <scramble_stream+0x93>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@stdout = global i32 0
@stderr = global i32 0
@.str = [35 x i8] c"Failed writing to standard output\0A\00"
@.str.1 = [21 x i8] c"Read %zu characters\0A\00"
define i32 @scramble_stream(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32
store i32* %0, i32** %3
store i64 0, i64* %4
br label %6
6: ; preds = %25, %1
%7 = load i32*, i32** %3
%8 = call i32 @getc(i32* %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %13
12: ; preds = %6
br label %28
13: ; preds = %6
%14 = load i32, i32* %5
%15 = call i32 @scramble_char(i32 %14)
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = load i32, i32* %5
%18 = load i32, i32* @stdout
%19 = call i32 @putc_unlocked(i32 %17, i32 %18)
%20 = icmp ne i32 %16, %19
br i1 %20, label %21, label %24
21: ; preds = %13
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %32
24: ; preds = %13
br label %25
25: ; preds = %24
%26 = load i64, i64* %4
%27 = add i64 %26, 1
store i64 %27, i64* %4
br label %6
28: ; preds = %12
%29 = load i32, i32* @stderr
%30 = load i64, i64* %4
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i64 %30)
store i32 0, i32* %2
br label %32
32: ; preds = %28, %21
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
@EOF = global i32 0
@stdout = global i32 0
@stderr = global i32 0
@.str = [35 x i8] c"Failed writing to standard output\0A\00"
@.str.1 = [21 x i8] c"Read %zu characters\0A\00"
define i32 @scramble_stream(i32* nocapture %0) {
%2 = tail call i32 @getc(i32* %0)
%3 = load i32, i32* @EOF
%4 = icmp eq i32 %2, %3
br i1 %4, label %20, label %5
5: ; preds = %1, %15
%6 = phi i32 [ %17, %15 ], [ %2, %1 ]
%7 = phi i64 [ %16, %15 ], [ 0, %1 ]
%8 = tail call i32 @scramble_char(i32 %6)
%9 = load i32, i32* @stdout
%10 = tail call i32 @putc_unlocked(i32 %8, i32 %9)
%11 = icmp eq i32 %8, %10
br i1 %11, label %15, label %12
12: ; preds = %5
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %24
15: ; preds = %5
%16 = add i64 %7, 1
%17 = tail call i32 @getc(i32* %0)
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %5
20: ; preds = %15, %1
%21 = phi i64 [ 0, %1 ], [ %16, %15 ]
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i64 %21)
br label %24
24: ; preds = %20, %12
%25 = phi i32 [ 0, %20 ], [ -1, %12 ]
ret i32 %25
}