#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 EXIT_FAILURE;
int O_WRONLY;
int /*<<< orphan*/ _IO(char, int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int);
int open(char const *, int);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char const *argv[]) {
  int a;
  a = open(argv[1], 0666);
  char arr[1944];
  int i;
  int index = open("/dev/asciistreamer", O_WRONLY);
  if (index == -1) {
    printf("Cannot open device!");
    return EXIT_FAILURE;
  }
  ioctl(index, _IO('o', 1), 15);
  for (i = 0; i < 1944; i++) {
    arr[i] = ' ';
  }
  int j = 0;
  while ((j = read(a, arr, 1944)) > 0) {
    write(index, arr, 1944);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x1b6,%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
lea    0xe62(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x7b8(%rbp)
cmpl   $0xffffffff,-0x7b8(%rbp)
jne    11d3 <main+0x73>
lea    0xe56(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    128d <main+0x12d>
mov    -0x7b8(%rbp),%eax
mov    %eax,-0x7c0(%rbp)
mov    $0x6f,%edi
mov    $0x1,%esi
call   1050 <_IO@plt>
mov    -0x7c0(%rbp),%edi
mov    %eax,%esi
mov    $0xf,%edx
call   1060 <ioctl@plt>
movl   $0x0,-0x7b4(%rbp)
cmpl   $0x798,-0x7b4(%rbp)
jge    123d <main+0xdd>
movslq -0x7b4(%rbp),%rax
movb   $0x20,-0x7b0(%rbp,%rax,1)
20
mov    -0x7b4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7b4(%rbp)
jmp    120a <main+0xaa>
movl   $0x0,-0x7bc(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x7b0(%rbp),%rsi
mov    $0x798,%edx
call   1070 <read@plt>
mov    %eax,-0x7bc(%rbp)
cmp    $0x0,%eax
jle    1286 <main+0x126>
mov    -0x7b8(%rbp),%edi
lea    -0x7b0(%rbp),%rsi
mov    $0x798,%edx
call   1030 <write@plt>
jmp    1247 <main+0xe7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x7c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x798,%rsp
mov    0x8(%rsi),%rdi
mov    $0x1b6,%esi
call   1090 <open@plt>
mov    %eax,%r15d
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
lea    0xe62(%rip),%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     1225 <main+0xb5>
mov    %eax,%ebp
mov    $0x6f,%edi
mov    $0x1,%esi
call   1050 <_IO@plt>
mov    %ebp,%edi
mov    %eax,%esi
mov    $0xf,%edx
call   1070 <ioctl@plt>
mov    %rsp,%rbx
mov    $0x798,%edx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1060 <memset@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x798,%edx
call   1080 <read@plt>
xor    %r14d,%r14d
test   %eax,%eax
jle    123b <main+0xcb>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x798,%edx
call   1030 <write@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x798,%edx
call   1080 <read@plt>
test   %eax,%eax
jg     1200 <main+0x90>
jmp    123b <main+0xcb>
lea    0xde7(%rip),%rdi
call   1040 <printf@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%r14d
mov    %r14d,%eax
add    $0x798,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"/dev/asciistreamer\00"
@O_WRONLY = global i32 0
@.str.1 = [20 x i8] c"Cannot open device!\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1944 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @open(i8* %13, i32 438)
store i32 %14, i32* %6
%15 = load i32, i32* @O_WRONLY
%16 = call i32 @open(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 %16, i32* %9
%17 = load i32, i32* %9
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
store i32 %21, i32* %3
br label %47
22: ; preds = %2
%23 = load i32, i32* %9
%24 = call i32 @_IO(i8 signext 111, i32 1)
%25 = call i32 @ioctl(i32 %23, i32 %24, i32 15)
store i32 0, i32* %8
br label %26
26: ; preds = %33, %22
%27 = load i32, i32* %8
%28 = icmp slt i32 %27, 1944
br i1 %28, label %29, label %36
29: ; preds = %26
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [1944 x i8], [1944 x i8]* %7, i64 0, i64 %31
store i8 32, i8* %32
br label %33
33: ; preds = %29
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
br label %26
36: ; preds = %26
store i32 0, i32* %10
br label %37
37: ; preds = %42, %36
%38 = load i32, i32* %6
%39 = getelementptr inbounds [1944 x i8], [1944 x i8]* %7, i64 0, i64 0
%40 = call i32 @read(i32 %38, i8* %39, i32 1944)
store i32 %40, i32* %10
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %37
%43 = load i32, i32* %9
%44 = getelementptr inbounds [1944 x i8], [1944 x i8]* %7, i64 0, i64 0
%45 = call i32 @write(i32 %43, i8* %44, i32 1944)
br label %37
46: ; preds = %37
store i32 0, i32* %3
br label %47
47: ; preds = %46, %19
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str = [19 x i8] c"/dev/asciistreamer\00"
@O_WRONLY = global i32 0
@.str.1 = [20 x i8] c"Cannot open device!\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1944 x i8]
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i32 @open(i8* %5, i32 438)
%7 = getelementptr inbounds [1944 x i8], [1944 x i8]* %3, i64 0, i64 0
%8 = load i32, i32* @O_WRONLY
%9 = tail call i32 @open(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
br label %24
14: ; preds = %2
%15 = getelementptr inbounds [1944 x i8], [1944 x i8]* %3, i64 0, i64 0
%16 = tail call i32 @_IO(i8 signext 111, i32 1)
%17 = tail call i32 @ioctl(i32 %9, i32 %16, i32 15)
%18 = call i32 @read(i32 %6, i8* %7, i32 1944)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %14, %20
%21 = call i32 @write(i32 %9, i8* %7, i32 1944)
%22 = call i32 @read(i32 %6, i8* %7, i32 1944)
%23 = icmp sgt i32 %22, 0
br i1 %23, label %20, label %24
24: ; preds = %20, %14, %11
%25 = phi i32 [ %13, %11 ], [ 0, %14 ], [ 0, %20 ]
ret i32 %25
}