#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 */
typedef int /*<<< orphan*/ un;
struct sockaddr_un {
  int /*<<< orphan*/ 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*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char const *);
char *strerror(int /*<<< orphan*/);
int vreboot_connect(const char *sockpath, bool showerror) {
  int ret = -1;
  int fd = socket(AF_UNIX, SOCK_STREAM, 0);
  if (fd == -1) {
    if (showerror)
      perror("socket client");
  } else {
    struct sockaddr_un un;
    int s;
    un.sun_family = AF_UNIX;
    strcpy(un.sun_path, sockpath);
    s = connect(fd, (struct sockaddr *)&un, sizeof(un));
    if (s == -1) {
      if (showerror)
        fprintf(stderr, "connect %s (%s)\n", sockpath, strerror(errno));
    } else {
      ret = fd;
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<vreboot_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11b7 <vreboot_connect+0x57>
cmpl   $0x0,-0xc(%rbp)
je     11b2 <vreboot_connect+0x52>
lea    0xe53(%rip),%rdi
call   1050 <perror@plt>
jmp    123f <vreboot_connect+0xdf>
mov    0x2e2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1060 <connect@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1234 <vreboot_connect+0xd4>
cmpl   $0x0,-0xc(%rbp)
je     122f <vreboot_connect+0xcf>
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xde4(%rip),%rsi
call   1040 <fprintf@plt>
jmp    123a <vreboot_connect+0xda>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    123f <vreboot_connect+0xdf>
mov    -0x10(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vreboot_connect>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
mov    0x2e74(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
cmp    $0xffffffff,%eax
je     11e8 <vreboot_connect+0x88>
mov    %eax,%ebx
mov    0x0(%rbp),%eax
mov    %eax,0x4(%rsp)
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1060 <connect@plt>
cmp    $0xffffffff,%eax
jne    11f2 <vreboot_connect+0x92>
mov    $0xffffffff,%ebx
test   %r15d,%r15d
je     11f2 <vreboot_connect+0x92>
mov    0x2e16(%rip),%rax
mov    (%rax),%ebp
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe35(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1040 <fprintf@plt>
jmp    11f2 <vreboot_connect+0x92>
mov    $0xffffffff,%ebx
test   %r15d,%r15d
jne    11ff <vreboot_connect+0x9f>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdfa(%rip),%rdi
call   1050 <perror@plt>
jmp    11f2 <vreboot_connect+0x92>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [14 x i8] c"socket client\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"connect %s (%s)\0A\00"
@errno = global i32 0
define i32 @vreboot_connect(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.sockaddr_un
%8 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 -1, i32* %5
%9 = load i32, i32* @AF_UNIX
%10 = load i32, i32* @SOCK_STREAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
br label %45
20: ; preds = %2
%21 = load i32, i32* @AF_UNIX
%22 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 1
store i32 %21, i32* %22
%23 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 0
%24 = load i32, i32* %23
%25 = load i8*, i8** %3
%26 = call i32 @strcpy(i32 %24, i8* %25)
%27 = load i32, i32* %6
%28 = bitcast %struct.sockaddr_un* %7 to %struct.sockaddr*
%29 = call i32 @connect(i32 %27, %struct.sockaddr* %28, i32 8)
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %42
32: ; preds = %20
%33 = load i32, i32* %4
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %32
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %3
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %37, i8* %39)
br label %41
41: ; preds = %35, %32
br label %44
42: ; preds = %20
%43 = load i32, i32* %6
store i32 %43, i32* %5
br label %44
44: ; preds = %42, %41
br label %45
45: ; preds = %44, %19
%46 = load i32, i32* %5
ret i32 %46
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [14 x i8] c"socket client\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"connect %s (%s)\0A\00"
@errno = global i32 0
define i32 @vreboot_connect(i8* %0, i32 %1) {
%3 = alloca %struct.sockaddr_un
%4 = load i32, i32* @AF_UNIX
%5 = load i32, i32* @SOCK_STREAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = icmp eq i32 %1, 0
br i1 %9, label %29, label %10
10: ; preds = %8
%11 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %29
12: ; preds = %2
%13 = bitcast %struct.sockaddr_un* %3 to i8*
%14 = load i32, i32* @AF_UNIX
%15 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %14, i32* %15
%16 = tail call i32 @strcpy(i32 undef, i8* %0)
%17 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%18 = call i32 @connect(i32 %6, %struct.sockaddr* %17, i32 8)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %27
20: ; preds = %12
%21 = icmp eq i32 %1, 0
br i1 %21, label %27, label %22
22: ; preds = %20
%23 = load i32, i32* @stderr
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %25)
br label %27
27: ; preds = %12, %20, %22
%28 = phi i32 [ -1, %22 ], [ -1, %20 ], [ %6, %12 ]
br label %29
29: ; preds = %8, %10, %27
%30 = phi i32 [ -1, %10 ], [ -1, %8 ], [ %28, %27 ]
ret i32 %30
}