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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int server_sockfd;
  int client_sockfd;
  int server_len, client_len;
  struct sockaddr_un server_address;
  struct sockaddr_un client_address;
  unlink("server_socket");
  server_sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
  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);
  while (1) {
    char ch;
    printf("Server waiting\n");
    client_len = sizeof(client_address);
    client_sockfd =
        accept(server_sockfd, (struct sockaddr *)&client_address, &client_len);
    read(client_sockfd, &ch, 1);
    ch++;
    write(client_sockfd, &ch, 1);
    close(client_sockfd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe43(%rip),%rdi
call   1030 <unlink@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%edi
lea    0xe0c(%rip),%rsi
call   1040 <strcpy@plt>
movl   $0x8,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   10a0 <bind@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   1090 <listen@plt>
lea    0xdeb(%rip),%rdi
call   1060 <printf@plt>
movl   $0x8,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   10b0 <accept@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x31(%rbp),%rsi
mov    $0x1,%edx
call   1080 <read@plt>
mov    -0x31(%rbp),%al
add    $0x1,%al
mov    %al,-0x32(%rbp)
mov    %al,-0x31(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x31(%rbp),%rsi
mov    $0x1,%edx
call   1050 <write@plt>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
jmp    121c <main+0x7c>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe4b(%rip),%rbx
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    0x2e24(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%r13d
mov    0x0(%rbp),%eax
mov    %eax,0xc(%rsp)
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0x8(%rsp),%rsi
mov    %r13d,%edi
mov    $0x8,%edx
call   10a0 <bind@plt>
mov    %r13d,%edi
mov    $0x5,%esi
call   1090 <listen@plt>
lea    0xdff(%rip),%r14
lea    0x10(%rsp),%r15
lea    0x4(%rsp),%r12
lea    0x3(%rsp),%rbx
xchg   %ax,%ax
mov    %r14,%rdi
call   1050 <puts@plt>
movl   $0x8,0x4(%rsp)
mov    %r13d,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   10b0 <accept@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1080 <read@plt>
addb   $0x1,0x3(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1060 <write@plt>
mov    %ebp,%edi
call   1070 <close@plt>
jmp    1220 <main+0x80>

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 = [16 x i8] c"Server waiting\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_un
%11 = alloca %struct.sockaddr_un
%12 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32 @unlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @AF_UNIX
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %6
%17 = load i32, i32* @AF_UNIX
%18 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %10, i32 0, i32 1
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %10, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @strcpy(i32 %20, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 8, i32* %8
%22 = load i32, i32* %6
%23 = bitcast %struct.sockaddr_un* %10 to %struct.sockaddr*
%24 = load i32, i32* %8
%25 = call i32 @bind(i32 %22, %struct.sockaddr* %23, i32 %24)
%26 = load i32, i32* %6
%27 = call i32 @listen(i32 %26, i32 5)
br label %28
28: ; preds = %2, %28
%29 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 8, i32* %9
%30 = load i32, i32* %6
%31 = bitcast %struct.sockaddr_un* %11 to %struct.sockaddr*
%32 = call i32 @accept(i32 %30, %struct.sockaddr* %31, i32* %9)
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = call i32 @read(i32 %33, i8* %12, i32 1)
%35 = load i8, i8* %12
%36 = add i8 %35, 1
store i8 %36, i8* %12
%37 = load i32, i32* %7
%38 = call i32 @write(i32 %37, i8* %12, i32 1)
%39 = load i32, i32* %7
%40 = call i32 @close(i32 %39)
br label %28
}

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 = [15 x i8] c"Server waiting\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_un
%5 = alloca %struct.sockaddr_un
%6 = alloca i8
%7 = bitcast i32* %3 to i8*
%8 = bitcast %struct.sockaddr_un* %4 to i8*
%9 = bitcast %struct.sockaddr_un* %5 to i8*
%10 = tail call i32 @unlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @AF_UNIX
%12 = load i32, i32* @SOCK_STREAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = load i32, i32* @AF_UNIX
%15 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i64 0, i32 1
store i32 %14, i32* %15
%16 = tail call i32 @strcpy(i32 undef, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%17 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%18 = call i32 @bind(i32 %13, %struct.sockaddr* %17, i32 8)
%19 = call i32 @listen(i32 %13, i32 5)
%20 = bitcast %struct.sockaddr_un* %5 to %struct.sockaddr*
br label %21
21: ; preds = %21, %2
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
store i32 8, i32* %3
%23 = call i32 @accept(i32 %13, %struct.sockaddr* %20, i32* %3)
%24 = call i32 @read(i32 %23, i8* %6, i32 1)
%25 = load i8, i8* %6
%26 = add i8 %25, 1
store i8 %26, i8* %6
%27 = call i32 @write(i32 %23, i8* %6, i32 1)
%28 = call i32 @close(i32 %23)
br label %21
}