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

/* Type definitions */
typedef int /*<<< orphan*/ time_t;
struct sockaddr_in {
  int /*<<< orphan*/ sin_family;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ saddr;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ bcopy(void *, void *, int /*<<< orphan*/);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(void *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ gethostname(char *, int);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  struct sockaddr_in saddr;
  struct hostent *hp;
  char hostname[256];
  int sock_id, sock_fd;
  FILE *sock_fp;
  char *ctime();
  time_t thetime;
  sock_id = socket(PF_INET, SOCK_STREAM, 0);
  if (sock_id == -1) {
    perror("scoket");
    exit(1);
  };
  bzero((void *)&saddr, sizeof(saddr));
  gethostname(hostname, 256);
  hp = gethostbyname(hostname);
  bcopy((void *)hp->h_addr, (void *)&saddr.sin_addr, hp->h_length);
  saddr.sin_port = htons(13000);
  saddr.sin_family = AF_INET;
  if (bind(sock_id, (struct sockaddr *)&saddr, sizeof(saddr)) != 0) {
    perror("bind");
    exit(1);
  };
  if (listen(sock_id, 1) != 0) {
    perror("listen");
    exit(1);
  };
  while (1) {
    sock_fd = accept(sock_id, NULL, NULL);
    printf("Wow! got a call\n");
    if (sock_fd == -1) {
      perror("accept");
      exit(1);
    };
    sock_fp = fdopen(sock_fd, "w");
    if (sock_fp == NULL) {
      perror("fdopen");
      exit(1);
    };
    thetime = time(NULL);
    fprintf(sock_fp, "The time here is...");
    fprintf(sock_fp, "%s", ctime(&thetime));
    fclose(sock_fp);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0xffffffff,-0x124(%rbp)
jne    1264 <main+0x54>
lea    0xdab(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    -0x10(%rbp),%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
call   1110 <gethostname@plt>
lea    -0x120(%rbp),%rdi
call   1070 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x10(%rbp),%rsi
add    $0x8,%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
call   10c0 <bcopy@plt>
mov    $0x32c8,%edi
call   1050 <htons@plt>
mov    %eax,-0xc(%rbp)
mov    0x2d26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x124(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
cmp    $0x0,%rax
je     12fb <main+0xeb>
lea    0xd1b(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x124(%rbp),%edi
mov    $0x1,%esi
call   10a0 <listen@plt>
cmp    $0x0,%rax
je     132b <main+0x11b>
lea    0xcf0(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
jmp    1330 <main+0x120>
mov    -0x124(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1100 <accept@plt>
mov    %eax,-0x128(%rbp)
lea    0xcc4(%rip),%rdi
call   1060 <printf@plt>
cmpl   $0xffffffff,-0x128(%rbp)
jne    1377 <main+0x167>
lea    0xcbc(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x128(%rbp),%edi
lea    0xca7(%rip),%rsi
call   10b0 <fdopen@plt>
mov    %rax,-0x130(%rbp)
cmpq   $0x0,-0x130(%rbp)
jne    13b4 <main+0x1a4>
lea    0xc88(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,-0x134(%rbp)
mov    -0x130(%rbp),%rdi
lea    0xc63(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x130(%rbp),%rax
mov    %rax,-0x140(%rbp)
lea    -0x134(%rbp),%rdi
mov    $0x0,%al
call   1040 <ctime@plt>
mov    -0x140(%rbp),%rdi
mov    %rax,%rdx
lea    0xc43(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x130(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1330 <main+0x120>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
mov    0x2d97(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
cmp    $0xffffffff,%eax
jne    125b <main+0x3b>
lea    0xdaa(%rip),%rdi
jmp    13bc <main+0x19c>
mov    %eax,%r12d
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x100,%esi
call   1110 <gethostname@plt>
mov    %rbp,%rdi
call   1080 <gethostbyname@plt>
mov    0x8(%rax),%rsi
lea    0x18(%rsp),%rdi
mov    (%rax),%edx
call   10d0 <memmove@plt>
mov    $0x32c8,%edi
call   1060 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2d39(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
test   %rax,%rax
jne    13a3 <main+0x183>
mov    %r12d,%edi
mov    $0x1,%esi
call   10a0 <listen@plt>
test   %rax,%rax
jne    13ac <main+0x18c>
mov    %r12d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1100 <accept@plt>
mov    %eax,%ebx
lea    0xd3e(%rip),%rdi
call   1030 <puts@plt>
cmp    $0xffffffff,%ebx
je     139a <main+0x17a>
lea    0xd0c(%rip),%r14
lea    0xd0e(%rip),%r15
lea    0xc(%rsp),%r13
lea    0xd16(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
call   10b0 <fdopen@plt>
test   %rax,%rax
je     13b5 <main+0x195>
mov    %rax,%rbx
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,0xc(%rsp)
mov    $0x13,%esi
mov    $0x1,%edx
mov    %r15,%rdi
mov    %rbx,%rcx
call   1130 <fwrite@plt>
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <ctime@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1070 <fputs@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r12d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1100 <accept@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1030 <puts@plt>
cmp    $0xffffffff,%ebx
jne    1330 <main+0x110>
lea    0xc72(%rip),%rdi
jmp    13bc <main+0x19c>
lea    0xc5d(%rip),%rdi
jmp    13bc <main+0x19c>
lea    0xc59(%rip),%rdi
jmp    13bc <main+0x19c>
lea    0xc60(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"scoket\00"
@AF_INET = global i32 0
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [7 x i8] c"listen\00"
@.str.3 = [17 x i8] c"Wow! got a call\0A\00"
@.str.4 = [7 x i8] c"accept\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [7 x i8] c"fdopen\00"
@.str.7 = [20 x i8] c"The time here is...\00"
@.str.8 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca %struct.hostent*
%4 = alloca [256 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i32 0, i32* %1
%9 = load i32, i32* @PF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = bitcast %struct.sockaddr_in* %2 to i8*
%19 = call i32 @bzero(i8* %18, i32 12)
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%21 = call i32 @gethostname(i8* %20, i32 256)
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%23 = call %struct.hostent* @gethostbyname(i8* %22)
store %struct.hostent* %23, %struct.hostent** %3
%24 = load %struct.hostent*, %struct.hostent** %3
%25 = getelementptr inbounds %struct.hostent, %struct.hostent* %24, i32 0, i32 1
%26 = load i64, i64* %25
%27 = inttoptr i64 %26 to i8*
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
%29 = bitcast i32* %28 to i8*
%30 = load %struct.hostent*, %struct.hostent** %3
%31 = getelementptr inbounds %struct.hostent, %struct.hostent* %30, i32 0, i32 0
%32 = load i32, i32* %31
%33 = call i32 @bcopy(i8* %27, i8* %29, i32 %32)
%34 = call i32 @htons(i32 13000)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
store i32 %34, i32* %35
%36 = load i32, i32* @AF_INET
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
store i32 %36, i32* %37
%38 = load i32, i32* %5
%39 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%40 = call i64 @bind(i32 %38, %struct.sockaddr* %39, i32 12)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %17
%43 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %17
%46 = load i32, i32* %5
%47 = call i64 @listen(i32 %46, i32 1)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %45
%50 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %45
br label %53
53: ; preds = %52, %70
%54 = load i32, i32* %5
%55 = call i32 @accept(i32 %54, i32* null, i32* null)
store i32 %55, i32* %6
%56 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%57 = load i32, i32* %6
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %62
59: ; preds = %53
%60 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %53
%63 = load i32, i32* %6
%64 = call i32* @fdopen(i32 %63, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %64, i32** %7
%65 = load i32*, i32** %7
%66 = icmp eq i32* %65, null
br i1 %66, label %67, label %70
67: ; preds = %62
%68 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%69 = call i32 @exit(i32 1)
unreachable
70: ; preds = %62
%71 = call i32 @time(i32* null)
store i32 %71, i32* %8
%72 = load i32*, i32** %7
%73 = call i32 (i32*, i8*, ...) @fprintf(i32* %72, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%74 = load i32*, i32** %7
%75 = call i8* (i32*, ...) bitcast (i8* (...)* @ctime to i8* (i32*, ...)*)(i32* %8)
%76 = call i32 (i32*, i8*, ...) @fprintf(i32* %74, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %75)
%77 = load i32*, i32** %7
%78 = call i32 @fclose(i32* %77)
br label %53
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"scoket\00"
@AF_INET = global i32 0
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [7 x i8] c"listen\00"
@.str.4 = [7 x i8] c"accept\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [7 x i8] c"fdopen\00"
@.str.7 = [20 x i8] c"The time here is...\00"
@str = [16 x i8] c"Wow! got a call\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [256 x i8]
%3 = alloca i32
%4 = bitcast %struct.sockaddr_in* %1 to i8*
%5 = getelementptr inbounds [256 x i8], [256 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 eq i32 %9, -1
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 = call i32 @bzero(i8* %4, i32 12)
%16 = call i32 @gethostname(i8* %5, i32 256)
%17 = call %struct.hostent* @gethostbyname(i8* %5)
%18 = getelementptr inbounds %struct.hostent, %struct.hostent* %17, i64 0, i32 1
%19 = load i64, i64* %18
%20 = inttoptr i64 %19 to i8*
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
%22 = bitcast i32* %21 to i8*
%23 = getelementptr inbounds %struct.hostent, %struct.hostent* %17, i64 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 @htons(i32 13000)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %25, i32* %26
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %27, i32* %28
%29 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%30 = call i64 @bind(i32 %9, %struct.sockaddr* %29, i32 12)
%31 = icmp eq i64 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %14
%33 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %14
%36 = call i64 @listen(i32 %9, i32 1)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = call i32 @accept(i32 %9, i32* null, i32* null)
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%41 = icmp eq i32 %39, -1
br i1 %41, label %45, label %48
42: ; preds = %35
%43 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %55, %38
%46 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %38, %55
%49 = phi i32 [ %61, %55 ], [ %39, %38 ]
%50 = call i32* @fdopen(i32 %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%51 = icmp eq i32* %50, null
br i1 %51, label %52, label %55
52: ; preds = %48
%53 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %48
%56 = call i32 @time(i32* null)
store i32 %56, i32* %3
%57 = call i64 @fwrite(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i64 19, i64 1, i32* %50)
%58 = call i8* (i32*, ...) bitcast (i8* (...)* @ctime to i8* (i32*, ...)*)(i32* %3)
%59 = call i32 @fputs(i8* %58, i32* %50)
%60 = call i32 @fclose(i32* %50)
%61 = call i32 @accept(i32 %9, i32* null, i32* null)
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%63 = icmp eq i32 %61, -1
br i1 %63, label %45, label %48
}