#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*/ timestr;
typedef scalar_t__ time_t;
struct sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
struct TYPE_2__ {
  int fd;
};
struct epoll_event {
  TYPE_1__ data;
  int /*<<< orphan*/ events;
};
typedef int /*<<< orphan*/ ssize_t;
typedef int socklen_t;
typedef int /*<<< orphan*/ clitaddr;

/* Variables and functions */
int /*<<< orphan*/ EPOLLIN;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int /*<<< orphan*/ EXIT_FAILURE;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ close(int);
char *ctime(scalar_t__ *);
int epoll_create1(int /*<<< orphan*/);
int epoll_ctl(int, int /*<<< orphan*/, int, struct epoll_event *);
int epoll_wait(int, struct epoll_event *, int, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int /*<<< orphan*/, int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
scalar_t__ time(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int dtserv_run(int listenfd) {
  int connfd;
  struct sockaddr_in clitaddr;
  socklen_t addrlen;
  char timestr[64];
  time_t tval, oldsec, cursec;
  ssize_t wlen;
  int count = 0;
  int ret;
  int epfd;
  struct epoll_event event;
  if ((epfd = epoll_create1(0)) == -1)
    error(EXIT_FAILURE, errno, "epoll_create1");
  event.events = EPOLLIN;
  event.data.fd = listenfd;
  if (epoll_ctl(epfd, EPOLL_CTL_ADD, listenfd, &event) == -1)
    error(EXIT_FAILURE, errno, "epoll_ctl");
  oldsec = time(0);
  for (;;) {
    ret = epoll_wait(epfd, &event, 1, 1000);
    if (ret == -1) {
      error(0, errno, "select");
      continue;
    } else if (ret == 0)
      continue;
    if (event.data.fd != listenfd)
      continue;
    addrlen = sizeof(clitaddr);
    connfd = accept(listenfd, (struct sockaddr *)&clitaddr, &addrlen);
    if (connfd == -1) {
      error(0, errno, "accept");
      continue;
    }
    tval = time(0);
    wlen = snprintf(timestr, sizeof(timestr), "%s", ctime(&tval));
    if (write(connfd, timestr, wlen) != wlen)
      error(0, errno, "write");
    close(connfd);
    count++;
    cursec = time(0);
    if (cursec > oldsec) {
      printf("last sec qps: %d\n", count);
      count = 0;
      oldsec = cursec;
    }
  }
}


x86 assembly (clang, -O0):
<dtserv_run>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x80(%rbp)
xor    %edi,%edi
call   10d0 <epoll_create1@plt>
mov    %eax,-0x88(%rbp)
cmp    $0xffffffff,%eax
jne    11f9 <dtserv_run+0x49>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
lea    0xe0c(%rip),%rdx
call   10b0 <error@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x90(%rbp)
mov    -0x88(%rbp),%edi
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
mov    -0x4(%rbp),%edx
lea    -0x90(%rbp),%rcx
call   1080 <epoll_ctl@plt>
cmp    $0xffffffff,%eax
jne    1256 <dtserv_run+0xa6>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
mov    0x2d88(%rip),%rax
mov    (%rax),%esi
lea    0xdbd(%rip),%rdx
call   10b0 <error@plt>
xor    %edi,%edi
call   1090 <time@plt>
mov    %rax,-0x70(%rbp)
mov    -0x88(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x1,%edx
mov    $0x3e8,%ecx
call   10a0 <epoll_wait@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0xffffffff,-0x84(%rbp)
jne    12ac <dtserv_run+0xfc>
mov    0x2d39(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    0xd76(%rip),%rdx
call   10b0 <error@plt>
jmp    1261 <dtserv_run+0xb1>
cmpl   $0x0,-0x84(%rbp)
jne    12be <dtserv_run+0x10e>
jmp    1261 <dtserv_run+0xb1>
jmp    12c3 <dtserv_run+0x113>
mov    -0x90(%rbp),%eax
cmp    -0x4(%rbp),%eax
je     12d7 <dtserv_run+0x127>
jmp    1261 <dtserv_run+0xb1>
movl   $0x4,-0x14(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   10c0 <accept@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1317 <dtserv_run+0x167>
mov    0x2cce(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    0xd12(%rip),%rdx
call   10b0 <error@plt>
jmp    1261 <dtserv_run+0xb1>
xor    %edi,%edi
call   1090 <time@plt>
mov    %rax,-0x68(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x68(%rbp),%rdi
call   1040 <ctime@plt>
mov    -0x98(%rbp),%rdi
mov    %rax,%rcx
mov    $0x40,%esi
lea    0xcda(%rip),%rdx
call   1060 <snprintf@plt>
mov    %eax,-0x7c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    -0x7c(%rbp),%edx
call   1030 <write@plt>
cmp    -0x7c(%rbp),%eax
je     1383 <dtserv_run+0x1d3>
mov    0x2c5d(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    0xcab(%rip),%rdx
call   10b0 <error@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
mov    -0x80(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80(%rbp)
xor    %edi,%edi
call   1090 <time@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
cmp    -0x70(%rbp),%rax
jle    13cb <dtserv_run+0x21b>
mov    -0x80(%rbp),%esi
lea    0xc78(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x80(%rbp)
mov    -0x78(%rbp),%rax
mov    %rax,-0x70(%rbp)
jmp    1261 <dtserv_run+0xb1>

x86 assembly (clang, -O2):
<dtserv_run>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %edi,%r14d
xor    %edi,%edi
call   10d0 <epoll_create1@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11ed <dtserv_run+0x3d>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
lea    0xe18(%rip),%rdx
call   10b0 <error@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    %r14d,0x8(%rsp)
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rcx
mov    %ebp,%edi
mov    %r14d,%edx
call   1080 <epoll_ctl@plt>
cmp    $0xffffffff,%eax
jne    123a <dtserv_run+0x8a>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
mov    0x2da4(%rip),%rax
mov    (%rax),%esi
lea    0xdd9(%rip),%rdx
call   10b0 <error@plt>
xor    %edi,%edi
call   1090 <time@plt>
mov    %rax,0x18(%rsp)
lea    0x8(%rsp),%rbx
lea    0xdc6(%rip),%r15
mov    0x2d77(%rip),%r13
nopl   0x0(%rax)
movl   $0x0,0x4(%rsp)
jmp    129b <dtserv_run+0xeb>
movl   $0x4,0x14(%rsp)
mov    %r14d,%edi
lea    0x28(%rsp),%rsi
lea    0x14(%rsp),%rdx
call   10c0 <accept@plt>
lea    0xd94(%rip),%rdx
cmp    $0xffffffff,%eax
jne    12c4 <dtserv_run+0x114>
mov    0x0(%r13),%esi
xor    %edi,%edi
call   10b0 <error@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
mov    $0x3e8,%ecx
call   10a0 <epoll_wait@plt>
test   %eax,%eax
je     129b <dtserv_run+0xeb>
mov    %r15,%rdx
cmp    $0xffffffff,%eax
je     1290 <dtserv_run+0xe0>
cmp    %r14d,0x8(%rsp)
jne    129b <dtserv_run+0xeb>
jmp    126a <dtserv_run+0xba>
mov    %eax,%r12d
xor    %edi,%edi
call   1090 <time@plt>
mov    %rax,0x20(%rsp)
lea    0x20(%rsp),%rdi
call   1040 <ctime@plt>
lea    0x30(%rsp),%rdi
mov    $0x40,%esi
lea    0xd38(%rip),%rdx
mov    %rax,%rcx
call   1060 <snprintf@plt>
mov    %eax,0x10(%rsp)
mov    %r12d,%edi
lea    0x30(%rsp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    0x10(%rsp),%eax
je     1321 <dtserv_run+0x171>
mov    0x0(%r13),%esi
xor    %edi,%edi
lea    0xd0d(%rip),%rdx
call   10b0 <error@plt>
mov    %r12d,%edi
call   1070 <close@plt>
addl   $0x1,0x4(%rsp)
xor    %edi,%edi
call   1090 <time@plt>
cmp    0x18(%rsp),%rax
jle    129b <dtserv_run+0xeb>
mov    %rax,%r12
lea    0xce5(%rip),%rdi
mov    0x4(%rsp),%esi
call   1050 <printf@plt>
mov    %r12,0x18(%rsp)
jmp    1260 <dtserv_run+0xb0>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.epoll_event = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@EXIT_FAILURE = global i32 0
@errno = global i32 0
@.str = [14 x i8] c"epoll_create1\00"
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.1 = [10 x i8] c"epoll_ctl\00"
@.str.2 = [7 x i8] c"select\00"
@.str.3 = [7 x i8] c"accept\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [6 x i8] c"write\00"
@.str.6 = [18 x i8] c"last sec qps: %d\0A\00"
define i32 @dtserv_run(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [64 x i8]
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.epoll_event
store i32 %0, i32* %2
store i32 0, i32* %11
%15 = call i32 @epoll_create1(i32 0)
store i32 %15, i32* %13
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %21
17: ; preds = %1
%18 = load i32, i32* @EXIT_FAILURE
%19 = load i32, i32* @errno
%20 = call i32 @error(i32 %18, i32 %19, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %17, %1
%22 = load i32, i32* @EPOLLIN
%23 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %14, i32 0, i32 1
store i32 %22, i32* %23
%24 = load i32, i32* %2
%25 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %14, i32 0, i32 0
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
store i32 %24, i32* %26
%27 = load i32, i32* %13
%28 = load i32, i32* @EPOLL_CTL_ADD
%29 = load i32, i32* %2
%30 = call i32 @epoll_ctl(i32 %27, i32 %28, i32 %29, %struct.epoll_event* %14)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %36
32: ; preds = %21
%33 = load i32, i32* @EXIT_FAILURE
%34 = load i32, i32* @errno
%35 = call i32 @error(i32 %33, i32 %34, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %36
36: ; preds = %32, %21
%37 = call i64 @time(i32 0)
store i64 %37, i64* %8
br label %38
38: ; preds = %94, %64, %57, %49, %43, %36
%39 = load i32, i32* %13
%40 = call i32 @epoll_wait(i32 %39, %struct.epoll_event* %14, i32 1, i32 1000)
store i32 %40, i32* %12
%41 = load i32, i32* %12
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %46
43: ; preds = %38
%44 = load i32, i32* @errno
%45 = call i32 @error(i32 0, i32 %44, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %38
46: ; preds = %38
%47 = load i32, i32* %12
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %46
br label %38
50: ; preds = %46
br label %51
51: ; preds = %50
%52 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %14, i32 0, i32 0
%53 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %52, i32 0, i32 0
%54 = load i32, i32* %53
%55 = load i32, i32* %2
%56 = icmp ne i32 %54, %55
br i1 %56, label %57, label %58
57: ; preds = %51
br label %38
58: ; preds = %51
store i32 4, i32* %5
%59 = load i32, i32* %2
%60 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%61 = call i32 @accept(i32 %59, %struct.sockaddr* %60, i32* %5)
store i32 %61, i32* %3
%62 = load i32, i32* %3
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %67
64: ; preds = %58
%65 = load i32, i32* @errno
%66 = call i32 @error(i32 0, i32 %65, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %38
67: ; preds = %58
%68 = call i64 @time(i32 0)
store i64 %68, i64* %7
%69 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%70 = call i8* @ctime(i64* %7)
%71 = call i32 @snprintf(i8* %69, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %70)
store i32 %71, i32* %10
%72 = load i32, i32* %3
%73 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%74 = load i32, i32* %10
%75 = call i32 @write(i32 %72, i8* %73, i32 %74)
%76 = load i32, i32* %10
%77 = icmp ne i32 %75, %76
br i1 %77, label %78, label %81
78: ; preds = %67
%79 = load i32, i32* @errno
%80 = call i32 @error(i32 0, i32 %79, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %81
81: ; preds = %78, %67
%82 = load i32, i32* %3
%83 = call i32 @close(i32 %82)
%84 = load i32, i32* %11
%85 = add nsw i32 %84, 1
store i32 %85, i32* %11
%86 = call i64 @time(i32 0)
store i64 %86, i64* %9
%87 = load i64, i64* %9
%88 = load i64, i64* %8
%89 = icmp sgt i64 %87, %88
br i1 %89, label %90, label %94
90: ; preds = %81
%91 = load i32, i32* %11
%92 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %91)
store i32 0, i32* %11
%93 = load i64, i64* %9
store i64 %93, i64* %8
br label %94
94: ; preds = %90, %81
br label %38
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.epoll_event = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@EXIT_FAILURE = global i32 0
@errno = global i32 0
@.str = [14 x i8] c"epoll_create1\00"
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.1 = [10 x i8] c"epoll_ctl\00"
@.str.2 = [7 x i8] c"select\00"
@.str.3 = [7 x i8] c"accept\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [6 x i8] c"write\00"
@.str.6 = [18 x i8] c"last sec qps: %d\0A\00"
define i32 @dtserv_run(i32 %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca [64 x i8]
%5 = alloca i64
%6 = alloca %struct.epoll_event
%7 = bitcast %struct.sockaddr_in* %2 to i8*
%8 = bitcast i32* %3 to i8*
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%10 = bitcast i64* %5 to i8*
%11 = bitcast %struct.epoll_event* %6 to i8*
%12 = tail call i32 @epoll_create1(i32 0)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %18
14: ; preds = %1
%15 = load i32, i32* @EXIT_FAILURE
%16 = load i32, i32* @errno
%17 = tail call i32 @error(i32 %15, i32 %16, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %14, %1
%19 = load i32, i32* @EPOLLIN
%20 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %6, i64 0, i32 1
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %6, i64 0, i32 0, i32 0
store i32 %0, i32* %21
%22 = load i32, i32* @EPOLL_CTL_ADD
%23 = call i32 @epoll_ctl(i32 %12, i32 %22, i32 %0, %struct.epoll_event* %6)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %29
25: ; preds = %18
%26 = load i32, i32* @EXIT_FAILURE
%27 = load i32, i32* @errno
%28 = call i32 @error(i32 %26, i32 %27, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %25, %18
%30 = call i64 @time(i32 0)
%31 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
br label %32
32: ; preds = %63, %29
%33 = phi i64 [ %61, %63 ], [ %30, %29 ]
br label %34
34: ; preds = %32, %58
%35 = phi i32 [ %60, %58 ], [ 0, %32 ]
br label %36
36: ; preds = %42, %34
%37 = call i32 @epoll_wait(i32 %12, %struct.epoll_event* %6, i32 1, i32 1000)
switch i32 %37, label %43 [
i32 -1, label %38
i32 0, label %42
]
38: ; preds = %36, %46
%39 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), %46 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %36 ]
%40 = load i32, i32* @errno
%41 = call i32 @error(i32 0, i32 %40, i8* %39)
br label %42
42: ; preds = %38, %43, %36
br label %36
43: ; preds = %36
%44 = load i32, i32* %21
%45 = icmp eq i32 %44, %0
br i1 %45, label %46, label %42
46: ; preds = %43
store i32 4, i32* %3
%47 = call i32 @accept(i32 %0, %struct.sockaddr* %31, i32* %3)
%48 = icmp eq i32 %47, -1
br i1 %48, label %38, label %49
49: ; preds = %46
%50 = call i64 @time(i32 0)
store i64 %50, i64* %5
%51 = call i8* @ctime(i64* %5)
%52 = call i32 @snprintf(i8* %9, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %51)
%53 = call i32 @write(i32 %47, i8* %9, i32 %52)
%54 = icmp eq i32 %53, %52
br i1 %54, label %58, label %55
55: ; preds = %49
%56 = load i32, i32* @errno
%57 = call i32 @error(i32 0, i32 %56, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %58
58: ; preds = %55, %49
%59 = call i32 @close(i32 %47)
%60 = add nuw nsw i32 %35, 1
%61 = call i64 @time(i32 0)
%62 = icmp sgt i64 %61, %33
br i1 %62, label %63, label %34
63: ; preds = %58
%64 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %60)
br label %32
}