#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*/ AF_LOCAL;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ socket_sendmmsg(int, char *);
int socketpair(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
               int *);
void sendmmsg_kmalloc_kfree(int port, char *buffer) {
  int sock[2];
  int rv = socketpair(AF_LOCAL, SOCK_DGRAM, 0, sock);
  if (rv != 0) {
    perror("socketpair()");
    exit(EXIT_FAILURE);
  }
  socket_sendmmsg(sock[0], buffer);
  close(sock[0]);
}


x86 assembly (clang, -O0):
<sendmmsg_kmalloc_kfree>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rcx
xor    %edx,%edx
call   1040 <socketpair@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11a3 <sendmmsg_kmalloc_kfree+0x53>
lea    0xe70(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <socket_sendmmsg@plt>
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendmmsg_kmalloc_kfree>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rcx
xor    %edx,%edx
call   1040 <socketpair@plt>
test   %eax,%eax
jne    1195 <sendmmsg_kmalloc_kfree+0x45>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
call   1050 <socket_sendmmsg@plt>
mov    0x8(%rsp),%edi
call   1030 <close@plt>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe64(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@AF_LOCAL = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [13 x i8] c"socketpair()\00"
@EXIT_FAILURE = global i32 0
define void @sendmmsg_kmalloc_kfree(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [2 x i32]
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = load i32, i32* @AF_LOCAL
%8 = load i32, i32* @SOCK_DGRAM
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%10 = call i32 @socketpair(i32 %7, i32 %8, i32 0, i32* %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%19 = load i32, i32* %18
%20 = load i8*, i8** %4
%21 = call i32 @socket_sendmmsg(i32 %19, i8* %20)
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%23 = load i32, i32* %22
%24 = call i32 @close(i32 %23)
ret void
}

LLVM IR (-O2):
@AF_LOCAL = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [13 x i8] c"socketpair()\00"
@EXIT_FAILURE = global i32 0
define void @sendmmsg_kmalloc_kfree(i32 %0, i8* %1) {
%3 = alloca [2 x i32]
%4 = bitcast [2 x i32]* %3 to i8*
%5 = load i32, i32* @AF_LOCAL
%6 = load i32, i32* @SOCK_DGRAM
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%8 = call i32 @socketpair(i32 %5, i32 %6, i32 0, i32* %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = load i32, i32* %7
%16 = call i32 @socket_sendmmsg(i32 %15, i8* %1)
%17 = load i32, i32* %7
%18 = call i32 @close(i32 %17)
ret void
}