#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 /*<<< orphan*/ status;

/* Variables and functions */
int write(int, void *, int);
int bme_reply_client(int client, int status, void *msg, int size) {
  if (write(client, &status, sizeof(status)) != sizeof(status))
    return -1;
  if (write(client, msg, size) != size)
    return -1;
  return size;
}


x86 assembly (clang, -O0):
<bme_reply_client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cltq
cmp    $0x4,%rax
je     114e <bme_reply_client+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1178 <bme_reply_client+0x68>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <write@plt>
cmp    -0x1c(%rbp),%eax
je     1172 <bme_reply_client+0x62>
movl   $0xffffffff,-0x4(%rbp)
jmp    1178 <bme_reply_client+0x68>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bme_reply_client>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%ebx
mov    %rdx,%r14
mov    %edi,%ebp
mov    %esi,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x4,%ecx
jne    1154 <bme_reply_client+0x44>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
cmp    %ebx,%eax
mov    $0xffffffff,%eax
cmove  %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bme_reply_client(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%10 = load i32, i32* %6
%11 = bitcast i32* %7 to i8*
%12 = call i32 @write(i32 %10, i8* %11, i32 4)
%13 = sext i32 %12 to i64
%14 = icmp ne i64 %13, 4
br i1 %14, label %15, label %16
15: ; preds = %4
store i32 -1, i32* %5
br label %26
16: ; preds = %4
%17 = load i32, i32* %6
%18 = load i8*, i8** %8
%19 = load i32, i32* %9
%20 = call i32 @write(i32 %17, i8* %18, i32 %19)
%21 = load i32, i32* %9
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %16
store i32 -1, i32* %5
br label %26
24: ; preds = %16
%25 = load i32, i32* %9
store i32 %25, i32* %5
br label %26
26: ; preds = %24, %23, %15
%27 = load i32, i32* %5
ret i32 %27
}

LLVM IR (-O2):
define i32 @bme_reply_client(i32 %0, i32 %1, i8* nocapture %2, i32 %3) {
%5 = alloca i32
store i32 %1, i32* %5
%6 = bitcast i32* %5 to i8*
%7 = call i32 @write(i32 %0, i8* %6, i32 4)
%8 = icmp eq i32 %7, 4
br i1 %8, label %9, label %13
9: ; preds = %4
%10 = tail call i32 @write(i32 %0, i8* %2, i32 %3)
%11 = icmp eq i32 %10, %3
%12 = select i1 %11, i32 %3, i32 -1
br label %13
13: ; preds = %9, %4
%14 = phi i32 [ -1, %4 ], [ %12, %9 ]
ret i32 %14
}