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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int INET_ADDRSTRLEN;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, TYPE_1__ *, char *, int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ my_fun(char *);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  struct sockaddr_in sin;
  struct sockaddr_in cin;
  int l_fd;
  int c_fd;
  socklen_t len;
  char buf[100];
  char addr_p[INET_ADDRSTRLEN];
  int port = 8000;
  int n;
  bzero(&sin, sizeof(sin));
  sin.sin_family = AF_INET;
  sin.sin_addr.s_addr = INADDR_ANY;
  sin.sin_port = htons(port);
  l_fd = socket(AF_INET, SOCK_STREAM, 0);
  bind(l_fd, (struct sockaddr *)&sin, sizeof(sin));
  listen(l_fd, 10);
  printf("waiting ...\n");
  while (1) {
    c_fd = accept(l_fd, (struct sockaddr *)&cin, &len);
    n = read(c_fd, buf, 100);
    inet_ntop(AF_INET, &cin.sin_addr, addr_p, sizeof(addr_p));
    printf("client IP is %s, port is %d\n", addr_p, ntohs(cin.sin_port));
    printf("content is : %s\n", buf);
    my_fun(buf);
    write(c_fd, buf, n);
    close(c_fd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2ddf(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0xb8(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x98(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xb0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0xa0(%rbp)
movl   $0x1f40,-0xa4(%rbp)
lea    -0x10(%rbp),%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2d97(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xa4(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x10(%rbp)
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
mov    0x2d64(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
mov    -0x24(%rbp),%edi
mov    $0xa,%esi
call   1090 <listen@plt>
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12a9 <main+0xd9>
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x64,%edx
call   1080 <read@plt>
mov    -0xb0(%rbp),%rdx
mov    %eax,%ecx
mov    -0xb8(%rbp),%rax
mov    %ecx,-0xa8(%rbp)
mov    0x2cfb(%rip),%rcx
mov    (%rcx),%edi
lea    -0x20(%rbp),%rsi
add    $0x4,%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x20(%rbp),%edi
call   10a0 <ntohs@plt>
mov    -0xb0(%rbp),%rsi
mov    %eax,%edx
lea    0xcf7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x90(%rbp),%rsi
lea    0xcff(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x90(%rbp),%rdi
call   10e0 <my_fun@plt>
mov    -0x28(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    -0xa8(%rbp),%edx
call   1040 <write@plt>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
jmp    12a4 <main+0xd4>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    0x2dcd(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
mov    %rax,-0x40(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x38(%rbp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    0x2dbe(%rip),%r15
mov    (%r15),%eax
mov    %eax,-0x30(%rbp)
mov    0x2da9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    $0x1f40,%edi
call   1060 <htons@plt>
mov    %eax,-0x38(%rbp)
mov    (%r15),%edi
mov    0x2d7d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,%r15d
mov    %eax,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
mov    %r15d,%edi
mov    $0xa,%esi
call   10a0 <listen@plt>
lea    0xdac(%rip),%rdi
call   1040 <puts@plt>
lea    -0xc0(%rbp),%r13
xchg   %ax,%ax
mov    %r15d,%edi
lea    -0x50(%rbp),%rsi
lea    -0x54(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,%r12d
mov    %eax,%edi
mov    %r13,%rsi
mov    $0x64,%edx
call   1090 <read@plt>
mov    %eax,%r14d
mov    0x2d2c(%rip),%rax
mov    (%rax),%edi
lea    -0x4c(%rbp),%rsi
mov    %rbx,%rdx
mov    -0x40(%rbp),%rcx
call   1030 <inet_ntop@plt>
mov    -0x50(%rbp),%edi
call   10b0 <ntohs@plt>
lea    0xd23(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd2d(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13,%rdi
call   10f0 <my_fun@plt>
mov    %r12d,%edi
mov    %r13,%rsi
mov    %r14d,%edx
call   1050 <write@plt>
mov    %r12d,%edi
call   1080 <close@plt>
jmp    1290 <main+0xb0>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@INET_ADDRSTRLEN = global i32 0
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOCK_STREAM = global i32 0
@.str = [13 x i8] c"waiting ...\0A\00"
@.str.1 = [29 x i8] c"client IP is %s, port is %d\0A\00"
@.str.2 = [17 x i8] c"content is : %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [100 x i8]
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %1
%12 = load i32, i32* @INET_ADDRSTRLEN
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %8
%15 = alloca i8, i64 %13
store i64 %13, i64* %9
store i32 8000, i32* %10
%16 = call i32 @bzero(%struct.sockaddr_in* %2, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
store i32 %17, i32* %18
%19 = load i32, i32* @INADDR_ANY
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
store i32 %19, i32* %21
%22 = load i32, i32* %10
%23 = call i32 @htons(i32 %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
store i32 %23, i32* %24
%25 = load i32, i32* @AF_INET
%26 = load i32, i32* @SOCK_STREAM
%27 = call i32 @socket(i32 %25, i32 %26, i32 0)
store i32 %27, i32* %4
%28 = load i32, i32* %4
%29 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%30 = call i32 @bind(i32 %28, %struct.sockaddr* %29, i32 12)
%31 = load i32, i32* %4
%32 = call i32 @listen(i32 %31, i32 10)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %34
34: ; preds = %35, %0
br label %35
35: ; preds = %34
%36 = load i32, i32* %4
%37 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%38 = call i32 @accept(i32 %36, %struct.sockaddr* %37, i32* %6)
store i32 %38, i32* %5
%39 = load i32, i32* %5
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%41 = call i32 @read(i32 %39, i8* %40, i32 100)
store i32 %41, i32* %11
%42 = load i32, i32* @AF_INET
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%44 = trunc i64 %13 to i32
%45 = call i32 @inet_ntop(i32 %42, %struct.TYPE_2__* %43, i8* %15, i32 %44)
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%47 = load i32, i32* %46
%48 = call i32 @ntohs(i32 %47)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %15, i32 %48)
%50 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %50)
%52 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%53 = call i32 @my_fun(i8* %52)
%54 = load i32, i32* %5
%55 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%56 = load i32, i32* %11
%57 = call i32 @write(i32 %54, i8* %55, i32 %56)
%58 = load i32, i32* %5
%59 = call i32 @close(i32 %58)
br label %34
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@INET_ADDRSTRLEN = global i32 0
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [29 x i8] c"client IP is %s, port is %d\0A\00"
@.str.2 = [17 x i8] c"content is : %s\0A\00"
@str = [12 x i8] c"waiting ...\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = bitcast %struct.sockaddr_in* %1 to i8*
%6 = bitcast %struct.sockaddr_in* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* @INET_ADDRSTRLEN
%10 = zext i32 %9 to i64
%11 = alloca i8, i64 %10
%12 = call i32 @bzero(%struct.sockaddr_in* %1, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %13, i32* %14
%15 = load i32, i32* @INADDR_ANY
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %15, i32* %16
%17 = tail call i32 @htons(i32 8000)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %17, i32* %18
%19 = load i32, i32* @AF_INET
%20 = load i32, i32* @SOCK_STREAM
%21 = tail call i32 @socket(i32 %19, i32 %20, i32 0)
%22 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%23 = call i32 @bind(i32 %21, %struct.sockaddr* %22, i32 12)
%24 = call i32 @listen(i32 %21, i32 10)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%26 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
br label %29
29: ; preds = %29, %0
%30 = call i32 @accept(i32 %21, %struct.sockaddr* %26, i32* %3)
%31 = call i32 @read(i32 %30, i8* %8, i32 100)
%32 = load i32, i32* @AF_INET
%33 = call i32 @inet_ntop(i32 %32, %struct.TYPE_2__* %27, i8* %11, i32 %9)
%34 = load i32, i32* %28
%35 = call i32 @ntohs(i32 %34)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 %35)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%38 = call i32 @my_fun(i8* %8)
%39 = call i32 @write(i32 %30, i8* %8, i32 %31)
%40 = call i32 @close(i32 %30)
br label %29
}