#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 ctrlunmask(char *, char *, int);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
void str2scr(FILE *in, FILE *out) {
  char block[0x400];
  char line[2 * 0x40 + 3];
  int n, i = 0, k = 0;
  memset(block, ' ', 0x400);
  while (!feof(in)) {
    fgets(line, 2 * 0x40 + 2, in);
    if (feof(in))
      break;
    if (!strcmp(line, "\f\n")) {
      fwrite(block, 1, 0x400, out);
      memset(block, ' ', 0x400);
      k = 0;
    } else {
      n = strlen(line);
      if (n)
        n -= (line[n - 1] == '\n');
      n = ctrlunmask(line, line, n);
      memcpy(block + k, line, n);
      k += 0x40;
    }
  }
}


x86 assembly (clang, -O0):
<str2scr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4b0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x4a8(%rbp)
movl   $0x0,-0x4ac(%rbp)
lea    -0x410(%rbp),%rdi
mov    $0x20,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11dc <str2scr+0x5c>
jmp    1305 <str2scr+0x185>
lea    -0x4a0(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x82,%esi
call   1050 <fgets@plt>
mov    -0x8(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     1209 <str2scr+0x89>
jmp    1305 <str2scr+0x185>
lea    -0x4a0(%rbp),%rdi
lea    0xde9(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1264 <str2scr+0xe4>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1090 <fwrite@plt>
lea    -0x410(%rbp),%rdi
mov    $0x20,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
movl   $0x0,-0x4ac(%rbp)
jmp    1300 <str2scr+0x180>
lea    -0x4a0(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x4a4(%rbp)
cmpl   $0x0,-0x4a4(%rbp)
je     12af <str2scr+0x12f>
mov    -0x4a4(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x4a0(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
sete   %al
and    $0x1,%al
movzbl %al,%ecx
mov    -0x4a4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4a4(%rbp)
lea    -0x4a0(%rbp),%rdi
lea    -0x4a0(%rbp),%rsi
mov    -0x4a4(%rbp),%edx
call   10a0 <ctrlunmask@plt>
mov    %eax,-0x4a4(%rbp)
lea    -0x410(%rbp),%rdi
movslq -0x4ac(%rbp),%rax
add    %rax,%rdi
lea    -0x4a0(%rbp),%rsi
mov    -0x4a4(%rbp),%edx
call   1080 <memcpy@plt>
mov    -0x4ac(%rbp),%eax
add    $0x40,%eax
mov    %eax,-0x4ac(%rbp)
jmp    11bd <str2scr+0x3d>
add    $0x4b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2scr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x498,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x90(%rsp),%rdi
mov    $0x20,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %rax,%rax
je     11bd <str2scr+0x4d>
add    $0x498,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
mov    %rsp,%r15
mov    $0xa0c,%r13d
lea    0x90(%rsp),%r12
jmp    1216 <str2scr+0xa6>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r14,%rcx
call   1080 <fwrite@plt>
mov    %r12,%rdi
mov    $0x20,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %rax,%rax
jne    11ab <str2scr+0x3b>
mov    %r15,%rdi
mov    $0x82,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %rax,%rax
jne    11ab <str2scr+0x3b>
mov    (%rsp),%eax
xor    %r13d,%eax
movzbl 0x2(%rsp),%ecx
or     %ax,%cx
je     11e0 <str2scr+0x70>
mov    %r15,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     1270 <str2scr+0x100>
movslq %eax,%rcx
xor    %edx,%edx
cmpb   $0xa,-0x1(%rcx,%r15,1)
sete   %dl
sub    %edx,%eax
jmp    1272 <str2scr+0x102>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
mov    %r15,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1090 <ctrlunmask@plt>
movslq %ebp,%rbp
lea    (%rsp,%rbp,1),%rdi
add    $0x90,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1070 <memcpy@plt>
add    $0x40,%ebp
jmp    1209 <str2scr+0x99>

LLVM IR (-O0):
@.str = [3 x i8] c"\0C\0A\00"
define void @str2scr(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [1024 x i8]
%6 = alloca [131 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
store i32 0, i32* %8
store i32 0, i32* %9
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%11 = call i32 @memset(i8* %10, i8 signext 32, i32 1024)
br label %12
12: ; preds = %65, %2
%13 = load i32*, i32** %3
%14 = call i64 @feof(i32* %13)
%15 = icmp ne i64 %14, 0
%16 = xor i1 %15, true
br i1 %16, label %17, label %66
17: ; preds = %12
%18 = getelementptr inbounds [131 x i8], [131 x i8]* %6, i64 0, i64 0
%19 = load i32*, i32** %3
%20 = call i32 @fgets(i8* %18, i32 130, i32* %19)
%21 = load i32*, i32** %3
%22 = call i64 @feof(i32* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %17
br label %66
25: ; preds = %17
%26 = getelementptr inbounds [131 x i8], [131 x i8]* %6, i64 0, i64 0
%27 = call i32 @strcmp(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
br i1 %28, label %35, label %29
29: ; preds = %25
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%31 = load i32*, i32** %4
%32 = call i32 @fwrite(i8* %30, i32 1, i32 1024, i32* %31)
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%34 = call i32 @memset(i8* %33, i8 signext 32, i32 1024)
store i32 0, i32* %9
br label %65
35: ; preds = %25
%36 = getelementptr inbounds [131 x i8], [131 x i8]* %6, i64 0, i64 0
%37 = call i32 @strlen(i8* %36)
store i32 %37, i32* %7
%38 = load i32, i32* %7
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %51
40: ; preds = %35
%41 = load i32, i32* %7
%42 = sub nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [131 x i8], [131 x i8]* %6, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 10
%48 = zext i1 %47 to i32
%49 = load i32, i32* %7
%50 = sub nsw i32 %49, %48
store i32 %50, i32* %7
br label %51
51: ; preds = %40, %35
%52 = getelementptr inbounds [131 x i8], [131 x i8]* %6, i64 0, i64 0
%53 = getelementptr inbounds [131 x i8], [131 x i8]* %6, i64 0, i64 0
%54 = load i32, i32* %7
%55 = call i32 @ctrlunmask(i8* %52, i8* %53, i32 %54)
store i32 %55, i32* %7
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%57 = load i32, i32* %9
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = getelementptr inbounds [131 x i8], [131 x i8]* %6, i64 0, i64 0
%61 = load i32, i32* %7
%62 = call i32 @memcpy(i8* %59, i8* %60, i32 %61)
%63 = load i32, i32* %9
%64 = add nsw i32 %63, 64
store i32 %64, i32* %9
br label %65
65: ; preds = %51, %29
br label %12
66: ; preds = %24, %12
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"\0C\0A\00"
define void @str2scr(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [131 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [131 x i8], [131 x i8]* %4, i64 0, i64 0
%7 = call i32 @memset(i8* %5, i8 signext 32, i32 1024)
%8 = call i64 @feof(i32* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %43
10: ; preds = %2, %39
%11 = phi i32 [ %40, %39 ], [ 0, %2 ]
%12 = call i32 @fgets(i8* %6, i32 130, i32* %0)
%13 = call i64 @feof(i32* %0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %43
15: ; preds = %10
%16 = call i32 @bcmp(i8* dereferenceable(3) %6, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64 3)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 @fwrite(i8* %5, i32 1, i32 1024, i32* %1)
%20 = call i32 @memset(i8* %5, i8 signext 32, i32 1024)
br label %39
21: ; preds = %15
%22 = call i32 @strlen(i8* %6)
%23 = icmp eq i32 %22, 0
br i1 %23, label %32, label %24
24: ; preds = %21
%25 = add nsw i32 %22, -1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [131 x i8], [131 x i8]* %4, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 10
%30 = sext i1 %29 to i32
%31 = add i32 %22, %30
br label %32
32: ; preds = %24, %21
%33 = phi i32 [ %31, %24 ], [ 0, %21 ]
%34 = call i32 @ctrlunmask(i8* %6, i8* %6, i32 %33)
%35 = sext i32 %11 to i64
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %35
%37 = call i32 @memcpy(i8* %36, i8* %6, i32 %34)
%38 = add nsw i32 %11, 64
br label %39
39: ; preds = %32, %18
%40 = phi i32 [ %38, %32 ], [ 0, %18 ]
%41 = call i64 @feof(i32* %0)
%42 = icmp eq i64 %41, 0
br i1 %42, label %10, label %43
43: ; preds = %39, %10, %2
ret void
}