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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ snprintf(int /*<<< orphan*/, int, char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
char toupper(char);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  struct sockaddr_un serun, cliun;
  socklen_t cliun_len;
  int listenfd, connfd, size;
  char buf[80];
  int i, n;
  if ((listenfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
    perror("socket error");
    exit(1);
  }
  memset(&serun, 0, sizeof(serun));
  serun.sun_family = AF_UNIX;
  snprintf(serun.sun_path, sizeof(serun.sun_path), "%s", "server.socket");
  size = sizeof(serun);
  unlink("server.socket");
  if (bind(listenfd, (struct sockaddr *)&serun, size) < 0) {
    perror("bind error:");
    exit(1);
  }
  printf("UNIX domain socket bound\n");
  if (listen(listenfd, 20) < 0) {
    perror("listen error");
    exit(1);
  }
  printf("Accepting connections ...\n");
  while (1) {
    cliun_len = sizeof(cliun);
    if ((connfd = accept(listenfd, (struct sockaddr *)&cliun, &cliun_len)) <
        0) {
      perror("accept error");
      continue;
    }
    while (1) {
      n = read(connfd, buf, sizeof(buf));
      if (n < 0) {
        perror("read error");
        break;
      } else if (n == 0) {
        printf("EOF\n");
        break;
      }
      printf("received: %s", buf);
      for (i = 0; i < n; i++) {
        buf[i] = toupper(buf[i]);
      }
      write(connfd, buf, n);
    }
    close(connfd);
  }
  close(listenfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2def(%rip),%rax
mov    (%rax),%edi
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    122d <main+0x4d>
lea    0xde2(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1080 <memset@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
mov    $0x4,%esi
lea    0xe38(%rip),%rdx
lea    0xdae(%rip),%rcx
call   1070 <snprintf@plt>
movl   $0x8,-0x28(%rbp)
lea    0xd9b(%rip),%rdi
call   1030 <unlink@plt>
mov    -0x20(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   10c0 <bind@plt>
cmp    $0x0,%rax
jge    12a6 <main+0xc6>
lea    0xd84(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0xd7a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%edi
mov    $0x14,%esi
call   10b0 <listen@plt>
cmp    $0x0,%rax
jge    12e1 <main+0x101>
lea    0xd6f(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x8,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    1323 <main+0x143>
lea    0xd50(%rip),%rdi
call   10d0 <perror@plt>
jmp    12ef <main+0x10f>
jmp    1328 <main+0x148>
mov    -0x24(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x50,%edx
call   10a0 <read@plt>
mov    %eax,-0x88(%rbp)
cmpl   $0x0,-0x88(%rbp)
jge    135d <main+0x17d>
lea    0xd23(%rip),%rdi
call   10d0 <perror@plt>
jmp    13f9 <main+0x219>
cmpl   $0x0,-0x88(%rbp)
jne    137d <main+0x19d>
lea    0xd10(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13f9 <main+0x219>
jmp    1382 <main+0x1a2>
lea    -0x80(%rbp),%rsi
lea    0xcf9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x84(%rbp)
mov    -0x84(%rbp),%eax
cmp    -0x88(%rbp),%eax
jge    13e2 <main+0x202>
movslq -0x84(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%edi
call   1040 <toupper@plt>
mov    %al,%cl
movslq -0x84(%rbp),%rax
mov    %cl,-0x80(%rbp,%rax,1)
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    139e <main+0x1be>
mov    -0x24(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    -0x88(%rbp),%edx
call   1050 <write@plt>
jmp    1328 <main+0x148>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
jmp    12ef <main+0x10f>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    0x2de3(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dca(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
test   %eax,%eax
js     1379 <main+0x189>
mov    %eax,%ebp
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1090 <memset@plt>
mov    (%rbx),%eax
mov    %eax,0x14(%rsp)
mov    0x10(%rsp),%edi
lea    0xe10(%rip),%rdx
lea    0xdc0(%rip),%rbx
mov    $0x4,%esi
mov    %rbx,%rcx
call   1080 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   10d0 <bind@plt>
test   %rax,%rax
js     1382 <main+0x192>
lea    0xdd8(%rip),%rdi
call   1050 <puts@plt>
mov    %ebp,%edi
mov    $0x14,%esi
call   10c0 <listen@plt>
test   %rax,%rax
js     138b <main+0x19b>
lea    0xdd0(%rip),%rdi
call   1050 <puts@plt>
lea    0x20(%rsp),%rbx
lea    0xd99(%rip),%r13
mov    %ebp,0x8(%rsp)
jmp    12d8 <main+0xe8>
nopl   0x0(%rax)
lea    0xdc5(%rip),%rdi
call   1050 <puts@plt>
mov    %r12d,%edi
call   10a0 <close@plt>
mov    0x8(%rsp),%ebp
movl   $0x8,0xc(%rsp)
mov    %ebp,%edi
lea    0x18(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   10f0 <accept@plt>
test   %eax,%eax
js     1368 <main+0x178>
mov    %eax,%r12d
nopl   0x0(%rax,%rax,1)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x50,%edx
call   10b0 <read@plt>
mov    %eax,%r14d
test   %eax,%eax
js     1357 <main+0x167>
test   %r14d,%r14d
je     12c0 <main+0xd0>
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14d,%r15d
xor    %ebp,%ebp
xchg   %ax,%ax
movsbl 0x20(%rsp,%rbp,1),%edi
call   1040 <toupper@plt>
mov    %al,0x20(%rsp,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1330 <main+0x140>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1060 <write@plt>
jmp    1300 <main+0x110>
lea    0xce3(%rip),%rdi
call   10e0 <perror@plt>
jmp    12cc <main+0xdc>
lea    0xcc5(%rip),%rdi
call   10e0 <perror@plt>
jmp    12d8 <main+0xe8>
lea    0xc80(%rip),%rdi
jmp    1392 <main+0x1a2>
lea    0xc92(%rip),%rdi
jmp    1392 <main+0x1a2>
lea    0xc95(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [13 x i8] c"socket error\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [14 x i8] c"server.socket\00"
@.str.3 = [12 x i8] c"bind error:\00"
@.str.4 = [26 x i8] c"UNIX domain socket bound\0A\00"
@.str.5 = [13 x i8] c"listen error\00"
@.str.6 = [27 x i8] c"Accepting connections ...\0A\00"
@.str.7 = [13 x i8] c"accept error\00"
@.str.8 = [11 x i8] c"read error\00"
@.str.9 = [5 x i8] c"EOF\0A\00"
@.str.10 = [13 x i8] c"received: %s\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 [80 x i8]
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
%11 = load i32, i32* @AF_UNIX
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %5
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %0
%19 = call i32 @memset(%struct.sockaddr_un* %2, i32 0, i32 8)
%20 = load i32, i32* @AF_UNIX
%21 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i32 0, i32 1
store i32 %20, i32* %21
%22 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @snprintf(i32 %23, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 8, i32* %7
%25 = call i32 @unlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* %5
%27 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%28 = load i32, i32* %7
%29 = call i64 @bind(i32 %26, %struct.sockaddr* %27, i32 %28)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %18
%32 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %18
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%36 = load i32, i32* %5
%37 = call i64 @listen(i32 %36, i32 20)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %34
%40 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %34
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
br label %44
44: ; preds = %42, %49, %90
store i32 8, i32* %4
%45 = load i32, i32* %5
%46 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%47 = call i32 @accept(i32 %45, %struct.sockaddr* %46, i32* %4)
store i32 %47, i32* %6
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %44
%50 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
br label %44
51: ; preds = %44
br label %52
52: ; preds = %51, %85
%53 = load i32, i32* %6
%54 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%55 = call i32 @read(i32 %53, i8* %54, i32 80)
store i32 %55, i32* %10
%56 = load i32, i32* %10
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %52
%59 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
br label %90
60: ; preds = %52
%61 = load i32, i32* %10
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %60
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
br label %90
65: ; preds = %60
br label %66
66: ; preds = %65
%67 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0), i8* %67)
store i32 0, i32* %9
br label %69
69: ; preds = %82, %66
%70 = load i32, i32* %9
%71 = load i32, i32* %10
%72 = icmp slt i32 %70, %71
br i1 %72, label %73, label %85
73: ; preds = %69
%74 = load i32, i32* %9
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 %75
%77 = load i8, i8* %76
%78 = call signext i8 @toupper(i8 signext %77)
%79 = load i32, i32* %9
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 %80
store i8 %78, i8* %81
br label %82
82: ; preds = %73
%83 = load i32, i32* %9
%84 = add nsw i32 %83, 1
store i32 %84, i32* %9
br label %69
85: ; preds = %69
%86 = load i32, i32* %6
%87 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%88 = load i32, i32* %10
%89 = call i32 @write(i32 %86, i8* %87, i32 %88)
br label %52
90: ; preds = %63, %58
%91 = load i32, i32* %6
%92 = call i32 @close(i32 %91)
br label %44
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [13 x i8] c"socket error\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [14 x i8] c"server.socket\00"
@.str.3 = [12 x i8] c"bind error:\00"
@.str.5 = [13 x i8] c"listen error\00"
@.str.7 = [13 x i8] c"accept error\00"
@.str.8 = [11 x i8] c"read error\00"
@.str.10 = [13 x i8] c"received: %s\00"
@str = [25 x i8] c"UNIX domain socket bound\00"
@str.11 = [26 x i8] c"Accepting connections ...\00"
@str.12 = [4 x i8] c"EOF\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_un
%2 = alloca %struct.sockaddr_un
%3 = alloca i32
%4 = alloca [80 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 [80 x i8], [80 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* @AF_UNIX
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = call i32 @memset(%struct.sockaddr_un* %1, i32 0, i32 8)
%18 = load i32, i32* @AF_UNIX
%19 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 1
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @snprintf(i32 %21, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @unlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%24 = bitcast %struct.sockaddr_un* %1 to %struct.sockaddr*
%25 = call i64 @bind(i32 %11, %struct.sockaddr* %24, i32 8)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %16
%28 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %16
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%32 = call i64 @listen(i32 %11, i32 20)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %30
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.11, i64 0, i64 0))
%39 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
br label %40
40: ; preds = %48, %37
store i32 8, i32* %3
%41 = call i32 @accept(i32 %11, %struct.sockaddr* %39, i32* %3)
%42 = icmp slt i32 %41, 0
br i1 %42, label %46, label %43
43: ; preds = %40
%44 = call i32 @read(i32 %41, i8* %8, i32 80)
%45 = icmp slt i32 %44, 0
br i1 %45, label %49, label %51
46: ; preds = %40
%47 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
br label %48
48: ; preds = %46, %70
br label %40
49: ; preds = %66, %43
%50 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
br label %70
51: ; preds = %43, %66
%52 = phi i32 [ %68, %66 ], [ %44, %43 ]
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %51
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.12, i64 0, i64 0))
br label %70
56: ; preds = %51
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0), i8* %8)
%58 = zext i32 %52 to i64
br label %59
59: ; preds = %56, %59
%60 = phi i64 [ 0, %56 ], [ %64, %59 ]
%61 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 %60
%62 = load i8, i8* %61
%63 = call signext i8 @toupper(i8 signext %62)
store i8 %63, i8* %61
%64 = add nuw nsw i64 %60, 1
%65 = icmp eq i64 %64, %58
br i1 %65, label %66, label %59
66: ; preds = %59
%67 = call i32 @write(i32 %41, i8* %8, i32 %52)
%68 = call i32 @read(i32 %41, i8* %8, i32 80)
%69 = icmp slt i32 %68, 0
br i1 %69, label %49, label %51
70: ; preds = %54, %49
%71 = call i32 @close(i32 %41)
br label %48
}