#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 */
typedef int /*<<< orphan*/ time_t;
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*/ servaddr;
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
scalar_t__ listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
scalar_t__ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int listenfd;
  int connfd;
  struct sockaddr_in servaddr;
  struct sockaddr_in cliaddr;
  int lenstruct;
  char buff[4096];
  time_t ticks;
  listenfd = socket(AF_INET, SOCK_STREAM, 0);
  if (listenfd < 0) {
    perror("socket error");
    return 1;
  }
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(60000);
  servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  lenstruct = sizeof(servaddr);
  if ((bind(listenfd, (struct sockaddr *)&servaddr, lenstruct)) < 0) {
    perror("bind error");
    return 1;
  }
  if (listen(listenfd, 10) < 0) {
    perror("listen error");
    return 1;
  }
  for (;;) {
    connfd = accept(listenfd, (struct sockaddr *)&cliaddr, &lenstruct);
    if (connfd < 0) {
      perror("accept error");
      return 1;
    }
    fprintf(stderr, "Addr of connected client: %s\n",
            inet_ntoa(cliaddr.sin_addr));
    ticks = time(NULL);
    snprintf(buff, sizeof(buff), "%.24s\r\n", ctime(&ticks));
    if (write(connfd, buff, strlen(buff)) < 0) {
      fprintf(stderr, "write error\n");
      return 1;
    }
    close(connfd);
  }
  close(listenfd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1070,%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    1257 <main+0x57>
lea    0xdba(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1413 <main+0x213>
lea    -0x28(%rbp),%rdi
mov    $0xc,%esi
call   1100 <bzero@plt>
mov    0x2d7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    $0xea60,%edi
call   1070 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,-0x28(%rbp)
movl   $0xc,-0x3c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    -0x3c(%rbp),%edx
call   10e0 <bind@plt>
cmp    $0x0,%rax
jge    12c7 <main+0xc7>
lea    0xd57(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1413 <main+0x213>
mov    -0x14(%rbp),%edi
mov    $0xa,%esi
call   10d0 <listen@plt>
cmp    $0x0,%rax
jge    12f6 <main+0xf6>
lea    0xd33(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1413 <main+0x213>
jmp    12fb <main+0xfb>
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
call   1110 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1330 <main+0x130>
lea    0xd06(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1413 <main+0x213>
mov    0x2c99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1064(%rbp)
mov    -0x38(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    -0x1064(%rbp),%edi
mov    %rax,%rdx
lea    0xcdb(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %eax,-0x1044(%rbp)
lea    -0x1040(%rbp),%rax
mov    %rax,-0x1060(%rbp)
lea    -0x1044(%rbp),%rdi
call   1050 <ctime@plt>
mov    -0x1060(%rbp),%rdi
mov    %rax,%rcx
mov    $0x1000,%esi
lea    0xcb3(%rip),%rdx
call   1080 <snprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1054(%rbp)
lea    -0x1040(%rbp),%rax
mov    %rax,-0x1050(%rbp)
lea    -0x1040(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x1054(%rbp),%edi
mov    -0x1050(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    1406 <main+0x206>
mov    0x2be6(%rip),%rax
mov    (%rax),%edi
lea    0xc65(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1413 <main+0x213>
mov    -0x18(%rbp),%edi
call   10a0 <close@plt>
jmp    12fb <main+0xfb>
mov    -0x4(%rbp),%eax
add    $0x1070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1038,%rsp
mov    0x2dd0(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
test   %eax,%eax
js     138b <main+0x18b>
mov    %eax,%r13d
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   1100 <bzero@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    $0xea60,%edi
call   1070 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,0x10(%rsp)
movl   $0xc,0x8(%rsp)
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
test   %rax,%rax
js     1394 <main+0x194>
mov    %r13d,%edi
mov    $0xa,%esi
call   10d0 <listen@plt>
test   %rax,%rax
js     139d <main+0x19d>
lea    0x20(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %r13d,%edi
call   1110 <accept@plt>
test   %eax,%eax
js     1369 <main+0x169>
mov    %eax,%ebp
lea    0xd87(%rip),%r12
lea    0x30(%rsp),%rbx
lea    0x8(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x2ce9(%rip),%rax
mov    (%rax),%r14d
mov    0x20(%rsp),%edi
call   1040 <inet_ntoa@plt>
mov    %r14d,%edi
lea    0xd35(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
xor    %edi,%edi
call   10c0 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1050 <ctime@plt>
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r12,%rdx
mov    %rax,%rcx
call   1080 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %rax,%rax
js     1372 <main+0x172>
mov    %ebp,%edi
call   10a0 <close@plt>
mov    %r13d,%edi
lea    0x20(%rsp),%rsi
mov    %r15,%rdx
call   1110 <accept@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    12e0 <main+0xe0>
lea    0xcb5(%rip),%rdi
jmp    13a4 <main+0x1a4>
mov    0x2c57(%rip),%rax
mov    (%rax),%edi
lea    0xcd6(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    13a9 <main+0x1a9>
lea    0xc6e(%rip),%rdi
jmp    13a4 <main+0x1a4>
lea    0xc72(%rip),%rdi
jmp    13a4 <main+0x1a4>
lea    0xc74(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%eax
add    $0x1038,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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 = [13 x i8] c"socket error\00"
@INADDR_ANY = global i32 0
@.str.1 = [11 x i8] c"bind error\00"
@.str.2 = [13 x i8] c"listen error\00"
@.str.3 = [13 x i8] c"accept error\00"
@stderr = global i32 0
@.str.4 = [30 x i8] c"Addr of connected client: %s\0A\00"
@.str.5 = [8 x i8] c"%.24s\0D\0A\00"
@.str.6 = [13 x i8] c"write error\0A\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 [4096 x i8]
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %75
20: ; preds = %2
%21 = call i32 @bzero(%struct.sockaddr_in* %8, i32 12)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %22, i32* %23
%24 = call i32 @htons(i32 60000)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %24, i32* %25
%26 = load i32, i32* @INADDR_ANY
%27 = call i32 @htonl(i32 %26)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %28, i32 0, i32 0
store i32 %27, i32* %29
store i32 12, i32* %10
%30 = load i32, i32* %6
%31 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%32 = load i32, i32* %10
%33 = call i64 @bind(i32 %30, %struct.sockaddr* %31, i32 %32)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %20
%36 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %75
37: ; preds = %20
%38 = load i32, i32* %6
%39 = call i64 @listen(i32 %38, i32 10)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %75
43: ; preds = %37
br label %44
44: ; preds = %72, %43
%45 = load i32, i32* %6
%46 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%47 = call i32 @accept(i32 %45, %struct.sockaddr* %46, i32* %10)
store i32 %47, i32* %7
%48 = load i32, i32* %7
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %44
%51 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %75
52: ; preds = %44
%53 = load i32, i32* @stderr
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%55 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %54, i32 0, i32 0
%56 = load i32, i32* %55
%57 = call i8* @inet_ntoa(i32 %56)
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %57)
%59 = call i32 @time(i32* null)
store i32 %59, i32* %12
%60 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%61 = call i8* @ctime(i32* %12)
%62 = call i32 @snprintf(i8* %60, i32 4096, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %61)
%63 = load i32, i32* %7
%64 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%65 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%66 = call i32 @strlen(i8* %65)
%67 = call i64 @write(i32 %63, i8* %64, i32 %66)
%68 = icmp slt i64 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %52
%70 = load i32, i32* @stderr
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %75
72: ; preds = %52
%73 = load i32, i32* %7
%74 = call i32 @close(i32 %73)
br label %44
75: ; preds = %69, %50, %41, %35, %18
%76 = load i32, i32* %3
ret i32 %76
}

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 = [13 x i8] c"socket error\00"
@INADDR_ANY = global i32 0
@.str.1 = [11 x i8] c"bind error\00"
@.str.2 = [13 x i8] c"listen error\00"
@.str.3 = [13 x i8] c"accept error\00"
@stderr = global i32 0
@.str.4 = [30 x i8] c"Addr of connected client: %s\0A\00"
@.str.5 = [8 x i8] c"%.24s\0D\0A\00"
@.str.6 = [13 x i8] c"write error\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [4096 x i8]
%7 = alloca i32
%8 = bitcast %struct.sockaddr_in* %3 to i8*
%9 = bitcast %struct.sockaddr_in* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%12 = bitcast i32* %7 to i8*
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = tail call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %65
19: ; preds = %2
%20 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %21, i32* %22
%23 = tail call i32 @htons(i32 60000)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %23, i32* %24
%25 = load i32, i32* @INADDR_ANY
%26 = tail call i32 @htonl(i32 %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %26, i32* %27
store i32 12, i32* %5
%28 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%29 = call i64 @bind(i32 %15, %struct.sockaddr* %28, i32 12)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %19
%32 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %65
33: ; preds = %19
%34 = call i64 @listen(i32 %15, i32 10)
%35 = icmp slt i64 %34, 0
br i1 %35, label %42, label %36
36: ; preds = %33
%37 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%38 = call i32 @accept(i32 %15, %struct.sockaddr* %37, i32* %5)
%39 = icmp slt i32 %38, 0
br i1 %39, label %44, label %40
40: ; preds = %36
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
br label %46
42: ; preds = %33
%43 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %65
44: ; preds = %61, %36
%45 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %65
46: ; preds = %40, %61
%47 = phi i32 [ %38, %40 ], [ %63, %61 ]
%48 = load i32, i32* @stderr
%49 = load i32, i32* %41
%50 = call i8* @inet_ntoa(i32 %49)
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %50)
%52 = call i32 @time(i32* null)
store i32 %52, i32* %7
%53 = call i8* @ctime(i32* %7)
%54 = call i32 @snprintf(i8* %11, i32 4096, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %53)
%55 = call i32 @strlen(i8* %11)
%56 = call i64 @write(i32 %47, i8* %11, i32 %55)
%57 = icmp slt i64 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %46
%59 = load i32, i32* @stderr
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
br label %65
61: ; preds = %46
%62 = call i32 @close(i32 %47)
%63 = call i32 @accept(i32 %15, %struct.sockaddr* %37, i32* %5)
%64 = icmp slt i32 %63, 0
br i1 %64, label %44, label %46
65: ; preds = %58, %44, %42, %31, %17
ret i32 1
}