#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 mread(char *, int, int);
int readock(int timeout, int count) {
  static int c;
  static char byt[5];
  c = mread(byt, count, timeout);
  if (c < 1)
    return (-2);
  if (c == 1)
    return (byt[0] & 0xff);
  else
    while (c)
      if (byt[--c] != ('X' & 037))
        return (-1);
  return ('X' & 037);
}


x86 assembly (clang, -O0):
<readock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0x2f05(%rip),%rdi
call   1030 <mread@plt>
mov    %eax,0x2ef6(%rip)
cmpl   $0x1,0x2eef(%rip)
jge    114f <readock+0x3f>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11c5 <readock+0xb5>
cmpl   $0x1,0x2ed6(%rip)
jne    1170 <readock+0x60>
movsbl 0x2ecd(%rip),%eax
and    $0xff,%eax
mov    %eax,-0x4(%rbp)
jmp    11c5 <readock+0xb5>
jmp    1175 <readock+0x65>
cmpl   $0x0,0x2eb0(%rip)
je     11b9 <readock+0xa9>
mov    0x2ea4(%rip),%eax
add    $0xffffffff,%eax
mov    %eax,0x2e9b(%rip)
movslq %eax,%rcx
lea    0x2e95(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x18,%eax
je     11b4 <readock+0xa4>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c5 <readock+0xb5>
jmp    1175 <readock+0x65>
jmp    11be <readock+0xae>
movl   $0x18,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readock>:
push   %rbx
mov    %edi,%edx
lea    0x2f0f(%rip),%rbx
mov    %rbx,%rdi
call   1030 <mread@plt>
test   %eax,%eax
jle    1134 <readock+0x24>
cmp    $0x1,%eax
jne    113b <readock+0x2b>
movzbl 0x2ef7(%rip),%eax
pop    %rbx
ret
mov    $0xfffffffe,%eax
pop    %rbx
ret
mov    %eax,%eax
mov    %rax,%rcx
sub    $0x1,%rcx
jb     1157 <readock+0x47>
cmpb   $0x18,-0x1(%rax,%rbx,1)
mov    %rcx,%rax
je     1140 <readock+0x30>
mov    $0xffffffff,%eax
pop    %rbx
ret
mov    $0x18,%eax
pop    %rbx
ret

LLVM IR (-O0):
@readock.c = internal global i32 0
@readock.byt = internal global [5 x i8] zeroinitializer
define i32 @readock(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
%7 = load i32, i32* %4
%8 = call i32 @mread(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @readock.byt, i64 0, i64 0), i32 %6, i32 %7)
store i32 %8, i32* @readock.c
%9 = load i32, i32* @readock.c
%10 = icmp slt i32 %9, 1
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -2, i32* %3
br label %35
12: ; preds = %2
%13 = load i32, i32* @readock.c
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @readock.byt, i64 0, i64 0)
%17 = sext i8 %16 to i32
%18 = and i32 %17, 255
store i32 %18, i32* %3
br label %35
19: ; preds = %12
br label %20
20: ; preds = %32, %19
%21 = load i32, i32* @readock.c
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %20
%24 = load i32, i32* @readock.c
%25 = add nsw i32 %24, -1
store i32 %25, i32* @readock.c
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [5 x i8], [5 x i8]* @readock.byt, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 24
br i1 %30, label %31, label %32
31: ; preds = %23
store i32 -1, i32* %3
br label %35
32: ; preds = %23
br label %20
33: ; preds = %20
br label %34
34: ; preds = %33
store i32 24, i32* %3
br label %35
35: ; preds = %34, %31, %15, %11
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@readock.byt = internal global [5 x i8] zeroinitializer
define i32 @readock(i32 %0, i32 %1) {
%3 = tail call i32 @mread(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @readock.byt, i64 0, i64 0), i32 %1, i32 %0)
%4 = icmp slt i32 %3, 1
br i1 %4, label %20, label %5
5: ; preds = %2
%6 = icmp eq i32 %3, 1
br i1 %6, label %9, label %7
7: ; preds = %5
%8 = zext i32 %3 to i64
br label %12
9: ; preds = %5
%10 = load i8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @readock.byt, i64 0, i64 0)
%11 = zext i8 %10 to i32
br label %20
12: ; preds = %7, %15
%13 = phi i64 [ %8, %7 ], [ %16, %15 ]
%14 = icmp eq i64 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %12
%16 = add nsw i64 %13, -1
%17 = getelementptr inbounds [5 x i8], [5 x i8]* @readock.byt, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 24
br i1 %19, label %12, label %20
20: ; preds = %12, %15, %2, %9
%21 = phi i32 [ %11, %9 ], [ -2, %2 ], [ 24, %12 ], [ -1, %15 ]
ret i32 %21
}