#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 */

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int read(int, ...);
int sockerror(int, char *);
int sockprint(int, char *, ...);
int dump_virtual_console(int fd_out, int fd_in) {
  struct {
    unsigned char lines, cols, x, y;
  } scrn;
  int x, y;
  if (lseek(fd_in, 0, SEEK_SET) == -1)
    return sockerror(fd_out, "lseek");
  if (read(fd_in, &scrn, 4) == -1)
    return sockerror(fd_out, "read on vcs");
  for (y = 0; y < scrn.lines; y++) {
    int nspaces = 0;
    for (x = 0; x < scrn.cols; x++) {
      int loop;
      char ca[2];
      if (read(fd_in, ca, 2) == -1)
        return sockerror(fd_out, "read on vcs (data)");
      if (ca[0] != ' ') {
        for (loop = 0; loop < nspaces; loop++) {
          if (sockprint(fd_out, " ") == -1)
            return -1;
        }
        nspaces = 0;
        if (sockprint(fd_out, "%c", ca[0]) == -1)
          return -1;
      } else {
        nspaces++;
      }
    }
    if (sockprint(fd_out, "\r\n") == -1)
      return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<dump_virtual_console>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e88(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
cmp    $0xffffffff,%eax
jne    1181 <dump_virtual_console+0x41>
mov    -0x8(%rbp),%edi
lea    0xe8c(%rip),%rsi
call   1060 <sockerror@plt>
mov    %eax,-0x4(%rbp)
jmp    1305 <dump_virtual_console+0x1c5>
mov    -0xc(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1040 <read@plt>
cmp    $0xffffffff,%eax
jne    11b4 <dump_virtual_console+0x74>
mov    -0x8(%rbp),%edi
lea    0xe5f(%rip),%rsi
call   1060 <sockerror@plt>
mov    %eax,-0x4(%rbp)
jmp    1305 <dump_virtual_console+0x1c5>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
movzbl -0x10(%rbp),%ecx
cmp    %ecx,%eax
jge    12fe <dump_virtual_console+0x1be>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
movzbl -0xf(%rbp),%ecx
cmp    %ecx,%eax
jge    12c5 <dump_virtual_console+0x185>
mov    -0xc(%rbp),%edi
lea    -0x22(%rbp),%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1040 <read@plt>
cmp    $0xffffffff,%eax
jne    121a <dump_virtual_console+0xda>
mov    -0x8(%rbp),%edi
lea    0xe05(%rip),%rsi
call   1060 <sockerror@plt>
mov    %eax,-0x4(%rbp)
jmp    1305 <dump_virtual_console+0x1c5>
movsbl -0x22(%rbp),%eax
cmp    $0x20,%eax
je     12a9 <dump_virtual_console+0x169>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1273 <dump_virtual_console+0x133>
mov    -0x8(%rbp),%edi
lea    0xde1(%rip),%rsi
mov    $0x0,%al
call   1050 <sockprint@plt>
cmp    $0xffffffff,%eax
jne    1260 <dump_virtual_console+0x120>
movl   $0xffffffff,-0x4(%rbp)
jmp    1305 <dump_virtual_console+0x1c5>
jmp    1265 <dump_virtual_console+0x125>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    122e <dump_virtual_console+0xee>
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
movsbl -0x22(%rbp),%edx
lea    0xd9f(%rip),%rsi
mov    $0x0,%al
call   1050 <sockprint@plt>
cmp    $0xffffffff,%eax
jne    12a4 <dump_virtual_console+0x164>
movl   $0xffffffff,-0x4(%rbp)
jmp    1305 <dump_virtual_console+0x1c5>
jmp    12b2 <dump_virtual_console+0x172>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12b7 <dump_virtual_console+0x177>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d8 <dump_virtual_console+0x98>
mov    -0x8(%rbp),%edi
lea    0xd5b(%rip),%rsi
mov    $0x0,%al
call   1050 <sockprint@plt>
cmp    $0xffffffff,%eax
jne    12eb <dump_virtual_console+0x1ab>
movl   $0xffffffff,-0x4(%rbp)
jmp    1305 <dump_virtual_console+0x1c5>
jmp    12f0 <dump_virtual_console+0x1b0>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11bb <dump_virtual_console+0x7b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_virtual_console>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r12d
mov    %edi,%r13d
mov    0x2e85(%rip),%rax
mov    (%rax),%edx
mov    %esi,%edi
xor    %esi,%esi
call   1030 <lseek@plt>
cmp    $0xffffffff,%eax
je     126b <dump_virtual_console+0x12b>
xor    %r14d,%r14d
lea    0x10(%rsp),%rsi
mov    %r12d,%edi
mov    $0x4,%edx
xor    %eax,%eax
call   1040 <read@plt>
cmp    $0xffffffff,%eax
je     1288 <dump_virtual_console+0x148>
cmpb   $0x0,0x10(%rsp)
je     12a2 <dump_virtual_console+0x162>
lea    0xe84(%rip),%r15
xor    %ecx,%ecx
mov    %ecx,0x14(%rsp)
cmpb   $0x0,0x11(%rsp)
lea    0xe(%rsp),%r14
je     123c <dump_virtual_console+0xfc>
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    11cf <dump_virtual_console+0x8f>
nopl   (%rax)
add    $0x1,%ebx
add    $0x1,%ebp
movzbl 0x11(%rsp),%eax
cmp    %eax,%ebp
jae    123c <dump_virtual_console+0xfc>
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   1040 <read@plt>
cmp    $0xffffffff,%eax
je     12b4 <dump_virtual_console+0x174>
mov    0xe(%rsp),%al
cmp    $0x20,%al
je     11c0 <dump_virtual_console+0x80>
test   %ebx,%ebx
jle    121f <dump_virtual_console+0xdf>
cs nopw 0x0(%rax,%rax,1)
mov    %r13d,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <sockprint@plt>
cmp    $0xffffffff,%eax
je     129c <dump_virtual_console+0x15c>
add    $0xffffffff,%ebx
jne    1200 <dump_virtual_console+0xc0>
mov    0xe(%rsp),%al
movsbl %al,%edx
xor    %ebx,%ebx
mov    %r13d,%edi
lea    0xdf9(%rip),%rsi
xor    %eax,%eax
call   1050 <sockprint@plt>
cmp    $0xffffffff,%eax
jne    11c3 <dump_virtual_console+0x83>
jmp    129c <dump_virtual_console+0x15c>
mov    %r13d,%edi
lea    0xde4(%rip),%rsi
xor    %eax,%eax
call   1050 <sockprint@plt>
cmp    $0xffffffff,%eax
je     129c <dump_virtual_console+0x15c>
mov    0x14(%rsp),%ecx
add    $0x1,%ecx
movzbl 0x10(%rsp),%eax
xor    %r14d,%r14d
cmp    %eax,%ecx
jb     11a3 <dump_virtual_console+0x63>
jmp    12a2 <dump_virtual_console+0x162>
lea    0xd8e(%rip),%rsi
mov    %r13d,%edi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <sockerror@plt>
lea    0xd77(%rip),%rsi
mov    %r13d,%edi
call   1060 <sockerror@plt>
mov    %eax,%r14d
jmp    12a2 <dump_virtual_console+0x162>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd57(%rip),%rsi
jmp    128f <dump_virtual_console+0x14f>

LLVM IR (-O0):
%struct.anon = type { i8, i8, i8, i8 }
@SEEK_SET = global i32 0
@.str = [6 x i8] c"lseek\00"
@.str.1 = [12 x i8] c"read on vcs\00"
@.str.2 = [19 x i8] c"read on vcs (data)\00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [3 x i8] c"%c\00"
@.str.5 = [3 x i8] c"\0D\0A\00"
define i32 @dump_virtual_console(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.anon
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [2 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
%12 = load i32, i32* %5
%13 = load i32, i32* @SEEK_SET
%14 = call i32 @lseek(i32 %12, i32 0, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i32, i32* %4
%18 = call i32 @sockerror(i32 %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 %18, i32* %3
br label %93
19: ; preds = %2
%20 = load i32, i32* %5
%21 = call i32 (i32, ...) @read(i32 %20, %struct.anon* %6, i32 4)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i32, i32* %4
%25 = call i32 @sockerror(i32 %24, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 %25, i32* %3
br label %93
26: ; preds = %19
store i32 0, i32* %8
br label %27
27: ; preds = %89, %26
%28 = load i32, i32* %8
%29 = getelementptr inbounds %struct.anon, %struct.anon* %6, i32 0, i32 0
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = icmp slt i32 %28, %31
br i1 %32, label %33, label %92
33: ; preds = %27
store i32 0, i32* %9
store i32 0, i32* %7
br label %34
34: ; preds = %80, %33
%35 = load i32, i32* %7
%36 = getelementptr inbounds %struct.anon, %struct.anon* %6, i32 0, i32 1
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = icmp slt i32 %35, %38
br i1 %39, label %40, label %83
40: ; preds = %34
%41 = load i32, i32* %5
%42 = getelementptr inbounds [2 x i8], [2 x i8]* %11, i64 0, i64 0
%43 = call i32 (i32, ...) @read(i32 %41, i8* %42, i32 2)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = load i32, i32* %4
%47 = call i32 @sockerror(i32 %46, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 %47, i32* %3
br label %93
48: ; preds = %40
%49 = getelementptr inbounds [2 x i8], [2 x i8]* %11, i64 0, i64 0
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp ne i32 %51, 32
br i1 %52, label %53, label %76
53: ; preds = %48
store i32 0, i32* %10
br label %54
54: ; preds = %64, %53
%55 = load i32, i32* %10
%56 = load i32, i32* %9
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %67
58: ; preds = %54
%59 = load i32, i32* %4
%60 = call i32 (i32, i8*, ...) @sockprint(i32 %59, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %63
62: ; preds = %58
store i32 -1, i32* %3
br label %93
63: ; preds = %58
br label %64
64: ; preds = %63
%65 = load i32, i32* %10
%66 = add nsw i32 %65, 1
store i32 %66, i32* %10
br label %54
67: ; preds = %54
store i32 0, i32* %9
%68 = load i32, i32* %4
%69 = getelementptr inbounds [2 x i8], [2 x i8]* %11, i64 0, i64 0
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = call i32 (i32, i8*, ...) @sockprint(i32 %68, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %71)
%73 = icmp eq i32 %72, -1
br i1 %73, label %74, label %75
74: ; preds = %67
store i32 -1, i32* %3
br label %93
75: ; preds = %67
br label %79
76: ; preds = %48
%77 = load i32, i32* %9
%78 = add nsw i32 %77, 1
store i32 %78, i32* %9
br label %79
79: ; preds = %76, %75
br label %80
80: ; preds = %79
%81 = load i32, i32* %7
%82 = add nsw i32 %81, 1
store i32 %82, i32* %7
br label %34
83: ; preds = %34
%84 = load i32, i32* %4
%85 = call i32 (i32, i8*, ...) @sockprint(i32 %84, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%86 = icmp eq i32 %85, -1
br i1 %86, label %87, label %88
87: ; preds = %83
store i32 -1, i32* %3
br label %93
88: ; preds = %83
br label %89
89: ; preds = %88
%90 = load i32, i32* %8
%91 = add nsw i32 %90, 1
store i32 %91, i32* %8
br label %27
92: ; preds = %27
store i32 0, i32* %3
br label %93
93: ; preds = %92, %87, %74, %62, %45, %23, %16
%94 = load i32, i32* %3
ret i32 %94
}

LLVM IR (-O2):
%struct.anon = type { i8, i8, i8, i8 }
@SEEK_SET = global i32 0
@.str = [6 x i8] c"lseek\00"
@.str.1 = [12 x i8] c"read on vcs\00"
@.str.2 = [19 x i8] c"read on vcs (data)\00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [3 x i8] c"%c\00"
@.str.5 = [3 x i8] c"\0D\0A\00"
define i32 @dump_virtual_console(i32 %0, i32 %1) {
%3 = alloca %struct.anon
%4 = alloca [2 x i8]
%5 = getelementptr inbounds %struct.anon, %struct.anon* %3, i64 0, i32 0
%6 = load i32, i32* @SEEK_SET
%7 = tail call i32 @lseek(i32 %1, i32 0, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @sockerror(i32 %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %70
11: ; preds = %2
%12 = call i32 (i32, ...) @read(i32 %1, %struct.anon* %3, i32 4)
%13 = icmp eq i32 %12, -1
br i1 %13, label %20, label %14
14: ; preds = %11
%15 = load i8, i8* %5
%16 = icmp eq i8 %15, 0
br i1 %16, label %70, label %17
17: ; preds = %14
%18 = getelementptr inbounds %struct.anon, %struct.anon* %3, i64 0, i32 1
%19 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
br label %26
20: ; preds = %11
%21 = call i32 @sockerror(i32 %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %70
22: ; preds = %66
%23 = load i8, i8* %5
%24 = zext i8 %23 to i32
%25 = icmp ult i32 %69, %24
br i1 %25, label %26, label %70
26: ; preds = %17, %22
%27 = phi i32 [ 0, %17 ], [ %69, %22 ]
%28 = load i8, i8* %18
%29 = icmp eq i8 %28, 0
br i1 %29, label %66, label %30
30: ; preds = %26, %60
%31 = phi i32 [ %61, %60 ], [ 0, %26 ]
%32 = phi i32 [ %62, %60 ], [ 0, %26 ]
%33 = call i32 (i32, ...) @read(i32 %1, i8* %19, i32 2)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = call i32 @sockerror(i32 %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %58
37: ; preds = %30
%38 = load i8, i8* %19
%39 = icmp eq i8 %38, 32
br i1 %39, label %56, label %40
40: ; preds = %37
%41 = icmp sgt i32 %31, 0
br i1 %41, label %44, label %51
42: ; preds = %44
%43 = icmp eq i32 %48, %31
br i1 %43, label %49, label %44
44: ; preds = %40, %42
%45 = phi i32 [ %48, %42 ], [ 0, %40 ]
%46 = call i32 (i32, i8*, ...) @sockprint(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%47 = icmp eq i32 %46, -1
%48 = add nuw nsw i32 %45, 1
br i1 %47, label %58, label %42
49: ; preds = %42
%50 = load i8, i8* %19
br label %51
51: ; preds = %49, %40
%52 = phi i8 [ %50, %49 ], [ %38, %40 ]
%53 = sext i8 %52 to i32
%54 = call i32 (i32, i8*, ...) @sockprint(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %53)
%55 = icmp eq i32 %54, -1
br i1 %55, label %58, label %60
56: ; preds = %37
%57 = add nsw i32 %31, 1
br label %60
58: ; preds = %51, %44, %35
%59 = phi i32 [ %36, %35 ], [ -1, %44 ], [ -1, %51 ]
br label %70
60: ; preds = %51, %56
%61 = phi i32 [ 0, %51 ], [ %57, %56 ]
%62 = add nuw nsw i32 %32, 1
%63 = load i8, i8* %18
%64 = zext i8 %63 to i32
%65 = icmp ult i32 %62, %64
br i1 %65, label %30, label %66
66: ; preds = %60, %26
%67 = call i32 (i32, i8*, ...) @sockprint(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%68 = icmp eq i32 %67, -1
%69 = add nuw nsw i32 %27, 1
br i1 %68, label %70, label %22
70: ; preds = %66, %22, %14, %58, %20, %9
%71 = phi i32 [ %10, %9 ], [ %21, %20 ], [ %59, %58 ], [ 0, %14 ], [ -1, %66 ], [ 0, %22 ]
ret i32 %71
}