#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*/ str;
typedef int socklen_t;
typedef int /*<<< orphan*/ serv_addr;
typedef int /*<<< orphan*/ cli_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ atoi(char *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ usleep(int);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int sockfd, clifd;
  struct sockaddr_in serv_addr, cli_addr;
  socklen_t cli_len;
  int ret;
  char msg[] = "hello, world!\n";
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <port>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    perror("socket() failed");
    exit(EXIT_FAILURE);
  }
  memset(&serv_addr, 0, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  serv_addr.sin_port = htons(atoi(argv[1]));
  if (bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) == -1) {
    fprintf(stderr, "bind() failed: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (listen(sockfd, 5) == -1) {
    fprintf(stderr, "listen() failed: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  cli_len = sizeof(cli_addr);
  clifd = accept(sockfd, (struct sockaddr *)&cli_addr, &cli_len);
  if (clifd == -1) {
    fprintf(stderr, "accept() failed: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  usleep(3500);
  char str[] = "abcdefg,hijklmn, opq, rst, uvw, xyz";
  ret = write(clifd, str, sizeof(str));
  close(clifd);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xde0(%rip),%rax
mov    %rax,-0x4f(%rbp)
mov    0xdde(%rip),%eax
mov    %eax,-0x47(%rbp)
mov    0xdd8(%rip),%ax
mov    %ax,-0x43(%rbp)
mov    0xdd0(%rip),%al
mov    %al,-0x41(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1275 <main+0x75>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdad(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
mov    0x2d43(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    12b4 <main+0xb4>
lea    0xd80(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2d1d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1352 <main+0x152>
mov    0x2cb7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x84(%rbp)
mov    0x2c98(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x84(%rbp),%edi
mov    %rax,%rdx
lea    0xcf2(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2c6d(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
jne    13a8 <main+0x1a8>
mov    0x2c61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x88(%rbp)
mov    0x2c42(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x88(%rbp),%edi
mov    %rax,%rdx
lea    0xcaf(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2c17(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
movl   $0xc,-0x3c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    140c <main+0x20c>
mov    0x2bfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    0x2bde(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x8c(%rbp),%edi
mov    %rax,%rdx
lea    0xc60(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2bb3(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    $0xdac,%edi
call   1110 <usleep@plt>
lea    -0x80(%rbp),%rdi
lea    0xc4f(%rip),%rsi
mov    $0x24,%edx
call   1090 <memcpy@plt>
mov    -0x18(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x24,%edx
call   1030 <write@plt>
mov    %eax,-0x40(%rbp)
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jne    1313 <main+0x123>
mov    0x2ddb(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2db1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
cmp    $0xffffffff,%eax
je     1328 <main+0x138>
mov    %eax,%ebx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    0x8(%r14),%rdi
call   10d0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
je     1336 <main+0x146>
mov    %ebx,%edi
mov    $0x5,%esi
call   1090 <listen@plt>
cmp    $0xffffffff,%eax
je     1356 <main+0x166>
movl   $0xc,0xc(%rsp)
lea    0x48(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   10c0 <accept@plt>
cmp    $0xffffffff,%eax
je     1376 <main+0x186>
mov    %eax,%ebp
mov    $0xdac,%edi
call   1100 <usleep@plt>
movaps 0xda2(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xd86(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movl   $0x7a7978,0x40(%rsp)
lea    0x20(%rsp),%rsi
mov    %ebp,%edi
mov    $0x24,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cb6(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xcda(%rip),%rsi
jmp    1399 <main+0x1a9>
lea    0xce3(%rip),%rdi
call   10b0 <perror@plt>
jmp    139e <main+0x1ae>
mov    0x2c93(%rip),%rax
mov    (%rax),%ebx
mov    0x2c7a(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xcce(%rip),%rsi
jmp    1394 <main+0x1a4>
mov    0x2c73(%rip),%rax
mov    (%rax),%ebx
mov    0x2c5a(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xcc1(%rip),%rsi
jmp    1394 <main+0x1a4>
mov    0x2c53(%rip),%rax
mov    (%rax),%ebx
mov    0x2c3a(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xcb6(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    0x2c13(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.msg = [15 x i8] c"hello, world!\0A\00"
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s <port>\0A\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [16 x i8] c"socket() failed\00"
@INADDR_ANY = global i32 0
@.str.2 = [19 x i8] c"bind() failed: %s\0A\00"
@errno = global i32 0
@.str.3 = [21 x i8] c"listen() failed: %s\0A\00"
@.str.4 = [21 x i8] c"accept() failed: %s\0A\00"
@__const.main.str = [36 x i8] c"abcdefg,hijklmn, opq, rst, uvw, xyz\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 %struct.sockaddr_in
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca i32
%12 = alloca [15 x i8]
%13 = alloca [36 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = bitcast [15 x i8]* %12 to i8*
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %25
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %2
%26 = load i32, i32* @AF_INET
%27 = load i32, i32* @SOCK_STREAM
%28 = call i32 @socket(i32 %26, i32 %27, i32 0)
store i32 %28, i32* %6
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %34
30: ; preds = %25
%31 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %25
%35 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 12)
%36 = load i32, i32* @AF_INET
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %36, i32* %37
%38 = load i32, i32* @INADDR_ANY
%39 = call i32 @htonl(i32 %38)
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%41 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %40, i32 0, i32 0
store i32 %39, i32* %41
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = call i32 @atoi(i8* %44)
%46 = call i32 @htons(i32 %45)
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %46, i32* %47
%48 = load i32, i32* %6
%49 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%50 = call i32 @bind(i32 %48, %struct.sockaddr* %49, i32 12)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %59
52: ; preds = %34
%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 ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %55)
%57 = load i32, i32* @EXIT_FAILURE
%58 = call i32 @exit(i32 %57)
unreachable
59: ; preds = %34
%60 = load i32, i32* %6
%61 = call i32 @listen(i32 %60, i32 5)
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %70
63: ; preds = %59
%64 = load i32, i32* @stderr
%65 = load i32, i32* @errno
%66 = call i8* @strerror(i32 %65)
%67 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %66)
%68 = load i32, i32* @EXIT_FAILURE
%69 = call i32 @exit(i32 %68)
unreachable
70: ; preds = %59
store i32 12, i32* %10
%71 = load i32, i32* %6
%72 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%73 = call i32 @accept(i32 %71, %struct.sockaddr* %72, i32* %10)
store i32 %73, i32* %7
%74 = load i32, i32* %7
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %83
76: ; preds = %70
%77 = load i32, i32* @stderr
%78 = load i32, i32* @errno
%79 = call i8* @strerror(i32 %78)
%80 = call i32 @fprintf(i32 %77, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %79)
%81 = load i32, i32* @EXIT_FAILURE
%82 = call i32 @exit(i32 %81)
unreachable
83: ; preds = %70
%84 = call i32 @usleep(i32 3500)
%85 = bitcast [36 x i8]* %13 to i8*
%86 = load i32, i32* %7
%87 = getelementptr inbounds [36 x i8], [36 x i8]* %13, i64 0, i64 0
%88 = call i32 @write(i32 %86, i8* %87, i32 36)
store i32 %88, i32* %11
%89 = load i32, i32* %7
%90 = call i32 @close(i32 %89)
%91 = load i32, i32* %6
%92 = call i32 @close(i32 %91)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s <port>\0A\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [16 x i8] c"socket() failed\00"
@INADDR_ANY = global i32 0
@.str.2 = [19 x i8] c"bind() failed: %s\0A\00"
@errno = global i32 0
@.str.3 = [21 x i8] c"listen() failed: %s\0A\00"
@.str.4 = [21 x i8] c"accept() failed: %s\0A\00"
@__const.main.str = [36 x i8] c"abcdefg,hijklmn, opq, rst, uvw, xyz\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [36 x i8]
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = icmp eq i32 %0, 2
br i1 %10, label %17, label %11
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %1
%14 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = load i32, i32* @AF_INET
%19 = load i32, i32* @SOCK_STREAM
%20 = tail call i32 @socket(i32 %18, i32 %19, i32 0)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = tail call i32 @exit(i32 %24)
unreachable
26: ; preds = %17
%27 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %28, i32* %29
%30 = load i32, i32* @INADDR_ANY
%31 = call i32 @htonl(i32 %30)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %31, i32* %32
%33 = getelementptr inbounds i8*, i8** %1, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @atoi(i8* %34)
%36 = call i32 @htons(i32 %35)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %36, i32* %37
%38 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%39 = call i32 @bind(i32 %20, %struct.sockaddr* %38, i32 12)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %48
41: ; preds = %26
%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 ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %44)
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %26
%49 = call i32 @listen(i32 %20, i32 5)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %58
51: ; preds = %48
%52 = load i32, i32* @stderr
%53 = load i32, i32* @errno
%54 = call i8* @strerror(i32 %53)
%55 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %54)
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %48
store i32 12, i32* %5
%59 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%60 = call i32 @accept(i32 %20, %struct.sockaddr* %59, i32* %5)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %69
62: ; preds = %58
%63 = load i32, i32* @stderr
%64 = load i32, i32* @errno
%65 = call i8* @strerror(i32 %64)
%66 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %65)
%67 = load i32, i32* @EXIT_FAILURE
%68 = call i32 @exit(i32 %67)
unreachable
69: ; preds = %58
%70 = call i32 @usleep(i32 3500)
%71 = getelementptr inbounds [36 x i8], [36 x i8]* %6, i64 0, i64 0
%72 = call i32 @write(i32 %60, i8* %71, i32 36)
%73 = call i32 @close(i32 %60)
%74 = call i32 @close(i32 %20)
ret i32 0
}