#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 /*<<< orphan*/ 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);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, char const *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char const *, int);
int main(void) {
  struct sockaddr_un addr;
  int s;
  const char *socketpath = "/var/run/minissdpd.sock";
  s = socket(AF_UNIX, SOCK_STREAM, 0);
  if (s < 0) {
    fprintf(stderr, "Error: cannot open socket\n");
    return 1;
  }
  addr.sun_family = AF_UNIX;
  strncpy(addr.sun_path, socketpath, sizeof(addr.sun_path));
  if (connect(s, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0) {
    fprintf(stderr, "Error: cannot connect to socket\n");
    return 1;
  }
  printf("connected to %s\n", socketpath);
  close(s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11c1 <main+0x61>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1239 <main+0xd9>
mov    0x2e20(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0x14(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1070 <connect@plt>
cmp    $0x0,%rax
jge    121a <main+0xba>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1239 <main+0xd9>
mov    -0x20(%rbp),%rsi
lea    0xe2f(%rip),%rdi
call   1040 <printf@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):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e7d(%rip),%r14
mov    (%r14),%edi
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
test   %eax,%eax
js     11ce <main+0x6e>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x4(%rsp)
lea    0xe6e(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1070 <connect@plt>
test   %rax,%rax
js     11e0 <main+0x80>
lea    0xe9d(%rip),%rdi
lea    0xe42(%rip),%rsi
call   1040 <printf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    11fa <main+0x9a>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
jmp    11f0 <main+0x90>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [24 x i8] c"/var/run/minissdpd.sock\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"Error: cannot open socket\0A\00"
@.str.2 = [33 x i8] c"Error: cannot connect to socket\0A\00"
@.str.3 = [17 x i8] c"connected to %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_un
%3 = alloca i32
%4 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8** %4
%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* %3
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %32
13: ; preds = %0
%14 = load i32, i32* @AF_UNIX
%15 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i32 0, i32 1
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i32 0, i32 0
%17 = load i32, i32* %16
%18 = load i8*, i8** %4
%19 = call i32 @strncpy(i32 %17, i8* %18, i32 4)
%20 = load i32, i32* %3
%21 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%22 = call i64 @connect(i32 %20, %struct.sockaddr* %21, i32 8)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %13
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %32
27: ; preds = %13
%28 = load i8*, i8** %4
%29 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = load i32, i32* %3
%31 = call i32 @close(i32 %30)
store i32 0, i32* %1
br label %32
32: ; preds = %27, %24, %10
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [24 x i8] c"/var/run/minissdpd.sock\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"Error: cannot open socket\0A\00"
@.str.2 = [33 x i8] c"Error: cannot connect to socket\0A\00"
@.str.3 = [17 x i8] c"connected to %s\0A\00"
define i32 @main() {
%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 %7, label %10
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %23
10: ; preds = %0
%11 = load i32, i32* @AF_UNIX
%12 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 1
store i32 %11, i32* %12
%13 = tail call i32 @strncpy(i32 undef, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 4)
%14 = bitcast %struct.sockaddr_un* %1 to %struct.sockaddr*
%15 = call i64 @connect(i32 %5, %struct.sockaddr* %14, i32 8)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %10
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %23
20: ; preds = %10
%21 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @close(i32 %5)
br label %23
23: ; preds = %20, %17, %7
%24 = phi i32 [ 1, %7 ], [ 1, %17 ], [ 0, %20 ]
ret i32 %24
}