#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;
  void *sun_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ servaddr;
typedef int /*<<< orphan*/ cliaddr;

/* Variables and functions */
void *AF_LOCAL;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_un *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dg_cli(int /*<<< orphan*/, int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
char *tmpnam(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int sockfd;
  socklen_t clilen;
  struct sockaddr_un servaddr, cliaddr;
  if ((sockfd = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0) {
    perror("socket");
    exit(EXIT_FAILURE);
  }
  bzero(&cliaddr, sizeof(cliaddr));
  cliaddr.sun_family = AF_LOCAL;
  strcpy(cliaddr.sun_path, tmpnam(NULL));
  if (bind(sockfd, (struct sockaddr *)&cliaddr, sizeof(cliaddr)) < 0) {
    perror("bind");
    close(sockfd);
    exit(EXIT_FAILURE);
  }
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sun_family = AF_LOCAL;
  strcpy(servaddr.sun_path, "/tmp/unix_domain_sockfd");
  dg_cli(stdin, sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%rdi
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11e6 <main+0x56>
lea    0xe2d(%rip),%rdi
call   1060 <perror@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    -0x38(%rbp),%rdi
mov    $0x10,%esi
call   1070 <bzero@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x3c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <tmpnam@plt>
mov    -0x3c(%rbp),%edi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x10,%edx
call   1050 <bind@plt>
cmp    $0x0,%rax
jge    1259 <main+0xc9>
lea    0xdc9(%rip),%rdi
call   1060 <perror@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    -0x28(%rbp),%rdi
mov    $0x10,%esi
call   1070 <bzero@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%edi
lea    0xd8d(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%esi
lea    -0x28(%rbp),%rdx
mov    $0x10,%ecx
call   1080 <dg_cli@plt>
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0x2e3f(%rip),%r15
mov    (%r15),%rdi
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
test   %eax,%eax
jns    11c6 <main+0x36>
lea    0xe41(%rip),%rdi
call   1060 <perror@plt>
jmp    121e <main+0x8e>
mov    %eax,%ebx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0x10,%esi
call   1070 <bzero@plt>
mov    (%r15),%rax
mov    %rax,0x10(%rsp)
mov    0x8(%rsp),%ebp
xor    %edi,%edi
call   10a0 <tmpnam@plt>
mov    %ebp,%edi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x10,%edx
call   1050 <bind@plt>
test   %rax,%rax
jns    122c <main+0x9c>
lea    0xdf5(%rip),%rdi
call   1060 <perror@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0x18(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x10,%esi
call   1070 <bzero@plt>
mov    (%r15),%rax
mov    %rax,0x20(%rsp)
mov    0x18(%rsp),%edi
lea    0xdbb(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
mov    %ebx,%esi
mov    %rbp,%rdx
mov    $0x10,%ecx
call   1080 <dg_cli@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i8* }
%struct.sockaddr = type { i32 }
@AF_LOCAL = global i8* null
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [24 x i8] c"/tmp/unix_domain_sockfd\00"
@stdin = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_un
%9 = alloca %struct.sockaddr_un
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8*, i8** @AF_LOCAL
%11 = load i32, i32* @SOCK_DGRAM
%12 = call i32 @socket(i8* %10, i32 %11, i32 0)
store i32 %12, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = call i32 @bzero(%struct.sockaddr_un* %9, i32 16)
%20 = load i8*, i8** @AF_LOCAL
%21 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %9, i32 0, i32 1
store i8* %20, i8** %21
%22 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %9, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i8* @tmpnam(i32* null)
%25 = call i32 @strcpy(i32 %23, i8* %24)
%26 = load i32, i32* %6
%27 = bitcast %struct.sockaddr_un* %9 to %struct.sockaddr*
%28 = call i64 @bind(i32 %26, %struct.sockaddr* %27, i32 16)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %18
%31 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* %6
%33 = call i32 @close(i32 %32)
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %18
%37 = call i32 @bzero(%struct.sockaddr_un* %8, i32 16)
%38 = load i8*, i8** @AF_LOCAL
%39 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 1
store i8* %38, i8** %39
%40 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 0
%41 = load i32, i32* %40
%42 = call i32 @strcpy(i32 %41, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%43 = load i32, i32* @stdin
%44 = load i32, i32* %6
%45 = bitcast %struct.sockaddr_un* %8 to %struct.sockaddr*
%46 = call i32 @dg_cli(i32 %43, i32 %44, %struct.sockaddr* %45, i32 16)
%47 = load i32, i32* @EXIT_SUCCESS
%48 = call i32 @exit(i32 %47)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i8* }
%struct.sockaddr = type { i32 }
@AF_LOCAL = global i8* null
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [24 x i8] c"/tmp/unix_domain_sockfd\00"
@stdin = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca %struct.sockaddr_un
%5 = bitcast %struct.sockaddr_un* %3 to i8*
%6 = bitcast %struct.sockaddr_un* %4 to i8*
%7 = load i8*, i8** @AF_LOCAL
%8 = load i32, i32* @SOCK_DGRAM
%9 = tail call i32 @socket(i8* %7, i32 %8, i32 0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = call i32 @bzero(%struct.sockaddr_un* %4, i32 16)
%17 = load i8*, i8** @AF_LOCAL
%18 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i64 0, i32 1
store i8* %17, i8** %18
%19 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i64 0, i32 0
%20 = load i32, i32* %19
%21 = tail call i8* @tmpnam(i32* null)
%22 = tail call i32 @strcpy(i32 %20, i8* %21)
%23 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%24 = call i64 @bind(i32 %9, %struct.sockaddr* %23, i32 16)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %15
%27 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @close(i32 %9)
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %15
%32 = call i32 @bzero(%struct.sockaddr_un* %3, i32 16)
%33 = load i8*, i8** @AF_LOCAL
%34 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i8* %33, i8** %34
%35 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%36 = load i32, i32* %35
%37 = call i32 @strcpy(i32 %36, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%38 = load i32, i32* @stdin
%39 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%40 = call i32 @dg_cli(i32 %38, i32 %9, %struct.sockaddr* %39, i32 16)
%41 = load i32, i32* @EXIT_SUCCESS
%42 = call i32 @exit(i32 %41)
unreachable
}