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

/* 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 /*<<< orphan*/ read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int pmap_wakeup(void) {
  struct sockaddr_un sun;
  int fd;
  char b;
  memset(&sun, 0, sizeof(sun));
  sun.sun_family = AF_UNIX;
  strcpy(sun.sun_path, "/var/run/portmap.socket");
  fd = socket(AF_UNIX, SOCK_STREAM, 0);
  if (fd == -1)
    return -1;
  if (connect(fd, (struct sockaddr *)&sun, sizeof(sun)) == -1) {
    close(fd);
    return -1;
  }
  read(fd, &b, sizeof(b));
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<pmap_wakeup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2e69(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
lea    0xe72(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11c5 <pmap_wakeup+0x65>
movl   $0xffffffff,-0x4(%rbp)
jmp    1213 <pmap_wakeup+0xb3>
mov    -0x14(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1070 <connect@plt>
cmp    $0xffffffff,%eax
jne    11f3 <pmap_wakeup+0x93>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1213 <pmap_wakeup+0xb3>
mov    -0x14(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pmap_wakeup>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2e6a(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x14(%rsp)
mov    0x10(%rsp),%edi
lea    0xe71(%rip),%rsi
call   1030 <strcpy@plt>
mov    (%rbx),%edi
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
cmp    $0xffffffff,%eax
je     11d8 <pmap_wakeup+0x78>
mov    %eax,%ebx
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    $0x8,%edx
call   1070 <connect@plt>
cmp    $0xffffffff,%eax
je     11df <pmap_wakeup+0x7f>
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1060 <read@plt>
xor    %ebp,%ebp
jmp    11e4 <pmap_wakeup+0x84>
mov    $0xffffffff,%ebp
jmp    11eb <pmap_wakeup+0x8b>
mov    $0xffffffff,%ebp
mov    %ebx,%edi
call   1050 <close@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

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

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