#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*/ pi_sleep(int);
int read_byte();
int write_block(int, int /*<<< orphan*/, int /*<<< orphan*/,
                int /*<<< orphan*/);
int trim_read(void) {
  int b1, b2, trim;
  if (write_block(32, 0, 0, 0) == -1)
    return -1;
  pi_sleep(80);
  b1 = read_byte();
  b2 = read_byte();
  if (b1 == -1 || b2 == -1)
    return -1;
  trim = b1 * 256 + b1;
  if (trim == 255)
    return -3;
  return trim;
}


x86 assembly (clang, -O0):
<trim_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x20,%edi
xor    %ecx,%ecx
mov    %ecx,%esi
mov    %ecx,%edx
call   1040 <write_block@plt>
cmp    $0xffffffff,%eax
jne    115d <trim_read+0x2d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c6 <trim_read+0x96>
mov    $0x50,%edi
call   1050 <pi_sleep@plt>
mov    $0x0,%al
call   1030 <read_byte@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <read_byte@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
je     118f <trim_read+0x5f>
cmpl   $0xffffffff,-0xc(%rbp)
jne    119b <trim_read+0x6b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c6 <trim_read+0x96>
mov    -0x8(%rbp),%eax
shl    $0x8,%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0xff,-0x10(%rbp)
jne    11c0 <trim_read+0x90>
movl   $0xfffffffd,-0x4(%rbp)
jmp    11c6 <trim_read+0x96>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim_read>:
push   %rbx
mov    $0x20,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <write_block@plt>
cmp    $0xffffffff,%eax
je     1177 <trim_read+0x47>
mov    $0x50,%edi
call   1050 <pi_sleep@plt>
xor    %eax,%eax
call   1030 <read_byte@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <read_byte@plt>
mov    %eax,%ecx
mov    %ebx,%eax
shl    $0x8,%eax
add    %ebx,%eax
cmp    $0xffffffff,%ecx
cmove  %ecx,%eax
cmp    $0xffffffff,%ebx
cmove  %ebx,%eax
pop    %rbx
ret
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @trim_read() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i32 @write_block(i32 32, i32 0, i32 0, i32 0)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %8
7: ; preds = %0
store i32 -1, i32* %1
br label %28
8: ; preds = %0
%9 = call i32 @pi_sleep(i32 80)
%10 = call i32 (...) @read_byte()
store i32 %10, i32* %2
%11 = call i32 (...) @read_byte()
store i32 %11, i32* %3
%12 = load i32, i32* %2
%13 = icmp eq i32 %12, -1
br i1 %13, label %17, label %14
14: ; preds = %8
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %14, %8
store i32 -1, i32* %1
br label %28
18: ; preds = %14
%19 = load i32, i32* %2
%20 = mul nsw i32 %19, 256
%21 = load i32, i32* %2
%22 = add nsw i32 %20, %21
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 255
br i1 %24, label %25, label %26
25: ; preds = %18
store i32 -3, i32* %1
br label %28
26: ; preds = %18
%27 = load i32, i32* %4
store i32 %27, i32* %1
br label %28
28: ; preds = %26, %25, %17, %7
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
define i32 @trim_read() {
%1 = tail call i32 @write_block(i32 32, i32 0, i32 0, i32 0)
%2 = icmp eq i32 %1, -1
br i1 %2, label %12, label %3
3: ; preds = %0
%4 = tail call i32 @pi_sleep(i32 80)
%5 = tail call i32 (...) @read_byte()
%6 = tail call i32 (...) @read_byte()
%7 = icmp eq i32 %5, -1
%8 = icmp eq i32 %6, -1
%9 = select i1 %7, i1 true, i1 %8
%10 = mul nsw i32 %5, 257
%11 = select i1 %9, i32 -1, i32 %10
br label %12
12: ; preds = %3, %0
%13 = phi i32 [ -1, %0 ], [ %11, %3 ]
ret i32 %13
}