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

/* Variables and functions */
scalar_t__ bfdmonClient_NotifyReadAndDispatch(int, int *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(int);
int /*<<< orphan*/ tpRmSktActor(int);
int /*<<< orphan*/ tpStopEventLoop();
void monitorSktActor(int sock, void *arg) {
  ssize_t res;
  int local_errno = 0;
  res = bfdmonClient_NotifyReadAndDispatch(sock, &local_errno);
  if (res < 0) {
    fprintf(stderr, "failed in read(): %s\n", strerror(local_errno));
    exit(1);
  } else if (res == 0) {
    close(sock);
    tpRmSktActor(sock);
    tpStopEventLoop();
    fprintf(stderr, "Connection to monitor server closed.\n");
  }
}


x86 assembly (clang, -O0):
<monitorSktActor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   1040 <bfdmonClient_NotifyReadAndDispatch@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    11d3 <monitorSktActor+0x63>
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1080 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jne    120c <monitorSktActor+0x9c>
mov    -0x4(%rbp),%edi
call   1030 <close@plt>
mov    -0x4(%rbp),%edi
call   1090 <tpRmSktActor@plt>
mov    $0x0,%al
call   1060 <tpStopEventLoop@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
lea    0xe11(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1211 <monitorSktActor+0xa1>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<monitorSktActor>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rsi
call   1040 <bfdmonClient_NotifyReadAndDispatch@plt>
test   %rax,%rax
js     11c2 <monitorSktActor+0x52>
jne    11bc <monitorSktActor+0x4c>
mov    %ebx,%edi
call   1030 <close@plt>
mov    %ebx,%edi
call   1090 <tpRmSktActor@plt>
xor    %eax,%eax
call   1060 <tpStopEventLoop@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e17(%rip),%rax
mov    (%rax),%ebx
mov    0xc(%rsp),%edi
call   1080 <strerror@plt>
lea    0xe25(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"failed in read(): %s\0A\00"
@.str.1 = [38 x i8] c"Connection to monitor server closed.\0A\00"
define void @monitorSktActor(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 0, i32* %6
%7 = load i32, i32* %3
%8 = call i64 @bfdmonClient_NotifyReadAndDispatch(i32 %7, i32* %6)
store i64 %8, i64* %5
%9 = load i64, i64* %5
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i32, i32* %6
%14 = call i8* @strerror(i32 %13)
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i64, i64* %5
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %17
%21 = load i32, i32* %3
%22 = call i32 @close(i32 %21)
%23 = load i32, i32* %3
%24 = call i32 @tpRmSktActor(i32 %23)
%25 = call i32 (...) @tpStopEventLoop()
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %20, %17
br label %29
29: ; preds = %28
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"failed in read(): %s\0A\00"
@.str.1 = [38 x i8] c"Connection to monitor server closed.\0A\00"
define void @monitorSktActor(i32 %0, i8* nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = call i64 @bfdmonClient_NotifyReadAndDispatch(i32 %0, i32* %3)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i32, i32* %3
%10 = call i8* @strerror(i32 %9)
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = icmp eq i64 %5, 0
br i1 %14, label %15, label %21
15: ; preds = %13
%16 = call i32 @close(i32 %0)
%17 = call i32 @tpRmSktActor(i32 %0)
%18 = call i32 (...) @tpStopEventLoop()
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %13, %15
ret void
}