#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 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_DGRAM;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, TYPE_1__ *, char *, int);
int /*<<< orphan*/ my_fun(char *);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  struct sockaddr_in sin;
  struct sockaddr_in cin;
  int s_fd;
  int port = 8000;
  socklen_t addr_len;
  char buf[100];
  char addr_p[INET_ADDRSTRLEN];
  int n;
  bzero(&sin, sizeof(sin));
  sin.sin_family = AF_INET;
  sin.sin_addr.s_addr = INADDR_ANY;
  sin.sin_port = htons(port);
  s_fd = socket(AF_INET, SOCK_DGRAM, 0);
  if (s_fd == -1) {
    perror("fail to create socket");
    exit(1);
  }
  if (bind(s_fd, (struct sockaddr *)&sin, sizeof(sin)) == -1) {
    perror("call to bind");
    exit(1);
  }
  while (1) {
    addr_len = sizeof(sin);
    n = recvfrom(s_fd, buf, 100, 0, (struct sockaddr *)&cin, &addr_len);
    if (n == -1) {
      perror("fail to receive\n");
      exit(1);
    }
    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);
    n = sendto(s_fd, buf, n, 0, (struct sockaddr *)&cin, addr_len);
    if (n == -1) {
      perror("fail to send\n");
      exit(1);
    }
  }
  if (close(s_fd) == -1) {
    perror("fail to close");
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1f40,-0x28(%rbp)
mov    0x2de8(%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)
lea    -0x10(%rbp),%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2daa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x28(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x10(%rbp)
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
mov    0x2d82(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1282 <main+0xc2>
lea    0xd8d(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x24(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
cmp    $0xffffffff,%eax
jne    12b2 <main+0xf2>
lea    0xd73(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    12b7 <main+0xf7>
jmp    12bc <main+0xfc>
movl   $0xc,-0x2c(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x90(%rbp),%rsi
lea    -0x20(%rbp),%r8
mov    $0x64,%edx
xor    %ecx,%ecx
lea    -0x2c(%rbp),%r9
call   1070 <recvfrom@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0xffffffff,-0xa4(%rbp)
jne    130a <main+0x14a>
lea    0xd28(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0xb0(%rbp),%rdx
mov    -0xb8(%rbp),%rax
mov    0x2cc9(%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   1080 <ntohs@plt>
mov    -0xb0(%rbp),%rsi
mov    %eax,%edx
lea    0xcec(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x90(%rbp),%rsi
lea    0xcf4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x90(%rbp),%rdi
call   10d0 <my_fun@plt>
mov    -0x24(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    -0xa4(%rbp),%edx
lea    -0x20(%rbp),%r8
mov    -0x2c(%rbp),%r9d
xor    %ecx,%ecx
call   1060 <sendto@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0xffffffff,-0xa4(%rbp)
jne    13b8 <main+0x1f8>
lea    0xcb9(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    12b7 <main+0xf7>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r15
mov    %rax,-0x40(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
lea    -0x38(%rbp),%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    0x2de1(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,-0x30(%rbp)
mov    0x2dcd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    $0x1f40,%edi
call   1040 <htons@plt>
mov    %eax,-0x38(%rbp)
mov    (%rbx),%edi
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
cmp    $0xffffffff,%eax
jne    1248 <main+0x88>
lea    0xdbd(%rip),%rdi
jmp    1325 <main+0x165>
mov    %eax,%r13d
lea    -0x38(%rbp),%rsi
mov    %eax,%edi
mov    $0xc,%edx
call   1090 <bind@plt>
cmp    $0xffffffff,%eax
jne    126c <main+0xac>
lea    0xdaf(%rip),%rdi
jmp    1325 <main+0x165>
lea    -0xc0(%rbp),%rbx
lea    -0x50(%rbp),%r12
nopw   0x0(%rax,%rax,1)
movl   $0xc,-0x2c(%rbp)
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
mov    %r12,%r8
lea    -0x2c(%rbp),%r9
call   1070 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     131e <main+0x15e>
mov    %eax,%r14d
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
lea    -0x4c(%rbp),%rsi
mov    %r15,%rdx
mov    -0x40(%rbp),%rcx
call   1030 <inet_ntop@plt>
mov    -0x50(%rbp),%edi
call   1080 <ntohs@plt>
lea    0xd64(%rip),%rdi
mov    %r15,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd6e(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   10d0 <my_fun@plt>
mov    -0x2c(%rbp),%r9d
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
mov    %r12,%r8
call   1060 <sendto@plt>
cmp    $0xffffffff,%eax
jne    1280 <main+0xc0>
lea    0xd46(%rip),%rdi
jmp    1325 <main+0x165>
lea    0xcfe(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

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_DGRAM = global i32 0
@.str = [22 x i8] c"fail to create socket\00"
@.str.1 = [13 x i8] c"call to bind\00"
@.str.2 = [17 x i8] c"fail to receive\0A\00"
@.str.3 = [29 x i8] c"client IP is %s, port is %d\0A\00"
@.str.4 = [17 x i8] c"content is : %s\0A\00"
@.str.5 = [14 x i8] c"fail to send\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
store i32 0, i32* %1
store i32 8000, i32* %5
%11 = load i32, i32* @INET_ADDRSTRLEN
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %8
%14 = alloca i8, i64 %12
store i64 %12, i64* %9
%15 = call i32 @bzero(%struct.sockaddr_in* %2, i32 12)
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
store i32 %16, i32* %17
%18 = load i32, i32* @INADDR_ANY
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
store i32 %18, i32* %20
%21 = load i32, i32* %5
%22 = call i32 @htons(i32 %21)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
store i32 %22, i32* %23
%24 = load i32, i32* @AF_INET
%25 = load i32, i32* @SOCK_DGRAM
%26 = call i32 @socket(i32 %24, i32 %25, i32 0)
store i32 %26, i32* %4
%27 = load i32, i32* %4
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %0
%30 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %0
%33 = load i32, i32* %4
%34 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%35 = call i32 @bind(i32 %33, %struct.sockaddr* %34, i32 12)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %32
br label %41
41: ; preds = %76, %40
br label %42
42: ; preds = %41
store i32 12, i32* %6
%43 = load i32, i32* %4
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%45 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%46 = call i32 @recvfrom(i32 %43, i8* %44, i32 100, i32 0, %struct.sockaddr* %45, i32* %6)
store i32 %46, i32* %10
%47 = load i32, i32* %10
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %52
49: ; preds = %42
%50 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %42
%53 = load i32, i32* @AF_INET
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%55 = trunc i64 %12 to i32
%56 = call i32 @inet_ntop(i32 %53, %struct.TYPE_2__* %54, i8* %14, i32 %55)
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%58 = load i32, i32* %57
%59 = call i32 @ntohs(i32 %58)
%60 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %14, i32 %59)
%61 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%62 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %61)
%63 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%64 = call i32 @my_fun(i8* %63)
%65 = load i32, i32* %4
%66 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%67 = load i32, i32* %10
%68 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%69 = load i32, i32* %6
%70 = call i32 @sendto(i32 %65, i8* %66, i32 %67, i32 0, %struct.sockaddr* %68, i32 %69)
store i32 %70, i32* %10
%71 = load i32, i32* %10
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %76
73: ; preds = %52
%74 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %52
br label %41
}

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_DGRAM = global i32 0
@.str = [22 x i8] c"fail to create socket\00"
@.str.1 = [13 x i8] c"call to bind\00"
@.str.2 = [17 x i8] c"fail to receive\0A\00"
@.str.3 = [29 x i8] c"client IP is %s, port is %d\0A\00"
@.str.4 = [17 x i8] c"content is : %s\0A\00"
@.str.5 = [14 x i8] c"fail to send\0A\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_DGRAM
%21 = tail call i32 @socket(i32 %19, i32 %20, i32 0)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %0
%24 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %0
%27 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%28 = call i32 @bind(i32 %21, %struct.sockaddr* %27, i32 12)
%29 = icmp eq i32 %28, -1
br i1 %29, label %34, label %30
30: ; preds = %26
%31 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
br label %37
34: ; preds = %26
%35 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %30, %43
store i32 12, i32* %3
%38 = call i32 @recvfrom(i32 %21, i8* %8, i32 100, i32 0, %struct.sockaddr* %31, i32* %3)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %37
%44 = load i32, i32* @AF_INET
%45 = call i32 @inet_ntop(i32 %44, %struct.TYPE_2__* %32, i8* %11, i32 %9)
%46 = load i32, i32* %33
%47 = call i32 @ntohs(i32 %46)
%48 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %11, i32 %47)
%49 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %8)
%50 = call i32 @my_fun(i8* %8)
%51 = load i32, i32* %3
%52 = call i32 @sendto(i32 %21, i8* %8, i32 %38, i32 0, %struct.sockaddr* %31, i32 %51)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %37
54: ; preds = %43
%55 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
}