#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*/ close(int);
int read(int, unsigned char *, int);
int send(int, void *, int, int /*<<< orphan*/);
int writeTossimEvent(void *data, int datalen, int clifd) {
  unsigned char ack;
  int i, j;
  ;
  j = 0;
  i = send(clifd, data, datalen, 0);
  ;
  if (i >= 0)
    j = read(clifd, &ack, 1);
  ;
  if ((i < 0) || (j < 0)) {
    ;
    close(clifd);
    return -1;
  };
  return 0;
}


x86 assembly (clang, -O0):
<writeTossimEvent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jl     117b <writeTossimEvent+0x4b>
mov    -0x18(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x20(%rbp)
jl     118f <writeTossimEvent+0x5f>
cmpl   $0x0,-0x24(%rbp)
jge    11a3 <writeTossimEvent+0x73>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11aa <writeTossimEvent+0x7a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeTossimEvent>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%edx
mov    %rdi,%rsi
xor    %ebp,%ebp
mov    %ebx,%edi
xor    %ecx,%ecx
call   1030 <send@plt>
test   %eax,%eax
js     115e <writeTossimEvent+0x2e>
lea    0x7(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1050 <read@plt>
test   %eax,%eax
jns    116a <writeTossimEvent+0x3a>
mov    %ebx,%edi
call   1040 <close@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @writeTossimEvent(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 0, i32* %10
%11 = load i32, i32* %7
%12 = load i8*, i8** %5
%13 = load i32, i32* %6
%14 = call i32 @send(i32 %11, i8* %12, i32 %13, i32 0)
store i32 %14, i32* %9
%15 = load i32, i32* %9
%16 = icmp sge i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = load i32, i32* %7
%19 = call i32 @read(i32 %18, i8* %8, i32 1)
store i32 %19, i32* %10
br label %20
20: ; preds = %17, %3
%21 = load i32, i32* %9
%22 = icmp slt i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i32, i32* %10
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23, %20
%27 = load i32, i32* %7
%28 = call i32 @close(i32 %27)
store i32 -1, i32* %4
br label %30
29: ; preds = %23
store i32 0, i32* %4
br label %30
30: ; preds = %29, %26
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
define i32 @writeTossimEvent(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8
%5 = tail call i32 @send(i32 %2, i8* %0, i32 %1, i32 0)
%6 = icmp sgt i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = call i32 @read(i32 %2, i8* %4, i32 1)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %3, %7
%11 = tail call i32 @close(i32 %2)
br label %12
12: ; preds = %7, %10
%13 = phi i32 [ -1, %10 ], [ 0, %7 ]
ret i32 %13
}