#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ server_address;
typedef int /*<<< orphan*/ client_address;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ inet_addr(char *);
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*/ 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_in server_address;
  struct sockaddr_in client_address;
  unlink("server_socket");
  server_sockfd = socket(AF_INET, SOCK_STREAM, 0);
  server_address.sin_family = AF_INET;
  server_address.sin_addr.s_addr = inet_addr("127.0.0.0");
  server_address.sin_port = 9734;
  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    $0x50,%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,-0x28(%rbp)
lea    0xe1d(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x2c(%rbp)
movl   $0x2606,-0x30(%rbp)
movl   $0xc,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   10a0 <bind@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   1090 <listen@plt>
lea    0xdee(%rip),%rdi
call   1050 <printf@plt>
movl   $0xc,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   10b0 <accept@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x41(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    -0x41(%rbp),%al
add    $0x1,%al
mov    %al,-0x42(%rbp)
mov    %al,-0x41(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x41(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
jmp    1223 <main+0x83>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xe4b(%rip),%rdi
call   1030 <unlink@plt>
mov    0x2e27(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%r13d
mov    (%rbx),%eax
mov    %eax,0x10(%rsp)
lea    0xe2b(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,0xc(%rsp)
movl   $0x2606,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %r13d,%edi
mov    $0xc,%edx
call   10a0 <bind@plt>
mov    %r13d,%edi
mov    $0x5,%esi
call   1090 <listen@plt>
lea    0xdfe(%rip),%r14
lea    0x18(%rsp),%r15
lea    0x4(%rsp),%r12
lea    0x3(%rsp),%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
call   1040 <puts@plt>
movl   $0xc,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   1070 <read@plt>
addb   $0x1,0x3(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <write@plt>
mov    %ebp,%edi
call   1060 <close@plt>
jmp    1230 <main+0x90>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [14 x i8] c"server_socket\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [10 x i8] c"127.0.0.0\00"
@.str.2 = [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_in
%11 = alloca %struct.sockaddr_in
%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_INET
%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_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %17, i32* %18
%19 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
store i32 %19, i32* %21
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 9734, i32* %22
store i32 12, i32* %8
%23 = load i32, i32* %6
%24 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%25 = load i32, i32* %8
%26 = call i32 @bind(i32 %23, %struct.sockaddr* %24, i32 %25)
%27 = load i32, i32* %6
%28 = call i32 @listen(i32 %27, i32 5)
br label %29
29: ; preds = %2, %29
%30 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 12, i32* %9
%31 = load i32, i32* %6
%32 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%33 = call i32 @accept(i32 %31, %struct.sockaddr* %32, i32* %9)
store i32 %33, i32* %7
%34 = load i32, i32* %7
%35 = call i32 @read(i32 %34, i8* %12, i32 1)
%36 = load i8, i8* %12
%37 = add i8 %36, 1
store i8 %37, i8* %12
%38 = load i32, i32* %7
%39 = call i32 @write(i32 %38, i8* %12, i32 1)
%40 = load i32, i32* %7
%41 = call i32 @close(i32 %40)
br label %29
}

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