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

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
scalar_t__ errno;
int read(int, char *, int);
__attribute__((noreturn)) void *
daemon_close_notify_thread(void *_close_notify_fd) {
  int close_notify_fd = (int)((char *)_close_notify_fd - (char *)NULL);
  char b;
  ssize_t r;
Redo:
  r = read(close_notify_fd, &b, 1);
  if (r == -1 && errno == EINTR)
    goto Redo;
  if (r > 0)
    goto Redo;
  _exit(0);
}


x86 assembly (clang, -O0):
<daemon_close_notify_thread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
sub    $0x0,%rax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1174 <daemon_close_notify_thread+0x54>
mov    0x2e84(%rip),%rax
mov    (%rax),%rax
mov    0x2e72(%rip),%rcx
cmp    (%rcx),%rax
jne    1174 <daemon_close_notify_thread+0x54>
jmp    1137 <daemon_close_notify_thread+0x17>
cmpl   $0x0,-0x14(%rbp)
jle    1183 <daemon_close_notify_thread+0x63>
jmp    1137 <daemon_close_notify_thread+0x17>
xor    %edi,%edi
call   1030 <_exit@plt>

x86 assembly (clang, -O2):
<daemon_close_notify_thread>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0x7(%rsp),%r14
mov    0x2ea9(%rip),%r15
mov    0x2e9a(%rip),%r12
jmp    1149 <daemon_close_notify_thread+0x29>
mov    (%r15),%rax
cmp    (%r12),%rax
jne    1161 <daemon_close_notify_thread+0x41>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0xffffffff,%eax
je     1140 <daemon_close_notify_thread+0x20>
test   %eax,%eax
jg     1149 <daemon_close_notify_thread+0x29>
xor    %edi,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
define i8* @daemon_close_notify_thread(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = ptrtoint i8* %6 to i64
%8 = sub i64 %7, 0
%9 = trunc i64 %8 to i32
store i32 %9, i32* %3
br label %10
10: ; preds = %23, %19, %1
%11 = load i32, i32* %3
%12 = call i32 @read(i32 %11, i8* %4, i32 1)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = load i64, i64* @errno
%17 = load i64, i64* @EINTR
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %15
br label %10
20: ; preds = %15, %10
%21 = load i32, i32* %5
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %20
br label %10
24: ; preds = %20
%25 = call i32 @_exit(i32 0)
unreachable
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
define noalias i8* @daemon_close_notify_thread(i8* %0) {
%2 = alloca i8
%3 = ptrtoint i8* %0 to i64
%4 = trunc i64 %3 to i32
br label %5
5: ; preds = %12, %1
%6 = call i32 @read(i32 %4, i8* %2, i32 1)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = load i64, i64* @errno
%10 = load i64, i64* @EINTR
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %15
12: ; preds = %8, %13
br label %5
13: ; preds = %5
%14 = icmp sgt i32 %6, 0
br i1 %14, label %12, label %15
15: ; preds = %8, %13
%16 = tail call i32 @_exit(i32 0)
unreachable
}