#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;
typedef int /*<<< orphan*/ int32_t;

/* Variables and functions */
int bme_read(int /*<<< orphan*/, void *, int);
int bme_write(int /*<<< orphan*/, void const *, int);
int bme_send_get_reply(int32_t sd, const void *smsg, int sbytes, void *rmsg,
                       int rbytes, int *rbytes_act) {
  int status, nb;
  if (bme_write(sd, smsg, sbytes) != sbytes)
    return -1;
  if (bme_read(sd, &status, sizeof(status)) == -1)
    return -1;
  if (status >= 0 && rmsg && rbytes) {
    nb = bme_read(sd, rmsg, rbytes);
    if (nb == -1)
      return -1;
    if (rbytes_act)
      *rbytes_act = nb;
  }
  return status;
}


x86 assembly (clang, -O0):
<bme_send_get_reply>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <bme_write@plt>
cmp    -0x14(%rbp),%eax
je     1162 <bme_send_get_reply+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ee <bme_send_get_reply+0xce>
mov    -0x8(%rbp),%edi
lea    -0x34(%rbp),%rsi
mov    $0x4,%edx
call   1040 <bme_read@plt>
cmp    $0xffffffff,%eax
jne    1188 <bme_send_get_reply+0x68>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ee <bme_send_get_reply+0xce>
cmpl   $0x0,-0x34(%rbp)
jl     11e8 <bme_send_get_reply+0xc8>
cmpq   $0x0,-0x20(%rbp)
je     11e8 <bme_send_get_reply+0xc8>
cmpl   $0x0,-0x24(%rbp)
je     11e8 <bme_send_get_reply+0xc8>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <bme_read@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0xffffffff,-0x38(%rbp)
jne    11cf <bme_send_get_reply+0xaf>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ee <bme_send_get_reply+0xce>
cmpq   $0x0,-0x30(%rbp)
je     11e3 <bme_send_get_reply+0xc3>
mov    -0x38(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
jmp    11e8 <bme_send_get_reply+0xc8>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bme_send_get_reply>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r14
mov    %r8d,%r12d
mov    %rcx,%r15
mov    %edx,%ebp
mov    %edi,%ebx
call   1030 <bme_write@plt>
mov    $0xffffffff,%r13d
cmp    %ebp,%eax
jne    118d <bme_send_get_reply+0x6d>
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1040 <bme_read@plt>
cmp    $0xffffffff,%eax
je     118d <bme_send_get_reply+0x6d>
test   %r12d,%r12d
je     1188 <bme_send_get_reply+0x68>
test   %r15,%r15
je     1188 <bme_send_get_reply+0x68>
cmpl   $0x0,0x4(%rsp)
js     1188 <bme_send_get_reply+0x68>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r12d,%edx
call   1040 <bme_read@plt>
cmp    $0xffffffff,%eax
je     118d <bme_send_get_reply+0x6d>
test   %r14,%r14
je     1188 <bme_send_get_reply+0x68>
mov    %eax,(%r14)
mov    0x4(%rsp),%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bme_send_get_reply(i32 %0, i8* %1, i32 %2, i8* %3, i32 %4, i32* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
store i32 %0, i32* %8
store i8* %1, i8** %9
store i32 %2, i32* %10
store i8* %3, i8** %11
store i32 %4, i32* %12
store i32* %5, i32** %13
%16 = load i32, i32* %8
%17 = load i8*, i8** %9
%18 = load i32, i32* %10
%19 = call i32 @bme_write(i32 %16, i8* %17, i32 %18)
%20 = load i32, i32* %10
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %6
store i32 -1, i32* %7
br label %55
23: ; preds = %6
%24 = load i32, i32* %8
%25 = bitcast i32* %14 to i8*
%26 = call i32 @bme_read(i32 %24, i8* %25, i32 4)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %29
28: ; preds = %23
store i32 -1, i32* %7
br label %55
29: ; preds = %23
%30 = load i32, i32* %14
%31 = icmp sge i32 %30, 0
br i1 %31, label %32, label %53
32: ; preds = %29
%33 = load i8*, i8** %11
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %53
35: ; preds = %32
%36 = load i32, i32* %12
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %53
38: ; preds = %35
%39 = load i32, i32* %8
%40 = load i8*, i8** %11
%41 = load i32, i32* %12
%42 = call i32 @bme_read(i32 %39, i8* %40, i32 %41)
store i32 %42, i32* %15
%43 = load i32, i32* %15
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %46
45: ; preds = %38
store i32 -1, i32* %7
br label %55
46: ; preds = %38
%47 = load i32*, i32** %13
%48 = icmp ne i32* %47, null
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = load i32, i32* %15
%51 = load i32*, i32** %13
store i32 %50, i32* %51
br label %52
52: ; preds = %49, %46
br label %53
53: ; preds = %52, %35, %32, %29
%54 = load i32, i32* %14
store i32 %54, i32* %7
br label %55
55: ; preds = %53, %45, %28, %22
%56 = load i32, i32* %7
ret i32 %56
}

LLVM IR (-O2):
define i32 @bme_send_get_reply(i32 %0, i8* %1, i32 %2, i8* %3, i32 %4, i32* writeonly %5) {
%7 = alloca i32
%8 = bitcast i32* %7 to i8*
%9 = tail call i32 @bme_write(i32 %0, i8* %1, i32 %2)
%10 = icmp eq i32 %9, %2
br i1 %10, label %11, label %29
11: ; preds = %6
%12 = call i32 @bme_read(i32 %0, i8* %8, i32 4)
%13 = icmp eq i32 %12, -1
br i1 %13, label %29, label %14
14: ; preds = %11
%15 = load i32, i32* %7
%16 = icmp sgt i32 %15, -1
%17 = icmp ne i8* %3, null
%18 = and i1 %17, %16
%19 = icmp ne i32 %4, 0
%20 = and i1 %19, %18
br i1 %20, label %21, label %27
21: ; preds = %14
%22 = call i32 @bme_read(i32 %0, i8* %3, i32 %4)
%23 = icmp eq i32 %22, -1
br i1 %23, label %29, label %24
24: ; preds = %21
%25 = icmp eq i32* %5, null
br i1 %25, label %27, label %26
26: ; preds = %24
store i32 %22, i32* %5
br label %27
27: ; preds = %24, %26, %14
%28 = load i32, i32* %7
br label %29
29: ; preds = %21, %11, %6, %27
%30 = phi i32 [ %28, %27 ], [ -1, %6 ], [ -1, %11 ], [ -1, %21 ]
ret i32 %30
}