#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*/ sa;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int sprintf(char *, char *, char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
scalar_t__ write(int, char *, int);
int main(void) {
  int s, c, n;
  struct sockaddr_in sa;
  char buf[32];
  time_t t;
  if ((s = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
    perror("socket");
    exit(1);
  }
  sa.sin_family = AF_INET;
  sa.sin_port = htons(50000);
  sa.sin_addr.s_addr = htonl(INADDR_ANY);
  if (bind(s, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
    perror("bind");
    exit(1);
  }
  if (listen(s, 5) < 0) {
    perror("listen");
    exit(1);
  }
  do {
    if ((c = accept(s, NULL, 0)) < 0) {
      perror("accept");
      exit(1);
    }
    t = time(NULL);
    n = sprintf(buf, "%s", ctime(&t));
    if (write(c, buf, n) < 0) {
      perror("write");
      exit(1);
    }
    close(c);
  } while (1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    121a <main+0x4a>
lea    0xdf5(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0xc350,%edi
call   1050 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
cmp    $0x0,%rax
jge    1275 <main+0xa5>
lea    0xda1(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   1090 <listen@plt>
cmp    $0x0,%rax
jge    12a2 <main+0xd2>
lea    0xd79(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    12a7 <main+0xd7>
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10c0 <accept@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    12d7 <main+0x107>
lea    0xd4b(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,-0x44(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    -0x44(%rbp),%rdi
call   1040 <ctime@plt>
mov    -0x50(%rbp),%rdi
mov    %rax,%rdx
lea    0xd18(%rip),%rsi
call   10d0 <sprintf@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    1339 <main+0x169>
lea    0xcf3(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
mov    $0x1,%al
test   $0x1,%al
jne    12a7 <main+0xd7>
jmp    1350 <main+0x180>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
test   %eax,%eax
jns    1203 <main+0x33>
lea    0xe02(%rip),%rdi
jmp    12ea <main+0x11a>
mov    %eax,%r15d
mov    0x2ddb(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    $0xc350,%edi
call   1060 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %r15d,%edi
mov    $0xc,%edx
call   10b0 <bind@plt>
test   %rax,%rax
jns    1256 <main+0x86>
lea    0xdb6(%rip),%rdi
jmp    12ea <main+0x11a>
mov    %r15d,%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
test   %rax,%rax
jns    1271 <main+0xa1>
lea    0xd9d(%rip),%rdi
jmp    12ea <main+0x11a>
mov    %r15d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <accept@plt>
test   %eax,%eax
js     12da <main+0x10a>
mov    %eax,%ebp
lea    0xc(%rsp),%r14
lea    0x20(%rsp),%rbx
nopl   (%rax)
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,0xc(%rsp)
mov    %r14,%rdi
call   1040 <ctime@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <stpcpy@plt>
sub    %ebx,%eax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %rax,%rax
js     12e3 <main+0x113>
mov    %ebp,%edi
call   1080 <close@plt>
mov    %r15d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <accept@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1290 <main+0xc0>
lea    0xd32(%rip),%rdi
jmp    12ea <main+0x11a>
lea    0xd30(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

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

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [7 x i8] c"listen\00"
@.str.3 = [7 x i8] c"accept\00"
@.str.5 = [6 x i8] c"write\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [32 x i8]
%3 = alloca i32
%4 = bitcast %struct.sockaddr_in* %1 to i8*
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%6 = bitcast i32* %3 to i8*
%7 = load i32, i32* @PF_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 %14
11: ; preds = %0
%12 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %15, i32* %16
%17 = tail call i32 @htons(i32 50000)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %17, i32* %18
%19 = load i32, i32* @INADDR_ANY
%20 = tail call i32 @htonl(i32 %19)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %20, i32* %21
%22 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%23 = call i64 @bind(i32 %9, %struct.sockaddr* %22, i32 12)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %14
%26 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %14
%29 = call i64 @listen(i32 %9, i32 5)
%30 = icmp slt i64 %29, 0
br i1 %30, label %36, label %31
31: ; preds = %28
%32 = call i32 @accept(i32 %9, i32* null, i32 0)
%33 = icmp slt i32 %32, 0
br i1 %33, label %39, label %34
34: ; preds = %31
%35 = ptrtoint [32 x i8]* %2 to i64
br label %42
36: ; preds = %28
%37 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %55, %31
%40 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %34, %55
%43 = phi i32 [ %32, %34 ], [ %57, %55 ]
%44 = call i32 @time(i32* null)
store i32 %44, i32* %3
%45 = call i8* @ctime(i32* %3)
%46 = call i8* @stpcpy(i8* %5, i8* %45)
%47 = ptrtoint i8* %46 to i64
%48 = sub i64 %47, %35
%49 = trunc i64 %48 to i32
%50 = call i64 @write(i32 %43, i8* %5, i32 %49)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %42
%53 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %42
%56 = call i32 @close(i32 %43)
%57 = call i32 @accept(i32 %9, i32* null, i32 0)
%58 = icmp slt i32 %57, 0
br i1 %58, label %39, label %42
}