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

/* Variables and functions */
int EXIT_FAILURE;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int make_named_socket(char *);
int /*<<< orphan*/ perror(char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ unlink(char *);
int main(int argc, char *argv[]) {
  int sock;
  char message[512];
  struct sockaddr_un name;
  socklen_t size;
  int nbytes;
  char *serverfile;
  if (argc < 2) {
    fprintf(stderr, "usage %s <server_socket_file> \n", argv[0]);
    exit(1);
  } else {
    serverfile = argv[1];
  }
  unlink(serverfile);
  sock = make_named_socket(serverfile);
  while (1) {
    size = sizeof(name);
    nbytes = recvfrom(sock, message, 512, 0, (struct sockaddr *)&name, &size);
    if (nbytes < 0) {
      perror("recfrom (server)");
      exit(EXIT_FAILURE);
    }
    message[nbytes] = 0;
    fprintf(stderr, "Server: got message: %s\n", message);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11a9 <main+0x49>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe66(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x238(%rbp)
mov    -0x238(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x238(%rbp),%rdi
call   1080 <make_named_socket@plt>
mov    %eax,-0x14(%rbp)
movl   $0x4,-0x22c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x220(%rbp),%rsi
lea    -0x228(%rbp),%r8
mov    $0x200,%edx
xor    %ecx,%ecx
lea    -0x22c(%rbp),%r9
call   1050 <recvfrom@plt>
mov    %eax,-0x230(%rbp)
cmpl   $0x0,-0x230(%rbp)
jge    122e <main+0xce>
lea    0xe05(%rip),%rdi
call   1060 <perror@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
movslq -0x230(%rbp),%rax
movb   $0x0,-0x220(%rbp,%rax,1)
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
lea    -0x220(%rbp),%rdx
lea    0xddd(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11d3 <main+0x73>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
cmp    $0x1,%edi
jg     1198 <main+0x38>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe77(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %rbx,%rdi
call   1080 <make_named_socket@plt>
mov    %eax,%ebp
movl   $0x4,0x4(%rsp)
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%r8
lea    0x4(%rsp),%r9
mov    %eax,%edi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1050 <recvfrom@plt>
test   %eax,%eax
js     1239 <main+0xd9>
mov    0x2e02(%rip),%r13
lea    0xe4c(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%r15
lea    0x4(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %eax,%eax
movb   $0x0,0x10(%rsp,%rax,1)
mov    0x0(%r13),%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
movl   $0x4,0x4(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r12,%r9
call   1050 <recvfrom@plt>
test   %eax,%eax
jns    1200 <main+0xa0>
lea    0xde0(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [32 x i8] c"usage %s <server_socket_file> \0A\00"
@.str.1 = [17 x i8] c"recfrom (server)\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [25 x i8] c"Server: got message: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [512 x i8]
%8 = alloca %struct.sockaddr_un
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %11
br label %25
25: ; preds = %21
%26 = load i8*, i8** %11
%27 = call i32 @unlink(i8* %26)
%28 = load i8*, i8** %11
%29 = call i32 @make_named_socket(i8* %28)
store i32 %29, i32* %6
br label %30
30: ; preds = %25, %41
store i32 4, i32* %9
%31 = load i32, i32* %6
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%33 = bitcast %struct.sockaddr_un* %8 to %struct.sockaddr*
%34 = call i32 @recvfrom(i32 %31, i8* %32, i32 512, i32 0, %struct.sockaddr* %33, i32* %9)
store i32 %34, i32* %10
%35 = load i32, i32* %10
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %30
%38 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %30
%42 = load i32, i32* %10
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 %43
store i8 0, i8* %44
%45 = load i32, i32* @stderr
%46 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%47 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %46)
br label %30
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [32 x i8] c"usage %s <server_socket_file> \0A\00"
@.str.1 = [17 x i8] c"recfrom (server)\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [25 x i8] c"Server: got message: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = alloca %struct.sockaddr_un
%5 = alloca i32
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%7 = bitcast %struct.sockaddr_un* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = icmp slt i32 %0, 2
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %1
%13 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32 @unlink(i8* %17)
%19 = tail call i32 @make_named_socket(i8* %17)
%20 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
store i32 4, i32* %5
%21 = call i32 @recvfrom(i32 %19, i8* %6, i32 512, i32 0, %struct.sockaddr* %20, i32* %5)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %27, %15
%24 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %15, %27
%28 = phi i32 [ %33, %27 ], [ %21, %15 ]
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %29
store i8 0, i8* %30
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %6)
store i32 4, i32* %5
%33 = call i32 @recvfrom(i32 %19, i8* %6, i32 512, i32 0, %struct.sockaddr* %20, i32* %5)
%34 = icmp slt i32 %33, 0
br i1 %34, label %23, label %27
}