#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 {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ sser;

/* 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*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
main() {
  int server, client;
  struct sockaddr_in sser, scli;
  int lenstru = sizeof(sser);
  server = socket(AF_INET, SOCK_STREAM, 0);
  sser.sin_family = AF_INET;
  sser.sin_port = htons(8006);
  sser.sin_addr.s_addr = inet_addr("127.0.0.1");
  bind(server, (struct sockaddr *)&sser, lenstru);
  listen(server, 100);
  while (1) {
    client = accept(server, (struct sockaddr *)&scli, &lenstru);
    if (client != -1) {
      char buf[30];
      int nb;
      nb = read(client, buf, 30);
      buf[nb] = '\0';
      printf("%s\n", buf);
      write(client, "gracias cliente", 30);
      close(client);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xc,-0x2c(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x1f46,%edi
call   1040 <htons@plt>
mov    %eax,-0x14(%rbp)
lea    0xe0e(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   10a0 <bind@plt>
mov    -0x8(%rbp),%edi
mov    $0x64,%esi
call   1090 <listen@plt>
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   10b0 <accept@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
je     127c <main+0xdc>
mov    -0xc(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x1e,%edx
call   1070 <read@plt>
mov    %eax,-0x54(%rbp)
movslq -0x54(%rbp),%rax
movb   $0x0,-0x50(%rbp,%rax,1)
lea    -0x50(%rbp),%rsi
lea    0xdaf(%rip),%rdi
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
lea    0xda4(%rip),%rsi
mov    $0x1e,%edx
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
jmp    1216 <main+0x76>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
movl   $0xc,0xc(%rsp)
mov    0x2e2b(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%ebx
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    $0x1f46,%edi
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
lea    0xe12(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10a0 <bind@plt>
mov    %ebx,%edi
mov    $0x64,%esi
call   1090 <listen@plt>
lea    0x20(%rsp),%r14
lea    0xc(%rsp),%r15
lea    0x30(%rsp),%r12
lea    0xde4(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   10b0 <accept@plt>
cmp    $0xffffffff,%eax
je     1230 <main+0x90>
mov    %eax,%r13d
mov    %eax,%edi
mov    %r12,%rsi
mov    $0x1e,%edx
call   1070 <read@plt>
cltq
movb   $0x0,0x30(%rsp,%rax,1)
lea    0xda8(%rip),%rdi
mov    %r12,%rsi
call   1050 <printf@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x1e,%edx
call   1030 <write@plt>
mov    %r13d,%edi
call   1060 <close@plt>
jmp    1230 <main+0x90>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [16 x i8] c"gracias cliente\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca [30 x i8]
%8 = alloca i32
store i32 0, i32* %1
store i32 12, i32* %6
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %2
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %12, i32* %13
%14 = call i32 @htons(i32 8006)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i32 %14, i32* %15
%16 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i32 0, i32 0
store i32 %16, i32* %18
%19 = load i32, i32* %2
%20 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%21 = load i32, i32* %6
%22 = call i32 @bind(i32 %19, %struct.sockaddr* %20, i32 %21)
%23 = load i32, i32* %2
%24 = call i32 @listen(i32 %23, i32 100)
br label %25
25: ; preds = %0, %44
%26 = load i32, i32* %2
%27 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%28 = call i32 @accept(i32 %26, %struct.sockaddr* %27, i32* %6)
store i32 %28, i32* %3
%29 = load i32, i32* %3
%30 = icmp ne i32 %29, -1
br i1 %30, label %31, label %44
31: ; preds = %25
%32 = load i32, i32* %3
%33 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%34 = call i32 @read(i32 %32, i8* %33, i32 30)
store i32 %34, i32* %8
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 %36
store i8 0, i8* %37
%38 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%39 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %38)
%40 = load i32, i32* %3
%41 = call i32 @write(i32 %40, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 30)
%42 = load i32, i32* %3
%43 = call i32 @close(i32 %42)
br label %44
44: ; preds = %31, %25
br label %25
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [16 x i8] c"gracias cliente\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca [30 x i8]
%5 = bitcast %struct.sockaddr_in* %1 to i8*
%6 = bitcast %struct.sockaddr_in* %2 to i8*
%7 = bitcast i32* %3 to i8*
store i32 12, i32* %3
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = tail call i32 @socket(i32 %8, i32 %9, i32 0)
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %11, i32* %12
%13 = tail call i32 @htons(i32 8006)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %13, i32* %14
%15 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %15, i32* %16
%17 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%18 = call i32 @bind(i32 %10, %struct.sockaddr* %17, i32 12)
%19 = call i32 @listen(i32 %10, i32 100)
%20 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%21 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
br label %22
22: ; preds = %32, %0
%23 = call i32 @accept(i32 %10, %struct.sockaddr* %20, i32* %3)
%24 = icmp eq i32 %23, -1
br i1 %24, label %32, label %25
25: ; preds = %22
%26 = call i32 @read(i32 %23, i8* %21, i32 30)
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 %27
store i8 0, i8* %28
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%30 = call i32 @write(i32 %23, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 30)
%31 = call i32 @close(i32 %23)
br label %32
32: ; preds = %25, %22
br label %22
}