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

/* Variables and functions */
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ prepare_ifsun(struct sockaddr_un *, char const *);
void connect_uds_server(int sock, const char *path) {
  struct sockaddr_un ifsun;
  int e;
  prepare_ifsun(&ifsun, path);
  e = connect(sock, ((struct sockaddr *)(&ifsun)), sizeof(ifsun));
  if (e < 0)
    err(1, "can't connect to a socket");
}


x86 assembly (clang, -O0):
<connect_uds_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdi
call   1030 <prepare_ifsun@plt>
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1050 <connect@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    117b <connect_uds_server+0x4b>
mov    $0x1,%edi
lea    0xe8a(%rip),%rsi
call   1040 <err@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connect_uds_server>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <prepare_ifsun@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1050 <connect@plt>
test   %eax,%eax
jns    1165 <connect_uds_server+0x35>
lea    0xea5(%rip),%rsi
mov    $0x1,%edi
call   1040 <err@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [26 x i8] c"can't connect to a socket\00"
define void @connect_uds_server(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.sockaddr_un
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i32 @prepare_ifsun(%struct.sockaddr_un* %5, i8* %7)
%9 = load i32, i32* %3
%10 = bitcast %struct.sockaddr_un* %5 to %struct.sockaddr*
%11 = call i32 @connect(i32 %9, %struct.sockaddr* %10, i32 4)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @err(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %2
ret void
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [26 x i8] c"can't connect to a socket\00"
define void @connect_uds_server(i32 %0, i8* %1) {
%3 = alloca %struct.sockaddr_un
%4 = bitcast %struct.sockaddr_un* %3 to i8*
%5 = call i32 @prepare_ifsun(%struct.sockaddr_un* %3, i8* %1)
%6 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%7 = call i32 @connect(i32 %0, %struct.sockaddr* %6, i32 4)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @err(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %2
ret void
}