#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*/ client;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ atoi(char *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/ *, char *,
                             int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
unsigned short ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, unsigned short);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char const *);
int /*<<< orphan*/ write(int, char const *, int /*<<< orphan*/);
int main(int argc, char *args[]) {
  int socketfd = socket(AF_INET, SOCK_STREAM, 0);
  if (socketfd < 0) {
    fprintf(stderr, "Socket error:%s\n\a", strerror(errno));
    exit(1);
  }
  struct sockaddr_in addr;
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_port = htons(atoi(args[1]));
  addr.sin_addr.s_addr = INADDR_ANY;
  if (bind(socketfd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
    fprintf(stderr, "Socket bind error:%s\n\a", strerror(errno));
    exit(1);
  }
  if (listen(socketfd, 10) < 0) {
    fprintf(stderr, "Socket listen error:%s\n\a", strerror(errno));
    exit(1);
  }
  struct sockaddr_in client;
  int lenth = sizeof(client);
  int fd = accept(socketfd, (struct sockaddr *)&client, &lenth);
  if (fd < 0) {
    fprintf(stderr, "Socket accept error:%s\n\a", strerror(errno));
    exit(1);
  }
  char buffer[16];
  inet_ntop(AF_INET, &client.sin_addr.s_addr, buffer, sizeof(client));
  unsigned short port = ntohs(client.sin_port);
  printf("client ip:%s port:%d", buffer, port);
  const char *str = "Hello Server under Ubuntu OS!";
  write(fd, str, strlen(str));
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1275 <main+0x75>
mov    0x2d8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    %rax,%rdx
lea    0xd9a(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2d5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    0x2d31(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
cmp    $0x0,%rax
jge    1305 <main+0x105>
mov    0x2cfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    0x2cde(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x68(%rbp),%edi
mov    %rax,%rdx
lea    0xd1c(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0xa,%esi
call   10b0 <listen@plt>
cmp    $0x0,%rax
jge    1352 <main+0x152>
mov    0x2cad(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    0x2c91(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    %rax,%rdx
lea    0xce6(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
movl   $0xc,-0x34(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    13ac <main+0x1ac>
mov    0x2c53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
mov    0x2c37(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x70(%rbp),%edi
mov    %rax,%rdx
lea    0xca5(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x2c35(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
add    $0x4,%rsi
lea    -0x50(%rbp),%rdx
mov    $0xc,%ecx
call   1030 <inet_ntop@plt>
mov    -0x30(%rbp),%edi
call   10c0 <ntohs@plt>
mov    %ax,-0x52(%rbp)
lea    -0x50(%rbp),%rsi
lea    0xc79(%rip),%rdi
movzwl -0x52(%rbp),%edx
call   1070 <printf@plt>
lea    0xc7e(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x7c(%rbp),%edi
mov    -0x78(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x38(%rbp),%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r14
mov    0x2dd3(%rip),%r12
mov    (%r12),%edi
mov    0x2da8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
test   %eax,%eax
js     1326 <main+0x126>
mov    %eax,%ebx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    (%r12),%eax
mov    %eax,0x18(%rsp)
mov    0x8(%r14),%rdi
call   10f0 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x2d76(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
test   %rax,%rax
js     1346 <main+0x146>
mov    %ebx,%edi
mov    $0xa,%esi
call   10b0 <listen@plt>
test   %rax,%rax
js     1366 <main+0x166>
movl   $0xc,0xc(%rsp)
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   10e0 <accept@plt>
test   %eax,%eax
js     1386 <main+0x186>
mov    %eax,%ebx
mov    (%r12),%edi
lea    0x24(%rsp),%rsi
lea    0x30(%rsp),%r14
mov    %r14,%rdx
mov    $0xc,%ecx
call   1030 <inet_ntop@plt>
mov    0x20(%rsp),%edi
call   10c0 <ntohs@plt>
movzwl %ax,%edx
lea    0xd6d(%rip),%rdi
mov    %r14,%rsi
call   1070 <printf@plt>
lea    0xd73(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebx,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2ca3(%rip),%rax
mov    (%rax),%ebx
mov    0x2c8a(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xcbc(%rip),%rsi
jmp    13a4 <main+0x1a4>
mov    0x2c83(%rip),%rax
mov    (%rax),%ebx
mov    0x2c6a(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xcae(%rip),%rsi
jmp    13a4 <main+0x1a4>
mov    0x2c63(%rip),%rax
mov    (%rax),%ebx
mov    0x2c4a(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xca5(%rip),%rsi
jmp    13a4 <main+0x1a4>
mov    0x2c43(%rip),%rax
mov    (%rax),%ebx
mov    0x2c2a(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xc9e(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"Socket error:%s\0A\07\00"
@errno = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [23 x i8] c"Socket bind error:%s\0A\07\00"
@.str.2 = [25 x i8] c"Socket listen error:%s\0A\07\00"
@.str.3 = [25 x i8] c"Socket accept error:%s\0A\07\00"
@.str.4 = [21 x i8] c"client ip:%s port:%d\00"
@.str.5 = [30 x i8] c"Hello Server under Ubuntu OS!\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = alloca i32
%11 = alloca [16 x i8]
%12 = alloca i16
%13 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%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* %6
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %2
%26 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 12)
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %27, i32* %28
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
%33 = call i32 @htons(i32 %32)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %33, i32* %34
%35 = load i32, i32* @INADDR_ANY
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%37 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %36, i32 0, i32 0
store i32 %35, i32* %37
%38 = load i32, i32* %6
%39 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%40 = call i64 @bind(i32 %38, %struct.sockaddr* %39, i32 12)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %25
%43 = load i32, i32* @stderr
%44 = load i32, i32* @errno
%45 = call i8* @strerror(i32 %44)
%46 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %45)
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %25
%49 = load i32, i32* %6
%50 = call i64 @listen(i32 %49, i32 10)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %58
52: ; preds = %48
%53 = load i32, i32* @stderr
%54 = load i32, i32* @errno
%55 = call i8* @strerror(i32 %54)
%56 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %55)
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %48
store i32 12, i32* %9
%59 = load i32, i32* %6
%60 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%61 = call i32 @accept(i32 %59, %struct.sockaddr* %60, i32* %9)
store i32 %61, i32* %10
%62 = load i32, i32* %10
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %70
64: ; preds = %58
%65 = load i32, i32* @stderr
%66 = load i32, i32* @errno
%67 = call i8* @strerror(i32 %66)
%68 = call i32 @fprintf(i32 %65, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %67)
%69 = call i32 @exit(i32 1)
unreachable
70: ; preds = %58
%71 = load i32, i32* @AF_INET
%72 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%73 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %72, i32 0, i32 0
%74 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%75 = call i32 @inet_ntop(i32 %71, i32* %73, i8* %74, i32 12)
%76 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%77 = load i32, i32* %76
%78 = call zeroext i16 @ntohs(i32 %77)
store i16 %78, i16* %12
%79 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%80 = load i16, i16* %12
%81 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %79, i16 zeroext %80)
store i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i8** %13
%82 = load i32, i32* %10
%83 = load i8*, i8** %13
%84 = load i8*, i8** %13
%85 = call i32 @strlen(i8* %84)
%86 = call i32 @write(i32 %82, i8* %83, i32 %85)
%87 = load i32, i32* %10
%88 = call i32 @close(i32 %87)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"Socket error:%s\0A\07\00"
@errno = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [23 x i8] c"Socket bind error:%s\0A\07\00"
@.str.2 = [25 x i8] c"Socket listen error:%s\0A\07\00"
@.str.3 = [25 x i8] c"Socket accept error:%s\0A\07\00"
@.str.4 = [21 x i8] c"client ip:%s port:%d\00"
@.str.5 = [30 x i8] c"Hello Server under Ubuntu OS!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [16 x i8]
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = tail call i8* @strerror(i32 %13)
%15 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = bitcast %struct.sockaddr_in* %3 to i8*
%19 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %20, i32* %21
%22 = getelementptr inbounds i8*, i8** %1, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
%25 = call i32 @htons(i32 %24)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %25, i32* %26
%27 = load i32, i32* @INADDR_ANY
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %27, i32* %28
%29 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%30 = call i64 @bind(i32 %9, %struct.sockaddr* %29, i32 12)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %17
%33 = load i32, i32* @stderr
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %17
%39 = call i64 @listen(i32 %9, i32 10)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %38
%42 = load i32, i32* @stderr
%43 = load i32, i32* @errno
%44 = call i8* @strerror(i32 %43)
%45 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %44)
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %38
%48 = bitcast %struct.sockaddr_in* %4 to i8*
%49 = bitcast i32* %5 to i8*
store i32 12, i32* %5
%50 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%51 = call i32 @accept(i32 %9, %struct.sockaddr* %50, i32* %5)
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %59
53: ; preds = %47
%54 = load i32, i32* @stderr
%55 = load i32, i32* @errno
%56 = call i8* @strerror(i32 %55)
%57 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %56)
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %47
%60 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%61 = load i32, i32* @AF_INET
%62 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
%63 = call i32 @inet_ntop(i32 %61, i32* %62, i8* %60, i32 12)
%64 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%65 = load i32, i32* %64
%66 = call zeroext i16 @ntohs(i32 %65)
%67 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %60, i16 zeroext %66)
%68 = call i32 @strlen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%69 = call i32 @write(i32 %51, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %68)
%70 = call i32 @close(i32 %51)
ret i32 0
}