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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ report_error();
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
void stub1(int);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
void client_socket(char *address, void (*functionPtr)(int)) {
  struct sockaddr_un remote;
  int socketfd = socket(AF_UNIX, SOCK_STREAM, 0);
  if (socketfd == -1) {
    syslog(LOG_ERR, "Could not create socket.");
    report_error();
    exit(EXIT_FAILURE);
  }
  remote.sun_family = AF_UNIX;
  strcpy(remote.sun_path, address);
  int status = connect(socketfd, (struct sockaddr *)&remote, sizeof(remote));
  if (status == -1) {
    syslog(LOG_ERR, "Could not listen at socket.");
    report_error();
    exit(EXIT_FAILURE);
  }
  (*functionPtr)(socketfd);
  close(socketfd);
}


x86 assembly (clang, -O0):
<client_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11d0 <client_socket+0x60>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
call   1050 <syslog@plt>
mov    $0x0,%al
call   1060 <report_error@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1080 <connect@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1230 <client_socket+0xc0>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
lea    0xe03(%rip),%rsi
call   1050 <syslog@plt>
mov    $0x0,%al
call   1060 <report_error@plt>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%edi
call   *%rax
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client_socket>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e64(%rip),%r15
mov    (%r15),%edi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
cmp    $0xffffffff,%eax
je     11d8 <client_socket+0x68>
mov    %eax,%ebp
mov    (%r15),%eax
mov    %eax,0x4(%rsp)
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x8,%edx
call   1080 <connect@plt>
cmp    $0xffffffff,%eax
je     11ea <client_socket+0x7a>
mov    %ebp,%edi
call   *%r14
mov    %ebp,%edi
call   1040 <close@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
jmp    11fa <client_socket+0x8a>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
call   1050 <syslog@plt>
xor    %eax,%eax
call   1060 <report_error@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@LOG_ERR = global i32 0
@.str = [25 x i8] c"Could not create socket.\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [28 x i8] c"Could not listen at socket.\00"
define void @client_socket(i8* %0, void (i32)* %1) {
%3 = alloca i8*
%4 = alloca void (i32)*
%5 = alloca %struct.sockaddr_un
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store void (i32)* %1, void (i32)** %4
%8 = load i32, i32* @AF_UNIX
%9 = load i32, i32* @SOCK_STREAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32, i32* @LOG_ERR
%15 = call i32 @syslog(i32 %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%16 = call i32 (...) @report_error()
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i32, i32* @AF_UNIX
%21 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i32 0, i32 1
store i32 %20, i32* %21
%22 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i32 0, i32 0
%23 = load i32, i32* %22
%24 = load i8*, i8** %3
%25 = call i32 @strcpy(i32 %23, i8* %24)
%26 = load i32, i32* %6
%27 = bitcast %struct.sockaddr_un* %5 to %struct.sockaddr*
%28 = call i32 @connect(i32 %26, %struct.sockaddr* %27, i32 8)
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %37
31: ; preds = %19
%32 = load i32, i32* @LOG_ERR
%33 = call i32 @syslog(i32 %32, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 (...) @report_error()
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %19
%38 = load void (i32)*, void (i32)** %4
%39 = load i32, i32* %6
%40 = load i32, i32* %6
%41 = call i32 @close(i32 %40)
ret void
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@LOG_ERR = global i32 0
@.str = [25 x i8] c"Could not create socket.\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [28 x i8] c"Could not listen at socket.\00"
define void @client_socket(i8* %0, void (i32)* nocapture %1) {
%3 = alloca %struct.sockaddr_un
%4 = bitcast %struct.sockaddr_un* %3 to i8*
%5 = load i32, i32* @AF_UNIX
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i32, i32* @LOG_ERR
%11 = tail call i32 @syslog(i32 %10, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 (...) @report_error()
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = load i32, i32* @AF_UNIX
%17 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %16, i32* %17
%18 = tail call i32 @strcpy(i32 undef, i8* %0)
%19 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%20 = call i32 @connect(i32 %7, %struct.sockaddr* %19, i32 8)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %28
22: ; preds = %15
%23 = load i32, i32* @LOG_ERR
%24 = call i32 @syslog(i32 %23, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 (...) @report_error()
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %15
%29 = call i32 @close(i32 %7)
ret void
}