#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 backscan(char *, int, char);
int ctrlmask(char *, char *, int);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, char, int);
void scr2str(FILE *in, FILE *out) {
  char block[0x400];
  char line[0x40 * 2];
  int n, i, k;
  do {
    memset(block, ' ', 0x400);
    n = fread(block, 1, 0x400, in);
    if (n == 0)
      break;
    n = backscan(block, n, ' ');
    for (i = 0; i < n; i += 0x40) {
      k = backscan(block + i, 0x40, ' ');
      k = ctrlmask(block + i, line, k);
      fwrite(line, 1, k, out);
      fwrite("\n", 1, 1, out);
    }
    fwrite("\f\n", 2, 1, out);
  } while (1);
}


x86 assembly (clang, -O0):
<scr2str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4a0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
mov    $0x20,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    %eax,-0x494(%rbp)
cmpl   $0x0,-0x494(%rbp)
jne    11ab <scr2str+0x5b>
jmp    12a2 <scr2str+0x152>
lea    -0x410(%rbp),%rdi
mov    -0x494(%rbp),%esi
mov    $0x20,%edx
call   1060 <backscan@plt>
mov    %eax,-0x494(%rbp)
movl   $0x0,-0x498(%rbp)
mov    -0x498(%rbp),%eax
cmp    -0x494(%rbp),%eax
jge    1279 <scr2str+0x129>
lea    -0x410(%rbp),%rdi
movslq -0x498(%rbp),%rax
add    %rax,%rdi
mov    $0x40,%esi
mov    $0x20,%edx
call   1060 <backscan@plt>
mov    %eax,-0x49c(%rbp)
lea    -0x410(%rbp),%rdi
movslq -0x498(%rbp),%rax
add    %rax,%rdi
lea    -0x490(%rbp),%rsi
mov    -0x49c(%rbp),%edx
call   1050 <ctrlmask@plt>
mov    %eax,-0x49c(%rbp)
lea    -0x490(%rbp),%rdi
mov    -0x49c(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
mov    -0x10(%rbp),%rcx
lea    0xda8(%rip),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1070 <fwrite@plt>
mov    -0x498(%rbp),%eax
add    $0x40,%eax
mov    %eax,-0x498(%rbp)
jmp    11d2 <scr2str+0x82>
mov    -0x10(%rbp),%rcx
lea    0xd7c(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    $0x1,%al
test   $0x1,%al
jne    1163 <scr2str+0x13>
jmp    12a2 <scr2str+0x152>
add    $0x4a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scr2str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x498,%rsp
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0x90(%rsp),%r14
mov    %r14,%rdi
mov    $0x20,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rbp,0x8(%rsp)
mov    %rbp,%rcx
call   1030 <fread@plt>
test   %eax,%eax
je     1287 <scr2str+0x127>
lea    0x90(%rsp),%r15
lea    0x10(%rsp),%r12
jmp    1216 <scr2str+0xb6>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xe29(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    %r15,%rdi
mov    $0x20,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    0x8(%rsp),%rcx
call   1030 <fread@plt>
test   %eax,%eax
je     1287 <scr2str+0x127>
mov    %r15,%rdi
mov    %eax,%esi
mov    $0x20,%edx
call   1070 <backscan@plt>
test   %eax,%eax
jle    11d0 <scr2str+0x70>
mov    %eax,%ebp
xor    %r14d,%r14d
xchg   %ax,%ax
lea    (%rsp,%r14,1),%r13
add    $0x90,%r13
mov    %r13,%rdi
mov    $0x40,%esi
mov    $0x20,%edx
call   1070 <backscan@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1060 <ctrlmask@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
add    $0x40,%r14
cmp    %r14d,%ebp
jg     1230 <scr2str+0xd0>
jmp    11d0 <scr2str+0x70>
add    $0x498,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [3 x i8] c"\0C\0A\00"
define void @scr2str(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [1024 x i8]
%6 = alloca [128 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
br label %10
10: ; preds = %52, %2
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i8 signext 32, i32 1024)
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%14 = load i32*, i32** %3
%15 = call i32 @fread(i8* %13, i32 1, i32 1024, i32* %14)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %10
br label %53
19: ; preds = %10
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%21 = load i32, i32* %7
%22 = call i32 @backscan(i8* %20, i32 %21, i8 signext 32)
store i32 %22, i32* %7
store i32 0, i32* %8
br label %23
23: ; preds = %46, %19
%24 = load i32, i32* %8
%25 = load i32, i32* %7
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %49
27: ; preds = %23
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = call i32 @backscan(i8* %31, i32 64, i8 signext 32)
store i32 %32, i32* %9
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%38 = load i32, i32* %9
%39 = call i32 @ctrlmask(i8* %36, i8* %37, i32 %38)
store i32 %39, i32* %9
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%41 = load i32, i32* %9
%42 = load i32*, i32** %4
%43 = call i32 @fwrite(i8* %40, i32 1, i32 %41, i32* %42)
%44 = load i32*, i32** %4
%45 = call i32 @fwrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1, i32 1, i32* %44)
br label %46
46: ; preds = %27
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 64
store i32 %48, i32* %8
br label %23
49: ; preds = %23
%50 = load i32*, i32** %4
%51 = call i32 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 1, i32* %50)
br label %52
52: ; preds = %49
br i1 true, label %10, label %53
53: ; preds = %52, %18
ret void
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"\0C\0A\00"
define void @scr2str(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = call i32 @memset(i8* %5, i8 signext 32, i32 1024)
%8 = call i32 @fread(i8* %5, i32 1, i32 1024, i32* %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %29, label %10
10: ; preds = %2, %24
%11 = phi i32 [ %27, %24 ], [ %8, %2 ]
%12 = call i32 @backscan(i8* %5, i32 %11, i8 signext 32)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %10, %14
%15 = phi i64 [ %21, %14 ], [ 0, %10 ]
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %15
%17 = call i32 @backscan(i8* %16, i32 64, i8 signext 32)
%18 = call i32 @ctrlmask(i8* %16, i8* %6, i32 %17)
%19 = call i32 @fwrite(i8* %6, i32 1, i32 %18, i32* %1)
%20 = call i32 @fputc(i32 10, i32* %1)
%21 = add nuw i64 %15, 64
%22 = trunc i64 %21 to i32
%23 = icmp sgt i32 %12, %22
br i1 %23, label %14, label %24
24: ; preds = %14, %10
%25 = call i32 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 1, i32* %1)
%26 = call i32 @memset(i8* %5, i8 signext 32, i32 1024)
%27 = call i32 @fread(i8* %5, i32 1, i32 1024, i32* %0)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %10
29: ; preds = %24, %2
ret void
}