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

/* 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 const *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
scalar_t__ close(int);
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
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 sockFD;
  if ((sockFD = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    fprintf(stderr, "socket() error\n");
    exit(1);
  }
  struct sockaddr_in servAddr;
  bzero(&servAddr, sizeof(servAddr));
  servAddr.sin_family = AF_INET;
  servAddr.sin_port = htons(57345);
  servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
  if (bind(sockFD, (const struct sockaddr *)&servAddr, sizeof(servAddr)) < 0) {
    fprintf(stderr, "bind() error\n");
    exit(1);
  }
  if (listen(sockFD, 16) < 0) {
    fprintf(stderr, "listen() error\n");
    exit(1);
  }
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
  while (1) {
    int connFD;
    if ((connFD = accept(sockFD, (struct sockaddr *)NULL, NULL)) < 0) {
      fprintf(stderr, "accept() error\n");
      exit(1);
    }
    time_t timer;
    char sendLine[256];
    time(&timer);
    snprintf(sendLine, sizeof(sendLine), "%s\n", ctime(&timer));
    if (write(connFD, sendLine, strlen(sendLine)) < 0) {
      fprintf(stderr, "write() error\n");
      exit(1);
    }
    if (close(connFD) < 0) {
      fprintf(stderr, "close() error\n");
      exit(1);
    }
  }
#pragma clang diagnostic pop
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    124d <main+0x5d>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
lea    0xdc2(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0xe001,%edi
call   1060 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
cmp    $0x0,%rax
jge    12bf <main+0xcf>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
lea    0xd60(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x10,%esi
call   10c0 <listen@plt>
cmp    $0x0,%rax
jge    12f5 <main+0x105>
mov    0x2cf3(%rip),%rax
mov    (%rax),%edi
lea    0xd38(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
jmp    12fa <main+0x10a>
mov    -0x14(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   10f0 <accept@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    1334 <main+0x144>
mov    0x2cb4(%rip),%rax
mov    (%rax),%edi
lea    0xd09(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    -0x28(%rbp),%rdi
call   10b0 <time@plt>
lea    -0x130(%rbp),%rax
mov    %rax,-0x148(%rbp)
lea    -0x28(%rbp),%rdi
call   1040 <ctime@plt>
mov    -0x148(%rbp),%rdi
mov    %rax,%rcx
mov    $0x100,%esi
lea    0xcd4(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x13c(%rbp)
lea    -0x130(%rbp),%rax
mov    %rax,-0x138(%rbp)
lea    -0x130(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x13c(%rbp),%edi
mov    -0x138(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    13cf <main+0x1df>
mov    0x2c19(%rip),%rax
mov    (%rax),%edi
lea    0xc82(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
cmp    $0x0,%rax
jge    1400 <main+0x210>
mov    0x2be8(%rip),%rax
mov    (%rax),%edi
lea    0xc60(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
jmp    12fa <main+0x10a>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x110,%rsp
mov    0x2de2(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2db8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
test   %eax,%eax
jns    1232 <main+0x42>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    0xdd3(%rip),%rsi
jmp    136e <main+0x17e>
mov    %eax,%r15d
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x8(%rsp)
mov    $0xe001,%edi
call   1060 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,(%rsp)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
test   %rax,%rax
jns    1295 <main+0xa5>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
lea    0xd80(%rip),%rsi
jmp    136e <main+0x17e>
mov    %r15d,%edi
mov    $0x10,%esi
call   10c0 <listen@plt>
test   %rax,%rax
jns    12bc <main+0xcc>
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
lea    0xd67(%rip),%rsi
jmp    136e <main+0x17e>
mov    %r15d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10f0 <accept@plt>
test   %eax,%eax
js     133a <main+0x14a>
mov    %eax,%ebx
lea    0xc(%rsp),%r12
lea    0xd64(%rip),%r14
lea    0x10(%rsp),%rbp
nop
mov    %r12,%rdi
call   10b0 <time@plt>
mov    %r12,%rdi
call   1040 <ctime@plt>
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
mov    %rax,%rcx
call   1070 <snprintf@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %rax,%rax
js     134c <main+0x15c>
mov    %ebx,%edi
call   1090 <close@plt>
test   %rax,%rax
js     135e <main+0x16e>
mov    %r15d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10f0 <accept@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    12e0 <main+0xf0>
mov    0x2c8f(%rip),%rax
mov    (%rax),%edi
lea    0xce4(%rip),%rsi
jmp    136e <main+0x17e>
mov    0x2c7d(%rip),%rax
mov    (%rax),%edi
lea    0xce6(%rip),%rsi
jmp    136e <main+0x17e>
mov    0x2c6b(%rip),%rax
mov    (%rax),%edi
lea    0xce3(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

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

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