#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;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ feof(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ printf(char *, ...);
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr *, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int /*<<< orphan*/ strlen(char *);
int main(void) {
  struct sockaddr_un remote;
  int s;
  if ((s = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) {
    perror("socket");
    exit(EXIT_FAILURE);
  }
  remote.sun_family = AF_UNIX;
  strcpy(remote.sun_path, "unix-dgram-server.temp");
  char str[100];
  while (printf("> "), fgets(str, 100, stdin), !feof(stdin)) {
    if (sendto(s, str, strlen(str), 0, (struct sockaddr *)(&remote),
               (socklen_t)sizeof(struct sockaddr_un)) == -1) {
      perror("sendto");
      exit(EXIT_FAILURE);
    }
    printf("sent %zu bytes\n", strlen(str));
  }
  close(s);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11f1 <main+0x51>
lea    0xe22(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
lea    0xe00(%rip),%rsi
call   1030 <strcpy@plt>
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2dbb(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1080 <fgets@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1254 <main+0xb4>
jmp    12d2 <main+0x132>
mov    -0x14(%rbp),%eax
mov    %eax,-0x8c(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x8c(%rbp),%edi
mov    -0x88(%rbp),%rsi
mov    %eax,%edx
lea    -0x10(%rbp),%r8
xor    %ecx,%ecx
mov    $0x8,%r9d
call   1060 <sendto@plt>
cmp    $0xffffffff,%eax
jne    12b4 <main+0x114>
lea    0xd80(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%esi
lea    0xd62(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    120c <main+0x6c>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    0x2cdf(%rip),%rax
mov    (%rax),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    0x2e33(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
cmp    $0xffffffff,%eax
je     12c9 <main+0x129>
mov    %eax,%r13d
mov    (%rbx),%eax
mov    %eax,0xc(%rsp)
lea    0xe27(%rip),%rsi
call   1030 <strcpy@plt>
lea    0xe32(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2de6(%rip),%rbp
mov    0x0(%rbp),%edx
lea    0x10(%rsp),%rdi
mov    $0x64,%esi
call   1080 <fgets@plt>
mov    0x0(%rbp),%edi
call   1090 <feof@plt>
test   %eax,%eax
jne    128f <main+0xef>
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%r14
lea    0xdff(%rip),%r15
lea    0xdee(%rip),%r12
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0x8,%r9d
call   1060 <sendto@plt>
cmp    $0xffffffff,%eax
je     12af <main+0x10f>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1080 <fgets@plt>
mov    0x0(%rbp),%edi
call   1090 <feof@plt>
test   %eax,%eax
je     1230 <main+0x90>
mov    %r13d,%edi
call   1070 <close@plt>
mov    0x2d22(%rip),%rax
mov    (%rax),%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd6b(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    0xd30(%rip),%rdi
jmp    12b6 <main+0x116>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [23 x i8] c"unix-dgram-server.temp\00"
@.str.2 = [3 x i8] c"> \00"
@stdin = global i32 0
@.str.3 = [7 x i8] c"sendto\00"
@.str.4 = [16 x i8] c"sent %zu bytes\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_un
%3 = alloca i32
%4 = alloca [100 x i8]
store i32 0, i32* %1
%5 = load i32, i32* @AF_UNIX
%6 = load i32, i32* @SOCK_DGRAM
%7 = call i32 @socket(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %3
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
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 = call i32 @strcpy(i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %40, %13
%20 = call i64 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%22 = load i32, i32* @stdin
%23 = call i32 @fgets(i8* %21, i32 100, i32 %22)
%24 = load i32, i32* @stdin
%25 = call i32 @feof(i32 %24)
%26 = icmp ne i32 %25, 0
%27 = xor i1 %26, true
br i1 %27, label %28, label %44
28: ; preds = %19
%29 = load i32, i32* %3
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%32 = call i32 @strlen(i8* %31)
%33 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%34 = call i32 @sendto(i32 %29, i8* %30, i32 %32, i32 0, %struct.sockaddr* %33, i32 8)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %40
36: ; preds = %28
%37 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %28
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%42 = call i32 @strlen(i8* %41)
%43 = call i64 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %42)
br label %19
44: ; preds = %19
%45 = load i32, i32* %3
%46 = call i32 @close(i32 %45)
%47 = load i32, i32* @EXIT_SUCCESS
ret i32 %47
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [23 x i8] c"unix-dgram-server.temp\00"
@.str.2 = [3 x i8] c"> \00"
@stdin = global i32 0
@.str.3 = [7 x i8] c"sendto\00"
@.str.4 = [16 x i8] c"sent %zu bytes\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca %struct.sockaddr_un
%2 = alloca [100 x i8]
%3 = bitcast %struct.sockaddr_un* %1 to i8*
%4 = load i32, i32* @AF_UNIX
%5 = load i32, i32* @SOCK_DGRAM
%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 = %0
%9 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
%13 = load i32, i32* @AF_UNIX
%14 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 1
store i32 %13, i32* %14
%15 = tail call i32 @strcpy(i32 undef, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%17 = call i64 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%18 = load i32, i32* @stdin
%19 = call i32 @fgets(i8* %16, i32 100, i32 %18)
%20 = load i32, i32* @stdin
%21 = call i32 @feof(i32 %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %42
23: ; preds = %12
%24 = bitcast %struct.sockaddr_un* %1 to %struct.sockaddr*
br label %25
25: ; preds = %23, %33
%26 = call i32 @strlen(i8* %16)
%27 = call i32 @sendto(i32 %6, i8* %16, i32 %26, i32 0, %struct.sockaddr* %24, i32 8)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %25
%34 = call i32 @strlen(i8* %16)
%35 = call i64 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %34)
%36 = call i64 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%37 = load i32, i32* @stdin
%38 = call i32 @fgets(i8* %16, i32 100, i32 %37)
%39 = load i32, i32* @stdin
%40 = call i32 @feof(i32 %39)
%41 = icmp eq i32 %40, 0
br i1 %41, label %25, label %42
42: ; preds = %33, %12
%43 = call i32 @close(i32 %6)
%44 = load i32, i32* @EXIT_SUCCESS
ret i32 %44
}