#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 connect(int, struct sockaddr *, int);
int /*<<< orphan*/ eof_get_ui_socketpath(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int strlen(char *);
int eof_ui_connect() {
  int sock, len;
  struct sockaddr_un una;
  sock = socket(AF_UNIX, SOCK_STREAM, 0);
  if (sock == -1) {
    return -1;
  }
  eof_get_ui_socketpath(una.sun_path, 108);
  printf("socket: %s\n", una.sun_path);
  una.sun_family = AF_UNIX;
  len = strlen(una.sun_path) + sizeof(una.sun_family);
  if (connect(sock, (struct sockaddr *)&una, len) == -1) {
    return -1;
  }
  return sock;
}


x86 assembly (clang, -O0):
<eof_ui_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    118a <eof_ui_connect+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f0 <eof_ui_connect+0xa0>
mov    -0x20(%rbp),%rdi
mov    $0x6c,%esi
call   1030 <eof_get_ui_socketpath@plt>
mov    -0x20(%rbp),%rsi
lea    0xe5d(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cltq
add    $0x4,%rax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1060 <connect@plt>
cmp    $0xffffffff,%eax
jne    11ea <eof_ui_connect+0x9a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f0 <eof_ui_connect+0xa0>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eof_ui_connect>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e8a(%rip),%r14
mov    (%r14),%edi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
cmp    $0xffffffff,%eax
je     11b1 <eof_ui_connect+0x61>
mov    %eax,%ebx
mov    $0x6c,%esi
call   1030 <eof_get_ui_socketpath@plt>
lea    0xe77(%rip),%rdi
call   1050 <printf@plt>
mov    (%r14),%eax
mov    %eax,0x10(%rsp)
call   1040 <strlen@plt>
lea    0x4(%rax),%edx
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
call   1060 <connect@plt>
cmp    $0xffffffff,%eax
cmove  %eax,%ebx
jmp    11b6 <eof_ui_connect+0x66>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
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 = [12 x i8] c"socket: %s\0A\00"
define i32 @eof_ui_connect() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_un
%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 eq i32 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %0
store i32 -1, i32* %1
br label %34
11: ; preds = %0
%12 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 0
%13 = load i8*, i8** %12
%14 = call i32 @eof_get_ui_socketpath(i8* %13, i32 108)
%15 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 0
%16 = load i8*, i8** %15
%17 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @AF_UNIX
%19 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 1
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 0
%21 = load i8*, i8** %20
%22 = call i32 @strlen(i8* %21)
%23 = sext i32 %22 to i64
%24 = add i64 %23, 4
%25 = trunc i64 %24 to i32
store i32 %25, i32* %3
%26 = load i32, i32* %2
%27 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%28 = load i32, i32* %3
%29 = call i32 @connect(i32 %26, %struct.sockaddr* %27, i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %32
31: ; preds = %11
store i32 -1, i32* %1
br label %34
32: ; preds = %11
%33 = load i32, i32* %2
store i32 %33, i32* %1
br label %34
34: ; preds = %32, %31, %10
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [12 x i8] c"socket: %s\0A\00"
define i32 @eof_ui_connect() {
%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 eq i32 %5, -1
br i1 %6, label %18, label %7
7: ; preds = %0
%8 = tail call i32 @eof_get_ui_socketpath(i8* undef, i32 108)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* undef)
%10 = load i32, i32* @AF_UNIX
%11 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 1
store i32 %10, i32* %11
%12 = tail call i32 @strlen(i8* undef)
%13 = add i32 %12, 4
%14 = bitcast %struct.sockaddr_un* %1 to %struct.sockaddr*
%15 = call i32 @connect(i32 %5, %struct.sockaddr* %14, i32 %13)
%16 = icmp eq i32 %15, -1
%17 = select i1 %16, i32 -1, i32 %5
br label %18
18: ; preds = %7, %0
%19 = phi i32 [ -1, %0 ], [ %17, %7 ]
ret i32 %19
}