#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 */
scalar_t__ EWOULDBLOCK;
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
scalar_t__ feof(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int fread(int *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ slave_exec(int);
int /*<<< orphan*/ slave_set_blocking_io(int /*<<< orphan*/, int);
int /*<<< orphan*/ stdin;
void slave_update() {
  slave_set_blocking_io(stdin, 0);
  int ret;
  int command_id;
  ret = (fread(&command_id, sizeof(*&command_id), 1, stdin));
  if (feof(stdin)) {
    return;
  }
  if (ret <= 0 && errno == EWOULDBLOCK) {
    return;
  }
  assert(ret == 1);
  slave_set_blocking_io(stdin, 1);
  slave_exec(command_id);
  fflush(0);
}


x86 assembly (clang, -O0):
<slave_update>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1070 <slave_set_blocking_io@plt>
mov    0x2e69(%rip),%rax
mov    (%rax),%ecx
lea    -0x8(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,-0x4(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     11b4 <slave_update+0x54>
jmp    1210 <slave_update+0xb0>
cmpl   $0x0,-0x4(%rbp)
jg     11dd <slave_update+0x7d>
mov    0x2e13(%rip),%rax
mov    (%rax),%rax
mov    0x2e01(%rip),%rcx
cmp    (%rcx),%rax
jne    11dd <slave_update+0x7d>
jmp    1210 <slave_update+0xb0>
cmpl   $0x1,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1070 <slave_set_blocking_io@plt>
mov    -0x8(%rbp),%edi
call   1080 <slave_exec@plt>
xor    %edi,%edi
call   1060 <fflush@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<slave_update>:
push   %r14
push   %rbx
push   %rax
mov    0x2e7d(%rip),%r14
mov    (%r14),%edi
xor    %esi,%esi
call   1070 <slave_set_blocking_io@plt>
mov    (%r14),%ecx
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,%ebx
mov    (%r14),%edi
call   1050 <feof@plt>
test   %rax,%rax
jne    11e0 <slave_update+0x80>
test   %ebx,%ebx
jg     11b5 <slave_update+0x55>
mov    0x2e32(%rip),%rax
mov    (%rax),%rax
mov    0x2e20(%rip),%rcx
cmp    (%rcx),%rax
je     11e0 <slave_update+0x80>
xor    %edi,%edi
cmp    $0x1,%ebx
sete   %dil
call   1040 <assert@plt>
mov    (%r14),%edi
mov    $0x1,%esi
call   1070 <slave_set_blocking_io@plt>
mov    0x4(%rsp),%edi
call   1080 <slave_exec@plt>
xor    %edi,%edi
call   1060 <fflush@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stdin = global i32 0
@errno = global i64 0
@EWOULDBLOCK = global i64 0
define void @slave_update() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @stdin
%4 = call i32 @slave_set_blocking_io(i32 %3, i32 0)
%5 = load i32, i32* @stdin
%6 = call i32 @fread(i32* %2, i32 4, i32 1, i32 %5)
store i32 %6, i32* %1
%7 = load i32, i32* @stdin
%8 = call i64 @feof(i32 %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %0
br label %29
11: ; preds = %0
%12 = load i32, i32* %1
%13 = icmp sle i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i64, i64* @errno
%16 = load i64, i64* @EWOULDBLOCK
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %14
br label %29
19: ; preds = %14, %11
%20 = load i32, i32* %1
%21 = icmp eq i32 %20, 1
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = load i32, i32* @stdin
%25 = call i32 @slave_set_blocking_io(i32 %24, i32 1)
%26 = load i32, i32* %2
%27 = call i32 @slave_exec(i32 %26)
%28 = call i32 @fflush(i32 0)
br label %29
29: ; preds = %19, %18, %10
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@errno = global i64 0
@EWOULDBLOCK = global i64 0
define void @slave_update() {
%1 = alloca i32
%2 = load i32, i32* @stdin
%3 = tail call i32 @slave_set_blocking_io(i32 %2, i32 0)
%4 = bitcast i32* %1 to i8*
%5 = load i32, i32* @stdin
%6 = call i32 @fread(i32* %1, i32 4, i32 1, i32 %5)
%7 = load i32, i32* @stdin
%8 = call i64 @feof(i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %25
10: ; preds = %0
%11 = icmp slt i32 %6, 1
br i1 %11, label %12, label %16
12: ; preds = %10
%13 = load i64, i64* @errno
%14 = load i64, i64* @EWOULDBLOCK
%15 = icmp eq i64 %13, %14
br i1 %15, label %25, label %16
16: ; preds = %12, %10
%17 = icmp eq i32 %6, 1
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i32, i32* @stdin
%21 = call i32 @slave_set_blocking_io(i32 %20, i32 1)
%22 = load i32, i32* %1
%23 = call i32 @slave_exec(i32 %22)
%24 = call i32 @fflush(i32 0)
br label %25
25: ; preds = %12, %0, %16
ret void
}