#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*/ cmd;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int readAnswer(int, unsigned char *, int);
int writeCmd(int, unsigned char *, int);
EnterIEEE(int fd) {
  unsigned char buf[200];
  unsigned char cmd[] = {0x00, 0x00, 0x00, 0x1b, 0x01, '@', 'E', 'J',  'L',
                         ' ',  '1',  '2',  '8',  '4',  '.', '4', 0x0a, '@',
                         'E',  'J',  'L',  0x0a, '@',  'E', 'J', 'L',  0x0a};
  int rd;
  memset(buf, 0, sizeof(buf));
Loop:
  if (writeCmd(fd, cmd, sizeof(cmd)) != sizeof(cmd)) {
    return 0;
  }
  rd = readAnswer(fd, buf, 8);
  if (rd == 0) {
    return 0;
  } else if (rd < 0) {
    return 0;
  } else {
    int i;
    for (i = 0; i < rd; i++)
      if (buf[i] != 0)
        break;
    if (i == rd)
      goto Loop;
    return 1;
  }
}


x86 assembly (clang, -O0):
<EnterIEEE>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %edi,-0x8(%rbp)
mov    0xebb(%rip),%rax
mov    %rax,-0xf0(%rbp)
mov    0xeb5(%rip),%rax
mov    %rax,-0xe8(%rbp)
mov    0xeaf(%rip),%rax
mov    %rax,-0xe0(%rbp)
mov    0xea9(%rip),%ax
mov    %ax,-0xd8(%rbp)
mov    0xe9e(%rip),%al
mov    %al,-0xd6(%rbp)
lea    -0xd0(%rbp),%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0xf0(%rbp),%rsi
mov    $0x1b,%edx
call   1050 <writeCmd@plt>
cltq
cmp    $0x1b,%rax
je     11c1 <EnterIEEE+0x91>
movl   $0x0,-0x4(%rbp)
jmp    127d <EnterIEEE+0x14d>
mov    -0x8(%rbp),%edi
lea    -0xd0(%rbp),%rsi
mov    $0x8,%edx
call   1040 <readAnswer@plt>
mov    %eax,-0xf4(%rbp)
cmpl   $0x0,-0xf4(%rbp)
jne    11f4 <EnterIEEE+0xc4>
movl   $0x0,-0x4(%rbp)
jmp    127d <EnterIEEE+0x14d>
cmpl   $0x0,-0xf4(%rbp)
jge    120d <EnterIEEE+0xdd>
movl   $0x0,-0x4(%rbp)
jmp    127d <EnterIEEE+0x14d>
movl   $0x0,-0xf8(%rbp)
mov    -0xf8(%rbp),%eax
cmp    -0xf4(%rbp),%eax
jge    125f <EnterIEEE+0x12f>
movslq -0xf8(%rbp),%rax
movzbl -0xd0(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     1246 <EnterIEEE+0x116>
jmp    125f <EnterIEEE+0x12f>
jmp    124b <EnterIEEE+0x11b>
mov    -0xf8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf8(%rbp)
jmp    1217 <EnterIEEE+0xe7>
mov    -0xf8(%rbp),%eax
cmp    -0xf4(%rbp),%eax
jne    1276 <EnterIEEE+0x146>
jmp    1195 <EnterIEEE+0x65>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EnterIEEE>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xe8,%rsp
mov    %edi,%ebp
movups 0xec5(%rip),%xmm0
movups %xmm0,0xb(%rsp)
movaps 0xeae(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x20(%rsp),%r15
xor    %r14d,%r14d
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1030 <memset@plt>
mov    %rsp,%rbx
jmp    1184 <EnterIEEE+0x54>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    %eax,%ecx
jne    11c4 <EnterIEEE+0x94>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1b,%edx
call   1050 <writeCmd@plt>
cmp    $0x1b,%eax
jne    11ca <EnterIEEE+0x9a>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x8,%edx
call   1040 <readAnswer@plt>
test   %eax,%eax
jle    11ca <EnterIEEE+0x9a>
mov    %eax,%eax
xor    %ecx,%ecx
nop
cmpb   $0x0,0x20(%rsp,%rcx,1)
jne    1180 <EnterIEEE+0x50>
add    $0x1,%rcx
cmp    %rcx,%rax
jne    11b0 <EnterIEEE+0x80>
mov    %eax,%ecx
jmp    1180 <EnterIEEE+0x50>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0xe8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.EnterIEEE.cmd = [27 x i8] c"\00\00\00\1B\01@EJL 1284.4\0A@EJL\0A@EJL\0A"
define i32 @EnterIEEE(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [200 x i8]
%5 = alloca [27 x i8]
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
%8 = bitcast [27 x i8]* %5 to i8*
%9 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i32 0, i32 200)
br label %11
11: ; preds = %50, %1
%12 = load i32, i32* %3
%13 = getelementptr inbounds [27 x i8], [27 x i8]* %5, i64 0, i64 0
%14 = call i32 @writeCmd(i32 %12, i8* %13, i32 27)
%15 = sext i32 %14 to i64
%16 = icmp ne i64 %15, 27
br i1 %16, label %17, label %18
17: ; preds = %11
store i32 0, i32* %2
br label %52
18: ; preds = %11
%19 = load i32, i32* %3
%20 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%21 = call i32 @readAnswer(i32 %19, i8* %20, i32 8)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %18
store i32 0, i32* %2
br label %52
25: ; preds = %18
%26 = load i32, i32* %6
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 0, i32* %2
br label %52
29: ; preds = %25
store i32 0, i32* %7
br label %30
30: ; preds = %43, %29
%31 = load i32, i32* %7
%32 = load i32, i32* %6
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %46
34: ; preds = %30
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %34
br label %46
42: ; preds = %34
br label %43
43: ; preds = %42
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %30
46: ; preds = %41, %30
%47 = load i32, i32* %7
%48 = load i32, i32* %6
%49 = icmp eq i32 %47, %48
br i1 %49, label %50, label %51
50: ; preds = %46
br label %11
51: ; preds = %46
store i32 1, i32* %2
br label %52
52: ; preds = %51, %28, %24, %17
%53 = load i32, i32* %2
ret i32 %53
}

LLVM IR (-O2):
@__const.EnterIEEE.cmd = [27 x i8] c"\00\00\00\1B\01@EJL 1284.4\0A@EJL\0A@EJL\0A"
define i32 @EnterIEEE(i32 %0) {
%2 = alloca [200 x i8]
%3 = alloca [27 x i8]
%4 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [27 x i8], [27 x i8]* %3, i64 0, i64 0
%6 = call i32 @memset(i8* %4, i32 0, i32 200)
br label %7
7: ; preds = %25, %1
%8 = call i32 @writeCmd(i32 %0, i8* %5, i32 27)
%9 = icmp eq i32 %8, 27
br i1 %9, label %10, label %28
10: ; preds = %7
%11 = call i32 @readAnswer(i32 %0, i8* %4, i32 8)
%12 = icmp slt i32 %11, 1
br i1 %12, label %28, label %13
13: ; preds = %10
%14 = zext i32 %11 to i64
br label %15
15: ; preds = %13, %20
%16 = phi i64 [ 0, %13 ], [ %21, %20 ]
%17 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = add nuw nsw i64 %16, 1
%22 = icmp eq i64 %21, %14
br i1 %22, label %25, label %15
23: ; preds = %15
%24 = trunc i64 %16 to i32
br label %25
25: ; preds = %20, %23
%26 = phi i32 [ %24, %23 ], [ %11, %20 ]
%27 = icmp eq i32 %26, %11
br i1 %27, label %7, label %28
28: ; preds = %10, %7, %25
%29 = phi i32 [ 1, %25 ], [ 0, %7 ], [ 0, %10 ]
ret i32 %29
}