#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 */
struct avfs_out_message {
  int dummy;
};
struct avfs_in_message {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int sock_send_message(int, struct avfs_out_message *, struct avfs_in_message *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int __av_send_message(struct avfs_out_message *out, struct avfs_in_message *in,
                      int keepsock) {
  int res;
  int sock;
  sock = socket(AF_UNIX, SOCK_STREAM, 0);
  if (sock == -1)
    return -1;
  res = sock_send_message(sock, out, in);
  if (res == -1)
    return -1;
  if (keepsock)
    return sock;
  else {
    close(sock);
    return 0;
  }
}


x86 assembly (clang, -O0):
<__av_send_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1175 <__av_send_message+0x45>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c2 <__av_send_message+0x92>
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <sock_send_message@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    119e <__av_send_message+0x6e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c2 <__av_send_message+0x92>
cmpl   $0x0,-0x1c(%rbp)
je     11b3 <__av_send_message+0x83>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c2 <__av_send_message+0x92>
mov    -0x24(%rbp),%edi
call   1030 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__av_send_message>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%r12
mov    0x2ea0(%rip),%rax
mov    (%rax),%edi
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <socket@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     118a <__av_send_message+0x5a>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r12,%rsi
mov    %r15,%rdx
call   1040 <sock_send_message@plt>
cmp    $0xffffffff,%eax
je     118a <__av_send_message+0x5a>
test   %r14d,%r14d
je     1181 <__av_send_message+0x51>
mov    %ebp,%ebx
jmp    118a <__av_send_message+0x5a>
mov    %ebp,%edi
call   1030 <close@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.avfs_out_message = type { i32 }
%struct.avfs_in_message = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
define i32 @__av_send_message(%struct.avfs_out_message* %0, %struct.avfs_in_message* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.avfs_out_message*
%6 = alloca %struct.avfs_in_message*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store %struct.avfs_out_message* %0, %struct.avfs_out_message** %5
store %struct.avfs_in_message* %1, %struct.avfs_in_message** %6
store i32 %2, i32* %7
%10 = load i32, i32* @AF_UNIX
%11 = load i32, i32* @SOCK_STREAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 -1, i32* %4
br label %32
16: ; preds = %3
%17 = load i32, i32* %9
%18 = load %struct.avfs_out_message*, %struct.avfs_out_message** %5
%19 = load %struct.avfs_in_message*, %struct.avfs_in_message** %6
%20 = call i32 @sock_send_message(i32 %17, %struct.avfs_out_message* %18, %struct.avfs_in_message* %19)
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %16
store i32 -1, i32* %4
br label %32
24: ; preds = %16
%25 = load i32, i32* %7
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = load i32, i32* %9
store i32 %28, i32* %4
br label %32
29: ; preds = %24
%30 = load i32, i32* %9
%31 = call i32 @close(i32 %30)
store i32 0, i32* %4
br label %32
32: ; preds = %29, %27, %23, %15
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
%struct.avfs_out_message = type { i32 }
%struct.avfs_in_message = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
define i32 @__av_send_message(%struct.avfs_out_message* %0, %struct.avfs_in_message* %1, i32 %2) {
%4 = load i32, i32* @AF_UNIX
%5 = load i32, i32* @SOCK_STREAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %15, label %8
8: ; preds = %3
%9 = tail call i32 @sock_send_message(i32 %6, %struct.avfs_out_message* %0, %struct.avfs_in_message* %1)
%10 = icmp eq i32 %9, -1
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = icmp eq i32 %2, 0
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = tail call i32 @close(i32 %6)
br label %15
15: ; preds = %11, %8, %3, %13
%16 = phi i32 [ 0, %13 ], [ -1, %3 ], [ -1, %8 ], [ %6, %11 ]
ret i32 %16
}