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

/* Variables and functions */
int ntohl(unsigned int);
int recv_safe(int, unsigned int *, int);
int send_msg(int, int, int, size_t, void const *);
int send_msg_recv_ret(int sock, int type, int op, size_t send_len,
                      const void *send_buf) {
  int ret;
  unsigned err_num;
  ret = send_msg(sock, type, op, send_len, send_buf);
  if (!ret) {
    ret = recv_safe(sock, &err_num, sizeof(err_num));
    if (!ret) {
      ret = -ntohl(err_num);
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<send_msg_recv_ret>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   1040 <send_msg@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11a0 <send_msg_recv_ret+0x70>
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1030 <recv_safe@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    119b <send_msg_recv_ret+0x6b>
mov    -0x28(%rbp),%edi
call   1050 <ntohl@plt>
mov    %eax,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
jmp    11a0 <send_msg_recv_ret+0x70>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_msg_recv_ret>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
call   1040 <send_msg@plt>
test   %eax,%eax
jne    1160 <send_msg_recv_ret+0x30>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <recv_safe@plt>
test   %eax,%eax
jne    1160 <send_msg_recv_ret+0x30>
mov    0xc(%rsp),%edi
call   1050 <ntohl@plt>
neg    %eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @send_msg_recv_ret(i32 %0, i32 %1, i32 %2, i64 %3, i8* %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
%8 = tail call i32 @send_msg(i32 %0, i32 %1, i32 %2, i64 %3, i8* %4)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %5
%11 = call i32 @recv_safe(i32 %0, i32* %6, i32 4)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i32, i32* %6
%15 = call i32 @ntohl(i32 %14)
%16 = sub nsw i32 0, %15
br label %17
17: ; preds = %10, %13, %5
%18 = phi i32 [ %8, %5 ], [ %11, %10 ], [ %16, %13 ]
ret i32 %18
}