#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_un {
  int /*<<< orphan*/ sun_path;
  int /*<<< orphan*/ sun_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ PF_UNIX;
int /*<<< orphan*/ SOCK_DGRAM;
int bind(int, struct sockaddr *, int);
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, char *, char *);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int ac, char *av[]) {
  int sock;
  struct sockaddr_un addr;
  socklen_t addrlen;
  char msg[512];
  int l;
  char sockname[] = "/tmp/logfilesock";
  time_t now;
  int msgnum = 0;
  char *timestr;
  addr.sun_family = AF_UNIX;
  strcpy(addr.sun_path, sockname);
  addrlen = strlen(sockname) + sizeof(addr.sun_family);
  sock = socket(PF_UNIX, SOCK_DGRAM, 0);
  if (sock == -1) {
    perror("socket");
    exit(2);
  };
  if (bind(sock, (struct sockaddr *)&addr, addrlen) == -1) {
    perror("bind");
    exit(3);
  };
  while (1) {
    l = read(sock, msg, 512);
    msg[l] = '\0';
    time(&now);
    timestr = ctime(&now);
    timestr[strlen(timestr) - 1] = '\0';
    printf("[%5d] %s %s\n", msgnum++, timestr, msg);
    fflush(stdout);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x270,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe30(%rip),%rax
mov    %rax,-0x250(%rbp)
mov    0xe2a(%rip),%rax
mov    %rax,-0x248(%rbp)
mov    0xe25(%rip),%al
mov    %al,-0x240(%rbp)
movl   $0x0,-0x258(%rbp)
mov    0x2dde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
lea    -0x250(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x250(%rbp),%rdi
call   1050 <strlen@plt>
cltq
add    $0x4,%rax
mov    %eax,-0x24(%rbp)
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
mov    0x2d9d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1267 <main+0xb7>
lea    0xdb9(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x2,%edi
call   10c0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1295 <main+0xe5>
lea    0xd92(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x3,%edi
call   10c0 <exit@plt>
jmp    129a <main+0xea>
mov    -0x14(%rbp),%edi
lea    -0x230(%rbp),%rsi
mov    $0x200,%edx
call   1070 <read@plt>
mov    %eax,-0x234(%rbp)
movslq -0x234(%rbp),%rax
movb   $0x0,-0x230(%rbp,%rax,1)
lea    -0x254(%rbp),%rdi
call   1080 <time@plt>
lea    -0x254(%rbp),%rdi
call   1040 <ctime@plt>
mov    %rax,-0x260(%rbp)
mov    -0x260(%rbp),%rax
mov    %rax,-0x270(%rbp)
mov    -0x260(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x270(%rbp),%rax
sub    $0x1,%ecx
mov    %ecx,-0x268(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x258(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x264(%rbp)
mov    %eax,-0x258(%rbp)
mov    -0x260(%rbp),%rdx
lea    -0x230(%rbp),%rcx
lea    0xcdc(%rip),%rdi
call   1060 <printf@plt>
mov    0x2c7b(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
jmp    129a <main+0xea>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x238,%rsp
movaps 0xe38(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movb   $0x0,0x20(%rsp)
mov    0x2e07(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
mov    0x2dd2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
cmp    $0xffffffff,%eax
je     12a4 <main+0xf4>
mov    %eax,%r14d
add    $0x4,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    %ebx,%edx
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
je     12ba <main+0x10a>
xor    %ebx,%ebx
lea    0x30(%rsp),%r12
lea    0xc(%rsp),%r13
nop
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x200,%edx
call   1070 <read@plt>
cltq
movb   $0x0,0x30(%rsp,%rax,1)
mov    %r13,%rdi
call   1080 <time@plt>
mov    %r13,%rdi
call   1040 <ctime@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbp,1)
lea    0x1(%rbx),%r15d
lea    0xd99(%rip),%rdi
mov    %ebx,%esi
mov    %rbp,%rdx
mov    %r12,%rcx
call   1060 <printf@plt>
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    %r15d,%ebx
jmp    1240 <main+0x90>
lea    0xd66(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x2,%edi
call   10c0 <exit@plt>
lea    0xd57(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x3,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@__const.main.sockname = [17 x i8] c"/tmp/logfilesock\00"
@AF_UNIX = global i32 0
@PF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [13 x i8] c"[%5d] %s %s\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_un
%8 = alloca i32
%9 = alloca [512 x i8]
%10 = alloca i32
%11 = alloca [17 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = bitcast [17 x i8]* %11 to i8*
store i32 0, i32* %13
%16 = load i32, i32* @AF_UNIX
%17 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 1
store i32 %16, i32* %17
%18 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 0
%19 = load i32, i32* %18
%20 = getelementptr inbounds [17 x i8], [17 x i8]* %11, i64 0, i64 0
%21 = call i32 @strcpy(i32 %19, i8* %20)
%22 = getelementptr inbounds [17 x i8], [17 x i8]* %11, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
%24 = sext i32 %23 to i64
%25 = add i64 %24, 4
%26 = trunc i64 %25 to i32
store i32 %26, i32* %8
%27 = load i32, i32* @PF_UNIX
%28 = load i32, i32* @SOCK_DGRAM
%29 = call i32 @socket(i32 %27, i32 %28, i32 0)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %2
%33 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%34 = call i32 @exit(i32 2)
unreachable
35: ; preds = %2
%36 = load i32, i32* %6
%37 = bitcast %struct.sockaddr_un* %7 to %struct.sockaddr*
%38 = load i32, i32* %8
%39 = call i32 @bind(i32 %36, %struct.sockaddr* %37, i32 %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %35
%42 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%43 = call i32 @exit(i32 3)
unreachable
44: ; preds = %35
br label %45
45: ; preds = %44, %45
%46 = load i32, i32* %6
%47 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%48 = call i32 @read(i32 %46, i8* %47, i32 512)
store i32 %48, i32* %10
%49 = load i32, i32* %10
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 %50
store i8 0, i8* %51
%52 = call i32 @time(i32* %12)
%53 = call i8* @ctime(i32* %12)
store i8* %53, i8** %14
%54 = load i8*, i8** %14
%55 = load i8*, i8** %14
%56 = call i32 @strlen(i8* %55)
%57 = sub nsw i32 %56, 1
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %54, i64 %58
store i8 0, i8* %59
%60 = load i32, i32* %13
%61 = add nsw i32 %60, 1
store i32 %61, i32* %13
%62 = load i8*, i8** %14
%63 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%64 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %60, i8* %62, i8* %63)
%65 = load i32, i32* @stdout
%66 = call i32 @fflush(i32 %65)
br label %45
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@__const.main.sockname = [17 x i8] c"/tmp/logfilesock\00"
@AF_UNIX = global i32 0
@PF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [13 x i8] c"[%5d] %s %s\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca [512 x i8]
%5 = alloca [17 x i8]
%6 = alloca i32
%7 = bitcast %struct.sockaddr_un* %3 to i8*
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 0
%10 = bitcast i32* %6 to i8*
%11 = load i32, i32* @AF_UNIX
%12 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %11, i32* %12
%13 = call i32 @strcpy(i32 undef, i8* %9)
%14 = call i32 @strlen(i8* %9)
%15 = load i32, i32* @PF_UNIX
%16 = load i32, i32* @SOCK_DGRAM
%17 = call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 2)
unreachable
22: ; preds = %2
%23 = add i32 %14, 4
%24 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%25 = call i32 @bind(i32 %17, %struct.sockaddr* %24, i32 %23)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 3)
unreachable
30: ; preds = %22, %30
%31 = phi i32 [ %41, %30 ], [ 0, %22 ]
%32 = call i32 @read(i32 %17, i8* %8, i32 512)
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %33
store i8 0, i8* %34
%35 = call i32 @time(i32* %6)
%36 = call i8* @ctime(i32* %6)
%37 = call i32 @strlen(i8* %36)
%38 = add nsw i32 %37, -1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
store i8 0, i8* %40
%41 = add nuw nsw i32 %31, 1
%42 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %31, i8* %36, i8* %8)
%43 = load i32, i32* @stdout
%44 = call i32 @fflush(i32 %43)
br label %30
}