#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*/ servaddr;
typedef int /*<<< orphan*/ cliaddr;

/* Variables and functions */
void *AF_LOCAL;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ dg_cli(int /*<<< orphan*/, int, struct sockaddr *, int);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
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;
  struct sockaddr_un cliaddr, servaddr;
  sockfd = socket(AF_LOCAL, SOCK_DGRAM, 0);
  memset(&cliaddr, 0, sizeof(cliaddr));
  cliaddr.sun_family = AF_LOCAL;
  strcpy(cliaddr.sun_path, tmpnam(NULL));
  bind(sockfd, (struct sockaddr *)&cliaddr, sizeof(cliaddr));
  memset(&servaddr, 0, sizeof(servaddr));
  servaddr.sun_family = AF_LOCAL;
  strcpy(servaddr.sun_path, "/tmp/unix.dg");
  dg_cli(stdin, sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
  return 0;
}


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    0x2e63(%rip),%rax
mov    (%rax),%rdi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x3c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <tmpnam@plt>
mov    -0x3c(%rbp),%edi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   1050 <bind@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%edi
lea    0xdfc(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%esi
lea    -0x38(%rbp),%rdx
mov    $0x10,%ecx
call   1060 <dg_cli@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0x2e6f(%rip),%r15
mov    (%r15),%rdi
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,%ebx
lea    0x18(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    (%r15),%rax
mov    %rax,0x20(%rsp)
mov    0x18(%rsp),%ebp
xor    %edi,%edi
call   1070 <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>
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    (%r15),%rax
mov    %rax,0x10(%rsp)
mov    0x8(%rsp),%edi
lea    0xe13(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
mov    %ebx,%esi
mov    %rbp,%rdx
mov    $0x10,%ecx
call   1060 <dg_cli@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i8* }
%struct.sockaddr = type { i32 }
@AF_LOCAL = global i8* null
@SOCK_DGRAM = global i32 0
@.str = [13 x i8] c"/tmp/unix.dg\00"
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_un
%8 = alloca %struct.sockaddr_un
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8*, i8** @AF_LOCAL
%10 = load i32, i32* @SOCK_DGRAM
%11 = call i32 @socket(i8* %9, i32 %10, i32 0)
store i32 %11, i32* %6
%12 = call i32 @memset(%struct.sockaddr_un* %7, i32 0, i32 16)
%13 = load i8*, i8** @AF_LOCAL
%14 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 1
store i8* %13, i8** %14
%15 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i8* @tmpnam(i32* null)
%18 = call i32 @strcpy(i32 %16, i8* %17)
%19 = load i32, i32* %6
%20 = bitcast %struct.sockaddr_un* %7 to %struct.sockaddr*
%21 = call i32 @bind(i32 %19, %struct.sockaddr* %20, i32 16)
%22 = call i32 @memset(%struct.sockaddr_un* %8, i32 0, i32 16)
%23 = load i8*, i8** @AF_LOCAL
%24 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 1
store i8* %23, i8** %24
%25 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 0
%26 = load i32, i32* %25
%27 = call i32 @strcpy(i32 %26, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%28 = load i32, i32* @stdin
%29 = load i32, i32* %6
%30 = bitcast %struct.sockaddr_un* %8 to %struct.sockaddr*
%31 = call i32 @dg_cli(i32 %28, i32 %29, %struct.sockaddr* %30, i32 16)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i8* }
%struct.sockaddr = type { i32 }
@AF_LOCAL = global i8* null
@SOCK_DGRAM = global i32 0
@.str = [13 x i8] c"/tmp/unix.dg\00"
@stdin = 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 = call i32 @memset(%struct.sockaddr_un* %3, i32 0, i32 16)
%11 = load i8*, i8** @AF_LOCAL
%12 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i8* %11, i8** %12
%13 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%14 = load i32, i32* %13
%15 = call i8* @tmpnam(i32* null)
%16 = call i32 @strcpy(i32 %14, i8* %15)
%17 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%18 = call i32 @bind(i32 %9, %struct.sockaddr* %17, i32 16)
%19 = call i32 @memset(%struct.sockaddr_un* %4, i32 0, i32 16)
%20 = load i8*, i8** @AF_LOCAL
%21 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i64 0, i32 1
store i8* %20, i8** %21
%22 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i64 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @strcpy(i32 %23, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%25 = load i32, i32* @stdin
%26 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%27 = call i32 @dg_cli(i32 %25, i32 %9, %struct.sockaddr* %26, i32 16)
ret i32 0
}