#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 /*<<< orphan*/ *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
scalar_t__ write(int, char *, int);
int main(int argc, char **argv) {
  int listenfd, connfd;
  int i, len;
  char buff[100];
  time_t ticks;
  struct sockaddr_in servaddr;
  if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    printf("socket error\n");
    return -1;
  }
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(9999);
  servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  if ((bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr))) < 0) {
    printf("bind error\n");
    return -1;
  }
  if (listen(listenfd, 100) < 0) {
    printf("listen error\n");
    return -1;
  }
  for (;;) {
    if ((connfd = accept(listenfd, (struct sockaddr *)NULL, NULL)) < 0) {
      printf("accept error\n");
      return -1;
    }
    ticks = time(NULL);
    snprintf(buff, sizeof(buff), "%.24s\r\n", ctime(&ticks));
    len = strlen(buff);
    for (i = 0; i <= len; i++) {
      if (write(connfd, &buff[i], 1) < 0) {
        printf("write error\n");
        return -1;
      }
    }
    close(connfd);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1236 <main+0x56>
lea    0xddb(%rip),%rdi
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13da <main+0x1fa>
lea    -0xa0(%rbp),%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    0x2d9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x98(%rbp)
mov    $0x270f,%edi
call   1060 <htons@plt>
mov    %eax,-0x9c(%rbp)
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,-0xa0(%rbp)
mov    -0x14(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
cmp    $0x0,%rax
jge    12b0 <main+0xd0>
lea    0xd6f(%rip),%rdi
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13da <main+0x1fa>
mov    -0x14(%rbp),%edi
mov    $0x64,%esi
call   10c0 <listen@plt>
cmp    $0x0,%rax
jge    12df <main+0xff>
lea    0xd4c(%rip),%rdi
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13da <main+0x1fa>
jmp    12e4 <main+0x104>
mov    -0x14(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   10f0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1317 <main+0x137>
lea    0xd22(%rip),%rdi
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13da <main+0x1fa>
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <time@plt>
mov    %eax,-0x94(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0xa8(%rbp)
lea    -0x94(%rbp),%rdi
call   1040 <ctime@plt>
mov    -0xa8(%rbp),%rdi
mov    %rax,%rcx
mov    $0x64,%esi
lea    0xce0(%rip),%rdx
call   1080 <snprintf@plt>
lea    -0x90(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jg     13cd <main+0x1ed>
mov    -0x18(%rbp),%edi
movslq -0x1c(%rbp),%rax
lea    -0x90(%rbp),%rsi
add    %rax,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    13ba <main+0x1da>
lea    0xc95(%rip),%rdi
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13da <main+0x1fa>
jmp    13bf <main+0x1df>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1371 <main+0x191>
mov    -0x18(%rbp),%edi
call   10a0 <close@plt>
jmp    12e4 <main+0x104>
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    0x2df0(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
test   %eax,%eax
js     12a2 <main+0xc2>
mov    %eax,%r13d
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    $0x270f,%edi
call   1070 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,0x10(%rsp)
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
test   %rax,%rax
js     1330 <main+0x150>
mov    %r13d,%edi
mov    $0x64,%esi
call   10c0 <listen@plt>
test   %rax,%rax
js     1339 <main+0x159>
mov    %r13d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10f0 <accept@plt>
test   %eax,%eax
js     134b <main+0x16b>
mov    %eax,%ebp
lea    0xd65(%rip),%r15
lea    0x20(%rsp),%r14
jmp    12cd <main+0xed>
lea    0xd90(%rip),%rdi
jmp    1352 <main+0x172>
xchg   %ax,%ax
mov    %ebp,%edi
call   10a0 <close@plt>
mov    %r13d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10f0 <accept@plt>
mov    %eax,%ebp
test   %eax,%eax
js     134b <main+0x16b>
xor    %edi,%edi
call   10b0 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1050 <ctime@plt>
mov    %r14,%rdi
mov    $0x64,%esi
mov    %r15,%rdx
mov    %rax,%rcx
call   1080 <snprintf@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
js     12b0 <main+0xd0>
mov    %eax,%ebx
add    $0x1,%ebx
mov    %r14,%r12
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
test   %rax,%rax
js     1342 <main+0x162>
add    $0x1,%r12
add    $0xffffffffffffffff,%rbx
jne    1310 <main+0x130>
jmp    12b0 <main+0xd0>
lea    0xcf7(%rip),%rdi
jmp    1352 <main+0x172>
lea    0xce1(%rip),%rdi
jmp    1352 <main+0x172>
lea    0xcbf(%rip),%rdi
jmp    1352 <main+0x172>
lea    0xcc2(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x88,%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 = [14 x i8] c"socket error\0A\00"
@INADDR_ANY = global i32 0
@.str.1 = [12 x i8] c"bind error\0A\00"
@.str.2 = [14 x i8] c"listen error\0A\00"
@.str.3 = [14 x i8] c"accept error\0A\00"
@.str.4 = [8 x i8] c"%.24s\0D\0A\00"
@.str.5 = [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 i32
%9 = alloca i32
%10 = alloca [100 x i8]
%11 = alloca i32
%12 = alloca %struct.sockaddr_in
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 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %75
19: ; preds = %2
%20 = call i32 @bzero(%struct.sockaddr_in* %12, i32 12)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i32 %21, i32* %22
%23 = call i32 @htons(i32 9999)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
store i32 %23, i32* %24
%25 = load i32, i32* @INADDR_ANY
%26 = call i32 @htonl(i32 %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
%28 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %27, i32 0, i32 0
store i32 %26, i32* %28
%29 = load i32, i32* %6
%30 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%31 = call i64 @bind(i32 %29, %struct.sockaddr* %30, i32 12)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %19
%34 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %75
35: ; preds = %19
%36 = load i32, i32* %6
%37 = call i64 @listen(i32 %36, i32 100)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %75
41: ; preds = %35
br label %42
42: ; preds = %72, %41
%43 = load i32, i32* %6
%44 = call i32 @accept(i32 %43, %struct.sockaddr* null, i32* null)
store i32 %44, i32* %7
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %75
48: ; preds = %42
%49 = call i32 @time(i32* null)
store i32 %49, i32* %11
%50 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%51 = call i8* @ctime(i32* %11)
%52 = call i32 @snprintf(i8* %50, i32 100, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %51)
%53 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%54 = call i32 @strlen(i8* %53)
store i32 %54, i32* %9
store i32 0, i32* %8
br label %55
55: ; preds = %69, %48
%56 = load i32, i32* %8
%57 = load i32, i32* %9
%58 = icmp sle i32 %56, %57
br i1 %58, label %59, label %72
59: ; preds = %55
%60 = load i32, i32* %7
%61 = load i32, i32* %8
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 %62
%64 = call i64 @write(i32 %60, i8* %63, i32 1)
%65 = icmp slt i64 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %59
%67 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %75
68: ; preds = %59
br label %69
69: ; preds = %68
%70 = load i32, i32* %8
%71 = add nsw i32 %70, 1
store i32 %71, i32* %8
br label %55
72: ; preds = %55
%73 = load i32, i32* %7
%74 = call i32 @close(i32 %73)
br label %42
75: ; preds = %66, %46, %39, %33, %17
%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
@INADDR_ANY = global i32 0
@.str.4 = [8 x i8] c"%.24s\0D\0A\00"
@str = [12 x i8] c"write error\00"
@str.6 = [13 x i8] c"accept error\00"
@str.7 = [13 x i8] c"listen error\00"
@str.8 = [11 x i8] c"bind error\00"
@str.9 = [13 x i8] c"socket error\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [100 x i8]
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = bitcast i32* %4 to i8*
%8 = bitcast %struct.sockaddr_in* %5 to i8*
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.9, i64 0, i64 0))
br label %63
15: ; preds = %2
%16 = call i32 @bzero(%struct.sockaddr_in* %5, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %17, i32* %18
%19 = tail call i32 @htons(i32 9999)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i32 %19, i32* %20
%21 = load i32, i32* @INADDR_ANY
%22 = tail call i32 @htonl(i32 %21)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
store i32 %22, i32* %23
%24 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%25 = call i64 @bind(i32 %11, %struct.sockaddr* %24, i32 12)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %15
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.8, i64 0, i64 0))
br label %63
29: ; preds = %15
%30 = call i64 @listen(i32 %11, i32 100)
%31 = icmp slt i64 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = call i32 @accept(i32 %11, %struct.sockaddr* null, i32* null)
%34 = icmp slt i32 %33, 0
br i1 %34, label %37, label %39
35: ; preds = %29
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.7, i64 0, i64 0))
br label %63
37: ; preds = %59, %32
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.6, i64 0, i64 0))
br label %63
39: ; preds = %32, %59
%40 = phi i32 [ %61, %59 ], [ %33, %32 ]
%41 = call i32 @time(i32* null)
store i32 %41, i32* %4
%42 = call i8* @ctime(i32* %4)
%43 = call i32 @snprintf(i8* %6, i32 100, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %42)
%44 = call i32 @strlen(i8* %6)
%45 = icmp slt i32 %44, 0
br i1 %45, label %59, label %46
46: ; preds = %39
%47 = add nuw i32 %44, 1
%48 = zext i32 %47 to i64
br label %52
49: ; preds = %52
%50 = add nuw nsw i64 %53, 1
%51 = icmp eq i64 %50, %48
br i1 %51, label %59, label %52
52: ; preds = %46, %49
%53 = phi i64 [ 0, %46 ], [ %50, %49 ]
%54 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %53
%55 = call i64 @write(i32 %40, i8* %54, i32 1)
%56 = icmp slt i64 %55, 0
br i1 %56, label %57, label %49
57: ; preds = %52
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %63
59: ; preds = %49, %39
%60 = call i32 @close(i32 %40)
%61 = call i32 @accept(i32 %11, %struct.sockaddr* null, i32* null)
%62 = icmp slt i32 %61, 0
br i1 %62, label %37, label %39
63: ; preds = %57, %37, %35, %27, %13
ret i32 -1
}