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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(char *, char *, int);
int setup_report_socket(void) {
  int sockfd = -1;
  int rc = -1;
  struct sockaddr_un addr;
  sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
  if (sockfd < 0) {
    return -1;
  }
  memset(&addr, 0, sizeof(struct sockaddr_un));
  addr.sun_family = AF_UNIX;
  strncpy(addr.sun_path, "/var/run/abrt/abrt.socket", sizeof(addr.sun_path));
  addr.sun_path[sizeof(addr.sun_path) - 1] = '\0';
  rc = connect(sockfd, (struct sockaddr *)&addr, sizeof(struct sockaddr_un));
  if (rc < 0) {
    close(sockfd);
    return -1;
  }
  return sockfd;
}


x86 assembly (clang, -O0):
<setup_report_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0xffffffff,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1198 <setup_report_socket+0x48>
movl   $0xffffffff,-0x4(%rbp)
jmp    1209 <setup_report_socket+0xb9>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe41(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
movb   $0x0,0x7(%rax)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1060 <connect@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1203 <setup_report_socket+0xb3>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1209 <setup_report_socket+0xb9>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_report_socket>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e87(%rip),%r15
mov    (%r15),%edi
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
js     11d7 <setup_report_socket+0x87>
mov    %eax,%ebp
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x10(%rsp)
mov    0x8(%rsp),%rdi
lea    0xe5a(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
mov    0x8(%rsp),%rax
movb   $0x0,0x7(%rax)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x10,%edx
call   1060 <connect@plt>
test   %eax,%eax
js     11d0 <setup_report_socket+0x80>
mov    %ebp,%ebx
jmp    11d7 <setup_report_socket+0x87>
mov    %ebp,%edi
call   1050 <close@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [26 x i8] c"/var/run/abrt/abrt.socket\00"
define i32 @setup_report_socket() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_un
store i32 -1, i32* %2
store i32 -1, i32* %3
%5 = load i32, i32* @AF_UNIX
%6 = load i32, i32* @SOCK_STREAM
%7 = call i32 @socket(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %0
store i32 -1, i32* %1
br label %31
11: ; preds = %0
%12 = call i32 @memset(%struct.sockaddr_un* %4, i32 0, i32 16)
%13 = load i32, i32* @AF_UNIX
%14 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 1
store i32 %13, i32* %14
%15 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 0
%16 = load i8*, i8** %15
%17 = call i32 @strncpy(i8* %16, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 8)
%18 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 0
%19 = load i8*, i8** %18
%20 = getelementptr inbounds i8, i8* %19, i64 7
store i8 0, i8* %20
%21 = load i32, i32* %2
%22 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%23 = call i32 @connect(i32 %21, %struct.sockaddr* %22, i32 16)
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %11
%27 = load i32, i32* %2
%28 = call i32 @close(i32 %27)
store i32 -1, i32* %1
br label %31
29: ; preds = %11
%30 = load i32, i32* %2
store i32 %30, i32* %1
br label %31
31: ; preds = %29, %26, %10
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [26 x i8] c"/var/run/abrt/abrt.socket\00"
define i32 @setup_report_socket() {
%1 = alloca %struct.sockaddr_un
%2 = bitcast %struct.sockaddr_un* %1 to i8*
%3 = load i32, i32* @AF_UNIX
%4 = load i32, i32* @SOCK_STREAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %21, label %7
7: ; preds = %0
%8 = call i32 @memset(%struct.sockaddr_un* %1, i32 0, i32 16)
%9 = load i32, i32* @AF_UNIX
%10 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 1
store i32 %9, i32* %10
%11 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 0
%12 = load i8*, i8** %11
%13 = call i32 @strncpy(i8* %12, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 8)
%14 = load i8*, i8** %11
%15 = getelementptr inbounds i8, i8* %14, i64 7
store i8 0, i8* %15
%16 = bitcast %struct.sockaddr_un* %1 to %struct.sockaddr*
%17 = call i32 @connect(i32 %5, %struct.sockaddr* %16, i32 16)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %7
%20 = call i32 @close(i32 %5)
br label %21
21: ; preds = %7, %0, %19
%22 = phi i32 [ -1, %19 ], [ -1, %0 ], [ %5, %7 ]
ret i32 %22
}