#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;
typedef int /*<<< orphan*/ server_address;
typedef int /*<<< orphan*/ client_address;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int /*<<< orphan*/ unlink(char *);
int write(int, char *, int);
int main() {
  int server_sockfd, client_sockfd;
  int server_len, client_len;
  struct sockaddr_un server_address;
  struct sockaddr_un client_address;
  int i, byte;
  char ch_send, ch_rec;
  unlink("server_socket");
  server_sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
  if (server_sockfd == -1) {
    perror("socket");
    exit(1);
  }
  server_address.sun_family = AF_UNIX;
  strcpy(server_address.sun_path, "server_socket");
  server_len = sizeof(server_address);
  bind(server_sockfd, (struct sockaddr *)&server_address, server_len);
  listen(server_sockfd, 5);
  printf("server waiting for client connect\n");
  client_len = sizeof(client_address);
  client_sockfd = accept(server_sockfd, (struct sockaddr *)&client_address,
                         (socklen_t *)&client_len);
  printf("the server wait for client data\n");
  for (i = 0, ch_send = '1'; i < 5; i++, ch_send++) {
    if ((byte = read(client_sockfd, &ch_rec, 1)) == -1) {
      perror("read");
      exit(1);
    }
    printf("the character receiver from client is %c\n", ch_rec);
    sleep(1);
    if (write(client_sockfd, &ch_send, 1) == -1) {
      perror("write");
      exit(1);
    }
  }
  close(client_sockfd);
  unlink("server_socket");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe1a(%rip),%rdi
call   1030 <unlink@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1227 <main+0x57>
lea    0xdef(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
lea    0xdc3(%rip),%rsi
call   1040 <strcpy@plt>
movl   $0x8,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   10a0 <bind@plt>
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   1090 <listen@plt>
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x8,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   10c0 <accept@plt>
mov    %eax,-0xc(%rbp)
lea    0xd9d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x2c(%rbp)
movb   $0x31,-0x31(%rbp)
cmpl   $0x5,-0x2c(%rbp)
jge    134a <main+0x17a>
mov    -0xc(%rbp),%edi
lea    -0x32(%rbp),%rsi
mov    $0x1,%edx
call   1080 <read@plt>
mov    %eax,-0x30(%rbp)
cmp    $0xffffffff,%eax
jne    12e3 <main+0x113>
lea    0xd7e(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
movsbl -0x32(%rbp),%esi
lea    0xd69(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10e0 <sleep@plt>
mov    -0xc(%rbp),%edi
lea    -0x31(%rbp),%rsi
mov    $0x1,%edx
call   1050 <write@plt>
cmp    $0xffffffff,%eax
jne    132f <main+0x15f>
lea    0xd61(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    1334 <main+0x164>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x31(%rbp),%al
add    $0x1,%al
mov    %al,-0x31(%rbp)
jmp    12a6 <main+0xd6>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
lea    0xca7(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xe12(%rip),%rdi
call   1030 <unlink@plt>
mov    0x2dee(%rip),%r14
mov    (%r14),%edi
mov    0x2dd4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
cmp    $0xffffffff,%eax
je     1459 <main+0x279>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0xc(%rsp)
lea    0xdda(%rip),%rsi
call   1040 <strcpy@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   10b0 <bind@plt>
mov    %ebx,%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
lea    0xdf4(%rip),%rdi
call   1050 <puts@plt>
movl   $0x8,0x4(%rsp)
lea    0x10(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
call   10d0 <accept@plt>
mov    %eax,%ebx
lea    0xdef(%rip),%rdi
call   1050 <puts@plt>
movb   $0x31,0x3(%rsp)
lea    0x2(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1090 <read@plt>
cmp    $0xffffffff,%eax
je     143a <main+0x25a>
movsbl 0x2(%rsp),%esi
lea    0xd6d(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   10f0 <sleep@plt>
lea    0x3(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1060 <write@plt>
cmp    $0xffffffff,%eax
je     1443 <main+0x263>
movb   $0x32,0x3(%rsp)
lea    0x2(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1090 <read@plt>
cmp    $0xffffffff,%eax
je     143a <main+0x25a>
movsbl 0x2(%rsp),%esi
lea    0xd17(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   10f0 <sleep@plt>
lea    0x3(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1060 <write@plt>
cmp    $0xffffffff,%eax
je     1443 <main+0x263>
movb   $0x33,0x3(%rsp)
lea    0x2(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1090 <read@plt>
cmp    $0xffffffff,%eax
je     143a <main+0x25a>
movsbl 0x2(%rsp),%esi
lea    0xcc1(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   10f0 <sleep@plt>
lea    0x3(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1060 <write@plt>
cmp    $0xffffffff,%eax
je     1443 <main+0x263>
movb   $0x34,0x3(%rsp)
lea    0x2(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1090 <read@plt>
cmp    $0xffffffff,%eax
je     143a <main+0x25a>
movsbl 0x2(%rsp),%esi
lea    0xc6b(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   10f0 <sleep@plt>
lea    0x3(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1060 <write@plt>
cmp    $0xffffffff,%eax
je     1443 <main+0x263>
movb   $0x35,0x3(%rsp)
lea    0x2(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1090 <read@plt>
cmp    $0xffffffff,%eax
je     143a <main+0x25a>
movsbl 0x2(%rsp),%esi
lea    0xc1d(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   10f0 <sleep@plt>
lea    0x3(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1060 <write@plt>
cmp    $0xffffffff,%eax
je     1443 <main+0x263>
mov    %ebx,%edi
call   1080 <close@plt>
lea    0xbd5(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xbcd(%rip),%rdi
jmp    144a <main+0x26a>
lea    0xbf3(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    0xba7(%rip),%rdi
jmp    144a <main+0x26a>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [14 x i8] c"server_socket\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [35 x i8] c"server waiting for client connect\0A\00"
@.str.3 = [33 x i8] c"the server wait for client data\0A\00"
@.str.4 = [5 x i8] c"read\00"
@.str.5 = [42 x i8] c"the character receiver from client is %c\0A\00"
@.str.6 = [6 x i8] c"write\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_un
%7 = alloca %struct.sockaddr_un
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
%11 = alloca i8
store i32 0, i32* %1
%12 = call i32 @unlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @AF_UNIX
%14 = load i32, i32* @SOCK_STREAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %0
%19 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %0
%22 = load i32, i32* @AF_UNIX
%23 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 1
store i32 %22, i32* %23
%24 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i32 @strcpy(i32 %25, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 8, i32* %4
%27 = load i32, i32* %2
%28 = bitcast %struct.sockaddr_un* %6 to %struct.sockaddr*
%29 = load i32, i32* %4
%30 = call i32 @bind(i32 %27, %struct.sockaddr* %28, i32 %29)
%31 = load i32, i32* %2
%32 = call i32 @listen(i32 %31, i32 5)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
store i32 8, i32* %5
%34 = load i32, i32* %2
%35 = bitcast %struct.sockaddr_un* %7 to %struct.sockaddr*
%36 = call i32 @accept(i32 %34, %struct.sockaddr* %35, i32* %5)
store i32 %36, i32* %3
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %8
store i8 49, i8* %10
br label %38
38: ; preds = %60, %21
%39 = load i32, i32* %8
%40 = icmp slt i32 %39, 5
br i1 %40, label %41, label %65
41: ; preds = %38
%42 = load i32, i32* %3
%43 = call i32 @read(i32 %42, i8* %11, i32 1)
store i32 %43, i32* %9
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %41
%49 = load i8, i8* %11
%50 = sext i8 %49 to i32
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i32 %50)
%52 = call i32 @sleep(i32 1)
%53 = load i32, i32* %3
%54 = call i32 @write(i32 %53, i8* %10, i32 1)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %59
56: ; preds = %48
%57 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %48
br label %60
60: ; preds = %59
%61 = load i32, i32* %8
%62 = add nsw i32 %61, 1
store i32 %62, i32* %8
%63 = load i8, i8* %10
%64 = add i8 %63, 1
store i8 %64, i8* %10
br label %38
65: ; preds = %38
%66 = load i32, i32* %3
%67 = call i32 @close(i32 %66)
%68 = call i32 @unlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [14 x i8] c"server_socket\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.4 = [5 x i8] c"read\00"
@.str.5 = [42 x i8] c"the character receiver from client is %c\0A\00"
@.str.6 = [6 x i8] c"write\00"
@str = [34 x i8] c"server waiting for client connect\00"
@str.7 = [32 x i8] c"the server wait for client data\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_un
%3 = alloca %struct.sockaddr_un
%4 = alloca i8
%5 = alloca i8
%6 = bitcast i32* %1 to i8*
%7 = bitcast %struct.sockaddr_un* %2 to i8*
%8 = bitcast %struct.sockaddr_un* %3 to i8*
%9 = tail call i32 @unlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @AF_UNIX
%11 = load i32, i32* @SOCK_STREAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = load i32, i32* @AF_UNIX
%19 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 1
store i32 %18, i32* %19
%20 = tail call i32 @strcpy(i32 undef, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%21 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%22 = call i32 @bind(i32 %12, %struct.sockaddr* %21, i32 8)
%23 = call i32 @listen(i32 %12, i32 5)
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
store i32 8, i32* %1
%25 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%26 = call i32 @accept(i32 %12, %struct.sockaddr* %25, i32* %1)
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.7, i64 0, i64 0))
store i8 49, i8* %4
%28 = call i32 @read(i32 %26, i8* %5, i32 1)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %33
30: ; preds = %73, %63, %53, %43, %17
%31 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %17
%34 = load i8, i8* %5
%35 = sext i8 %34 to i32
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i32 %35)
%37 = call i32 @sleep(i32 1)
%38 = call i32 @write(i32 %26, i8* %4, i32 1)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %76, %66, %56, %46, %33
%41 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %33
store i8 50, i8* %4
%44 = call i32 @read(i32 %26, i8* %5, i32 1)
%45 = icmp eq i32 %44, -1
br i1 %45, label %30, label %46
46: ; preds = %43
%47 = load i8, i8* %5
%48 = sext i8 %47 to i32
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i32 %48)
%50 = call i32 @sleep(i32 1)
%51 = call i32 @write(i32 %26, i8* %4, i32 1)
%52 = icmp eq i32 %51, -1
br i1 %52, label %40, label %53
53: ; preds = %46
store i8 51, i8* %4
%54 = call i32 @read(i32 %26, i8* %5, i32 1)
%55 = icmp eq i32 %54, -1
br i1 %55, label %30, label %56
56: ; preds = %53
%57 = load i8, i8* %5
%58 = sext i8 %57 to i32
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i32 %58)
%60 = call i32 @sleep(i32 1)
%61 = call i32 @write(i32 %26, i8* %4, i32 1)
%62 = icmp eq i32 %61, -1
br i1 %62, label %40, label %63
63: ; preds = %56
store i8 52, i8* %4
%64 = call i32 @read(i32 %26, i8* %5, i32 1)
%65 = icmp eq i32 %64, -1
br i1 %65, label %30, label %66
66: ; preds = %63
%67 = load i8, i8* %5
%68 = sext i8 %67 to i32
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i32 %68)
%70 = call i32 @sleep(i32 1)
%71 = call i32 @write(i32 %26, i8* %4, i32 1)
%72 = icmp eq i32 %71, -1
br i1 %72, label %40, label %73
73: ; preds = %66
store i8 53, i8* %4
%74 = call i32 @read(i32 %26, i8* %5, i32 1)
%75 = icmp eq i32 %74, -1
br i1 %75, label %30, label %76
76: ; preds = %73
%77 = load i8, i8* %5
%78 = sext i8 %77 to i32
%79 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i32 %78)
%80 = call i32 @sleep(i32 1)
%81 = call i32 @write(i32 %26, i8* %4, i32 1)
%82 = icmp eq i32 %81, -1
br i1 %82, label %40, label %83
83: ; preds = %76
%84 = call i32 @close(i32 %26)
%85 = call i32 @unlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
ret i32 0
}