#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 uint64_t;

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ EINTR;
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
int write(int, int *, int);
void spy_finish_work_notify(int event_fd) {
  int ret;
  uint64_t dummy = 1;
  do {
    ret = write(event_fd, &dummy, 8);
  } while (ret < 0 && (errno == EAGAIN || errno == EINTR));
  assert(ret >= 0);
}


x86 assembly (clang, -O0):
<spy_finish_work_notify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x4(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    %eax,-0x8(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0xd(%rbp)
jge    1194 <spy_finish_work_notify+0x74>
mov    0x2e84(%rip),%rax
mov    (%rax),%rcx
mov    $0x1,%al
mov    0x2e60(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0xe(%rbp)
je     118e <spy_finish_work_notify+0x6e>
mov    0x2e65(%rip),%rax
mov    (%rax),%rax
mov    0x2e53(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0xe(%rbp)
mov    -0xe(%rbp),%al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1132 <spy_finish_work_notify+0x12>
cmpl   $0x0,-0x8(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spy_finish_work_notify>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movl   $0x1,0xc(%rsp)
lea    0xc(%rsp),%r14
mov    0x2e9d(%rip),%r15
mov    0x2e7e(%rip),%r12
mov    0x2e87(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1030 <write@plt>
test   %eax,%eax
jns    1182 <spy_finish_work_notify+0x62>
mov    (%r15),%rcx
cmp    (%r12),%rcx
je     1160 <spy_finish_work_notify+0x40>
cmp    0x0(%r13),%rcx
je     1160 <spy_finish_work_notify+0x40>
not    %eax
shr    $0x1f,%eax
mov    %eax,%edi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <assert@plt>

LLVM IR (-O0):
@errno = global i64 0
@EAGAIN = global i64 0
@EINTR = global i64 0
define void @spy_finish_work_notify(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 1, i32* %4
br label %5
5: ; preds = %21, %1
%6 = load i32, i32* %2
%7 = call i32 @write(i32 %6, i32* %4, i32 8)
store i32 %7, i32* %3
br label %8
8: ; preds = %5
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %8
%12 = load i64, i64* @errno
%13 = load i64, i64* @EAGAIN
%14 = icmp eq i64 %12, %13
br i1 %14, label %19, label %15
15: ; preds = %11
%16 = load i64, i64* @errno
%17 = load i64, i64* @EINTR
%18 = icmp eq i64 %16, %17
br label %19
19: ; preds = %15, %11
%20 = phi i1 [ true, %11 ], [ %18, %15 ]
br label %21
21: ; preds = %19, %8
%22 = phi i1 [ false, %8 ], [ %20, %19 ]
br i1 %22, label %5, label %23
23: ; preds = %21
%24 = load i32, i32* %3
%25 = icmp sge i32 %24, 0
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@EAGAIN = global i64 0
@EINTR = global i64 0
define void @spy_finish_work_notify(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 1, i32* %2
br label %4
4: ; preds = %7, %1
%5 = call i32 @write(i32 %0, i32* %2, i32 8)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %4
%8 = load i64, i64* @errno
%9 = load i64, i64* @EAGAIN
%10 = icmp eq i64 %8, %9
%11 = load i64, i64* @EINTR
%12 = icmp eq i64 %8, %11
%13 = select i1 %10, i1 true, i1 %12
br i1 %13, label %4, label %14
14: ; preds = %4, %7
%15 = xor i32 %5, -1
%16 = lshr i32 %15, 31
%17 = tail call i32 @assert(i32 %16)
ret void
}