#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 sockaddr_un {
  int /*<<< orphan*/ sun_path;
  void *sun_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
void *AF_UNIX;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ bind(int, struct sockaddr const *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int /*<<< orphan*/ unlink(char *);
int main(void) {
  int socket_fd;
  struct sockaddr_un server_address;
  struct sockaddr_un client_address;
  int bytes_received, bytes_sent, integer_buffer;
  socklen_t address_length;
  if ((socket_fd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) {
    perror("client: socket");
    return 1;
  }
  memset(&client_address, 0, sizeof(struct sockaddr_un));
  client_address.sun_family = AF_UNIX;
  strcpy(client_address.sun_path, "/tmp/CI_UNIX_SOCK_CLIENT");
  unlink("/tmp/CI_UNIX_SOCK_CLIENT");
  if (bind(socket_fd, (const struct sockaddr *)&client_address,
           sizeof(struct sockaddr_un)) < 0) {
    perror("client: bind");
    return 1;
  }
  memset(&server_address, 0, sizeof(struct sockaddr_un));
  server_address.sun_family = AF_UNIX;
  strcpy(server_address.sun_path, "/tmp/CI_UNIX_SOCK_SRV");
  integer_buffer = 5;
  bytes_sent =
      sendto(socket_fd, (char *)&integer_buffer, sizeof(int), 0,
             (struct sockaddr *)&server_address, sizeof(struct sockaddr_un));
  close(socket_fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%rdi
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11cd <main+0x4d>
lea    0xe44(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    129c <main+0x11c>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%edi
lea    0xe1a(%rip),%rsi
call   1040 <strcpy@plt>
lea    0xe0e(%rip),%rdi
call   1030 <unlink@plt>
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   1080 <bind@plt>
cmp    $0x0,%rax
jge    1239 <main+0xb9>
lea    0xe00(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    129c <main+0x11c>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%edi
lea    0xdd4(%rip),%rsi
call   1040 <strcpy@plt>
movl   $0x5,-0x34(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x34(%rbp),%rsi
lea    -0x18(%rbp),%r8
mov    $0x4,%edx
xor    %ecx,%ecx
mov    $0x10,%r9d
call   1060 <sendto@plt>
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    0x2e55(%rip),%r12
mov    (%r12),%rdi
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
test   %eax,%eax
js     1268 <main+0xe8>
mov    %eax,%ebp
lea    0x10(%rsp),%r15
xor    %r14d,%r14d
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    (%r12),%rax
mov    %rax,0x18(%rsp)
mov    0x10(%rsp),%edi
lea    0xe33(%rip),%rbx
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x10,%edx
call   1080 <bind@plt>
test   %rax,%rax
js     1271 <main+0xf1>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    (%r12),%rax
mov    %rax,0x28(%rsp)
mov    0x20(%rsp),%edi
lea    0xe0d(%rip),%rsi
call   1040 <strcpy@plt>
movl   $0x5,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
mov    $0x10,%r9d
call   1060 <sendto@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    %r14d,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd91(%rip),%rdi
jmp    1278 <main+0xf8>
lea    0xdb0(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%r14d
jmp    1258 <main+0xd8>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i8* }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i8* null
@SOCK_DGRAM = global i32 0
@.str = [15 x i8] c"client: socket\00"
@.str.1 = [25 x i8] c"/tmp/CI_UNIX_SOCK_CLIENT\00"
@.str.2 = [13 x i8] c"client: bind\00"
@.str.3 = [22 x i8] c"/tmp/CI_UNIX_SOCK_SRV\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_un
%4 = alloca %struct.sockaddr_un
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = load i8*, i8** @AF_UNIX
%10 = load i32, i32* @SOCK_DGRAM
%11 = call i32 @socket(i8* %9, i32 %10, i32 0)
store i32 %11, i32* %2
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %42
15: ; preds = %0
%16 = call i32 @memset(%struct.sockaddr_un* %4, i32 0, i32 16)
%17 = load i8*, i8** @AF_UNIX
%18 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 1
store i8* %17, i8** %18
%19 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @strcpy(i32 %20, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @unlink(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* %2
%24 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%25 = call i64 @bind(i32 %23, %struct.sockaddr* %24, i32 16)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %15
%28 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %42
29: ; preds = %15
%30 = call i32 @memset(%struct.sockaddr_un* %3, i32 0, i32 16)
%31 = load i8*, i8** @AF_UNIX
%32 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i32 0, i32 1
store i8* %31, i8** %32
%33 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i32 0, i32 0
%34 = load i32, i32* %33
%35 = call i32 @strcpy(i32 %34, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
store i32 5, i32* %7
%36 = load i32, i32* %2
%37 = bitcast i32* %7 to i8*
%38 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%39 = call i32 @sendto(i32 %36, i8* %37, i32 4, i32 0, %struct.sockaddr* %38, i32 16)
store i32 %39, i32* %6
%40 = load i32, i32* %2
%41 = call i32 @close(i32 %40)
store i32 0, i32* %1
br label %42
42: ; preds = %29, %27, %13
%43 = load i32, i32* %1
ret i32 %43
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i8* }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i8* null
@SOCK_DGRAM = global i32 0
@.str = [15 x i8] c"client: socket\00"
@.str.1 = [25 x i8] c"/tmp/CI_UNIX_SOCK_CLIENT\00"
@.str.2 = [13 x i8] c"client: bind\00"
@.str.3 = [22 x i8] c"/tmp/CI_UNIX_SOCK_SRV\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_un
%2 = alloca %struct.sockaddr_un
%3 = alloca i32
%4 = bitcast %struct.sockaddr_un* %1 to i8*
%5 = bitcast %struct.sockaddr_un* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = load i8*, i8** @AF_UNIX
%8 = load i32, i32* @SOCK_DGRAM
%9 = tail call i32 @socket(i8* %7, i32 %8, i32 0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %36
13: ; preds = %0
%14 = call i32 @memset(%struct.sockaddr_un* %2, i32 0, i32 16)
%15 = load i8*, i8** @AF_UNIX
%16 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 1
store i8* %15, i8** %16
%17 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 0
%18 = load i32, i32* %17
%19 = call i32 @strcpy(i32 %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @unlink(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%21 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%22 = call i64 @bind(i32 %9, %struct.sockaddr* %21, i32 16)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %13
%25 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %36
26: ; preds = %13
%27 = call i32 @memset(%struct.sockaddr_un* %1, i32 0, i32 16)
%28 = load i8*, i8** @AF_UNIX
%29 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 1
store i8* %28, i8** %29
%30 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 0
%31 = load i32, i32* %30
%32 = call i32 @strcpy(i32 %31, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
store i32 5, i32* %3
%33 = bitcast %struct.sockaddr_un* %1 to %struct.sockaddr*
%34 = call i32 @sendto(i32 %9, i8* %6, i32 4, i32 0, %struct.sockaddr* %33, i32 16)
%35 = call i32 @close(i32 %9)
br label %36
36: ; preds = %26, %24, %11
%37 = phi i32 [ 1, %11 ], [ 1, %24 ], [ 0, %26 ]
ret i32 %37
}