#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 ssize_t;
typedef int socklen_t;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
scalar_t__ ENOENT;
int /*<<< orphan*/ SOCK_DGRAM;
int bind(int, struct sockaddr *, int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, long, int /*<<< orphan*/);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int);
char toupper(unsigned char);
int unlink(char *);
int main(void) {
  struct sockaddr_un svaddr, claddr;
  int sfd, j;
  ssize_t numRead;
  socklen_t len;
  char buf[10];
  sfd = socket(AF_UNIX, SOCK_DGRAM, 0);
  if (sfd == -1)
    exit(-1);
  if (unlink("/tmp/us_xfr") == -1 && errno != ENOENT)
    exit(-2);
  memset(&svaddr, 0, sizeof(struct sockaddr_un));
  svaddr.sun_family = AF_UNIX;
  strncpy(svaddr.sun_path, "/tmp/us_xfr", sizeof(svaddr.sun_path) - 1);
  if (bind(sfd, (struct sockaddr *)&svaddr, sizeof(struct sockaddr_un)) == -1)
    exit(-3);
  for (;;) {
    len = sizeof(struct sockaddr_un);
    numRead = recvfrom(sfd, buf, 10, 0, (struct sockaddr *)&claddr, &len);
    if (numRead == -1)
      exit(-4);
    printf("server recved %ld bytes from %s\n", (long)numRead, claddr.sun_path);
    for (j = 0; j < numRead; j++)
      buf[j] = toupper((unsigned char)buf[j]);
    if (sendto(sfd, buf, numRead, 0, (struct sockaddr *)&claddr, len) !=
        numRead)
      perror("sendto ");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11ef <main+0x3f>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
lea    0xe0a(%rip),%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%eax
jne    1228 <main+0x78>
mov    0x2dc5(%rip),%rax
mov    (%rax),%rax
mov    0x2dab(%rip),%rcx
cmp    (%rcx),%rax
je     1228 <main+0x78>
mov    $0xfffffffe,%edi
call   10c0 <exit@plt>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
lea    0xdb2(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncpy@plt>
mov    -0x1c(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
jne    127c <main+0xcc>
mov    $0xfffffffd,%edi
call   10c0 <exit@plt>
jmp    1281 <main+0xd1>
movl   $0x8,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x32(%rbp),%rsi
lea    -0x18(%rbp),%r8
mov    $0xa,%edx
xor    %ecx,%ecx
lea    -0x28(%rbp),%r9
call   1090 <recvfrom@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    12ba <main+0x10a>
mov    $0xfffffffc,%edi
call   10c0 <exit@plt>
movslq -0x24(%rbp),%rsi
mov    -0x18(%rbp),%edx
lea    0xd44(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1306 <main+0x156>
movslq -0x20(%rbp),%rax
movzbl -0x32(%rbp,%rax,1),%edi
call   1050 <toupper@plt>
mov    %al,%cl
movslq -0x20(%rbp),%rax
mov    %cl,-0x32(%rbp,%rax,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12d4 <main+0x124>
mov    -0x1c(%rbp),%edi
lea    -0x32(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    -0x18(%rbp),%r8
mov    -0x28(%rbp),%r9d
xor    %ecx,%ecx
call   1080 <sendto@plt>
cmp    -0x24(%rbp),%eax
je     1334 <main+0x184>
lea    0xcfe(%rip),%rdi
call   10b0 <perror@plt>
jmp    1281 <main+0xd1>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x2e23(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
cmp    $0xffffffff,%eax
jne    11e7 <main+0x37>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    %eax,%ebx
lea    0xe10(%rip),%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%eax
jne    1214 <main+0x64>
mov    0x2dcf(%rip),%rax
mov    (%rax),%rax
mov    0x2db5(%rip),%rcx
cmp    (%rcx),%rax
jne    1296 <main+0xe6>
lea    0x20(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x24(%rsp)
mov    0x20(%rsp),%edi
lea    0xdc6(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncpy@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1262 <main+0xb2>
mov    $0xfffffffd,%edi
call   10c0 <exit@plt>
movl   $0x8,0x8(%rsp)
lea    0xe(%rsp),%rsi
lea    0x18(%rsp),%r8
lea    0x8(%rsp),%r9
mov    %ebx,%edi
mov    $0xa,%edx
xor    %ecx,%ecx
call   1090 <recvfrom@plt>
cmp    $0xffffffff,%eax
jne    12a0 <main+0xf0>
mov    $0xfffffffc,%edi
call   10c0 <exit@plt>
mov    $0xfffffffe,%edi
call   10c0 <exit@plt>
mov    %eax,%r15d
mov    %ebx,%r13d
lea    0xe(%rsp),%r12
jmp    12fc <main+0x14c>
nopl   (%rax)
mov    0x8(%rsp),%r9d
mov    %r13d,%edi
mov    %r12,%rsi
mov    %r15d,%edx
xor    %ecx,%ecx
lea    0x18(%rsp),%rbp
mov    %rbp,%r8
call   1080 <sendto@plt>
cmp    %r15d,%eax
jne    133c <main+0x18c>
movl   $0x8,0x8(%rsp)
mov    %r13d,%edi
mov    %r12,%rsi
mov    $0xa,%edx
xor    %ecx,%ecx
mov    %rbp,%r8
lea    0x8(%rsp),%r9
call   1090 <recvfrom@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
je     128c <main+0xdc>
movslq %r15d,%r14
mov    0x18(%rsp),%edx
lea    0xd02(%rip),%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
test   %r14d,%r14d
jle    12b0 <main+0x100>
mov    %r15d,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax)
movzbl 0xe(%rsp,%rbp,1),%edi
call   1050 <toupper@plt>
mov    %al,0xe(%rsp,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1320 <main+0x170>
jmp    12b0 <main+0x100>
lea    0xcea(%rip),%rdi
call   10b0 <perror@plt>
jmp    12d2 <main+0x122>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [12 x i8] c"/tmp/us_xfr\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.1 = [33 x i8] c"server recved %ld bytes from %s\0A\00"
@.str.2 = [8 x i8] c"sendto \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_un
%3 = alloca %struct.sockaddr_un
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [10 x i8]
store i32 0, i32* %1
%9 = load i32, i32* @AF_UNIX
%10 = load i32, i32* @SOCK_DGRAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %0
%17 = call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i64, i64* @errno
%21 = load i64, i64* @ENOENT
%22 = icmp ne i64 %20, %21
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 @exit(i32 -2)
unreachable
25: ; preds = %19, %16
%26 = call i32 @memset(%struct.sockaddr_un* %2, i32 0, i32 8)
%27 = load i32, i32* @AF_UNIX
%28 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i32 0, i32 1
store i32 %27, i32* %28
%29 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i32 0, i32 0
%30 = load i32, i32* %29
%31 = call i32 @strncpy(i32 %30, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 3)
%32 = load i32, i32* %4
%33 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%34 = call i32 @bind(i32 %32, %struct.sockaddr* %33, i32 8)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %25
%37 = call i32 @exit(i32 -3)
unreachable
38: ; preds = %25
br label %39
39: ; preds = %81, %38
store i32 8, i32* %7
%40 = load i32, i32* %4
%41 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%42 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%43 = call i32 @recvfrom(i32 %40, i8* %41, i32 10, i32 0, %struct.sockaddr* %42, i32* %7)
store i32 %43, i32* %6
%44 = load i32, i32* %6
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %48
46: ; preds = %39
%47 = call i32 @exit(i32 -4)
unreachable
48: ; preds = %39
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i32 0, i32 0
%52 = load i32, i32* %51
%53 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i64 %50, i32 %52)
store i32 0, i32* %5
br label %54
54: ; preds = %67, %48
%55 = load i32, i32* %5
%56 = load i32, i32* %6
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %70
58: ; preds = %54
%59 = load i32, i32* %5
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 %60
%62 = load i8, i8* %61
%63 = call signext i8 @toupper(i8 zeroext %62)
%64 = load i32, i32* %5
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 %65
store i8 %63, i8* %66
br label %67
67: ; preds = %58
%68 = load i32, i32* %5
%69 = add nsw i32 %68, 1
store i32 %69, i32* %5
br label %54
70: ; preds = %54
%71 = load i32, i32* %4
%72 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%73 = load i32, i32* %6
%74 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%75 = load i32, i32* %7
%76 = call i32 @sendto(i32 %71, i8* %72, i32 %73, i32 0, %struct.sockaddr* %74, i32 %75)
%77 = load i32, i32* %6
%78 = icmp ne i32 %76, %77
br i1 %78, label %79, label %81
79: ; preds = %70
%80 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %81
81: ; preds = %79, %70
br label %39
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [12 x i8] c"/tmp/us_xfr\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.1 = [33 x i8] c"server recved %ld bytes from %s\0A\00"
@.str.2 = [8 x i8] c"sendto \00"
define i32 @main() {
%1 = alloca %struct.sockaddr_un
%2 = alloca %struct.sockaddr_un
%3 = alloca i32
%4 = alloca [10 x i8]
%5 = bitcast %struct.sockaddr_un* %1 to i8*
%6 = bitcast %struct.sockaddr_un* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* @AF_UNIX
%10 = load i32, i32* @SOCK_DGRAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %0
%16 = tail call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = load i64, i64* @errno
%20 = load i64, i64* @ENOENT
%21 = icmp eq i64 %19, %20
br i1 %21, label %24, label %22
22: ; preds = %18
%23 = tail call i32 @exit(i32 -2)
unreachable
24: ; preds = %18, %15
%25 = call i32 @memset(%struct.sockaddr_un* %1, i32 0, i32 8)
%26 = load i32, i32* @AF_UNIX
%27 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 1
store i32 %26, i32* %27
%28 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 0
%29 = load i32, i32* %28
%30 = call i32 @strncpy(i32 %29, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 3)
%31 = bitcast %struct.sockaddr_un* %1 to %struct.sockaddr*
%32 = call i32 @bind(i32 %11, %struct.sockaddr* %31, i32 8)
%33 = icmp eq i32 %32, -1
br i1 %33, label %40, label %34
34: ; preds = %24
%35 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
store i32 8, i32* %3
%36 = call i32 @recvfrom(i32 %11, i8* %8, i32 10, i32 0, %struct.sockaddr* %35, i32* %3)
%37 = icmp eq i32 %36, -1
br i1 %37, label %42, label %38
38: ; preds = %34
%39 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 0
br label %44
40: ; preds = %24
%41 = call i32 @exit(i32 -3)
unreachable
42: ; preds = %65, %34
%43 = call i32 @exit(i32 -4)
unreachable
44: ; preds = %38, %65
%45 = phi i32 [ %36, %38 ], [ %66, %65 ]
%46 = sext i32 %45 to i64
%47 = load i32, i32* %39
%48 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i64 %46, i32 %47)
%49 = icmp sgt i32 %45, 0
br i1 %49, label %50, label %59
50: ; preds = %44
%51 = zext i32 %45 to i64
br label %52
52: ; preds = %50, %52
%53 = phi i64 [ 0, %50 ], [ %57, %52 ]
%54 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 %53
%55 = load i8, i8* %54
%56 = call signext i8 @toupper(i8 zeroext %55)
store i8 %56, i8* %54
%57 = add nuw nsw i64 %53, 1
%58 = icmp eq i64 %57, %51
br i1 %58, label %59, label %52
59: ; preds = %52, %44
%60 = load i32, i32* %3
%61 = call i32 @sendto(i32 %11, i8* %8, i32 %45, i32 0, %struct.sockaddr* %35, i32 %60)
%62 = icmp eq i32 %61, %45
br i1 %62, label %65, label %63
63: ; preds = %59
%64 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %65
65: ; preds = %63, %59
store i32 8, i32* %3
%66 = call i32 @recvfrom(i32 %11, i8* %8, i32 10, i32 0, %struct.sockaddr* %35, i32* %3)
%67 = icmp eq i32 %66, -1
br i1 %67, label %42, label %44
}