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

/* Variables and functions */
int /*<<< orphan*/ PF_LOCAL;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ connect(int, struct sockaddr *, unsigned long);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ unlink(char *);
int main(void) {
  struct sockaddr_un local;
  local.sun_family = PF_LOCAL;
  strcpy(local.sun_path, "testechos.sock");
  unlink(local.sun_path);
  unsigned long sun_len = strlen(local.sun_path) + sizeof(local.sun_family);
  int socket_1 = socket(PF_LOCAL, SOCK_STREAM, 0);
  connect(socket_1, (struct sockaddr *)&local, sun_len + 1);
  for (;;) {
    printf(">>%ld\n", time(NULL));
    char *payload = "hello";
    send(socket_1, payload, strlen(payload), 0);
    sleep(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe4a(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
cltq
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
add    $0x1,%rdx
call   1090 <connect@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%esi
lea    0xdf6(%rip),%rdi
call   1070 <printf@plt>
lea    0xdf1(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
jmp    1207 <main+0x77>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e39(%rip),%rbp
mov    0x0(%rbp),%eax
mov    %eax,0x8(%rsp)
lea    0xe53(%rip),%rsi
call   1040 <strcpy@plt>
call   1030 <unlink@plt>
call   1050 <strlen@plt>
movslq %eax,%rbx
mov    0x0(%rbp),%edi
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%ebp
add    $0x5,%rbx
mov    %rsp,%rsi
mov    %eax,%edi
mov    %rbx,%rdx
call   1090 <connect@plt>
lea    0xe23(%rip),%r14
lea    0xe23(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %edi,%edi
call   1080 <time@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
jmp    1200 <main+0x70>

LLVM IR (-O0):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@PF_LOCAL = global i32 0
@.str = [15 x i8] c"testechos.sock\00"
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c">>%ld\0A\00"
@.str.2 = [6 x i8] c"hello\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_un
%3 = alloca i64
%4 = alloca i32
%5 = alloca i8*
store i32 0, i32* %1
%6 = load i32, i32* @PF_LOCAL
%7 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i32 0, i32 1
store i32 %6, i32* %7
%8 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i32 0, i32 0
%9 = load i8*, i8** %8
%10 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i32 0, i32 0
%12 = load i8*, i8** %11
%13 = call i32 @unlink(i8* %12)
%14 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i32 0, i32 0
%15 = load i8*, i8** %14
%16 = call i32 @strlen(i8* %15)
%17 = sext i32 %16 to i64
%18 = add i64 %17, 4
store i64 %18, i64* %3
%19 = load i32, i32* @PF_LOCAL
%20 = load i32, i32* @SOCK_STREAM
%21 = call i32 @socket(i32 %19, i32 %20, i32 0)
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%24 = load i64, i64* %3
%25 = add i64 %24, 1
%26 = call i32 @connect(i32 %22, %struct.sockaddr* %23, i64 %25)
br label %27
27: ; preds = %27, %0
%28 = call i32 @time(i32* null)
%29 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %28)
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %5
%30 = load i32, i32* %4
%31 = load i8*, i8** %5
%32 = load i8*, i8** %5
%33 = call i32 @strlen(i8* %32)
%34 = call i32 @send(i32 %30, i8* %31, i32 %33, i32 0)
%35 = call i32 @sleep(i32 1)
br label %27
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@PF_LOCAL = global i32 0
@.str = [15 x i8] c"testechos.sock\00"
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c">>%ld\0A\00"
@.str.2 = [6 x i8] c"hello\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_un
%2 = bitcast %struct.sockaddr_un* %1 to i8*
%3 = load i32, i32* @PF_LOCAL
%4 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 1
store i32 %3, i32* %4
%5 = tail call i32 @strcpy(i8* undef, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @unlink(i8* undef)
%7 = tail call i32 @strlen(i8* undef)
%8 = sext i32 %7 to i64
%9 = load i32, i32* @PF_LOCAL
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = bitcast %struct.sockaddr_un* %1 to %struct.sockaddr*
%13 = add nsw i64 %8, 5
%14 = call i32 @connect(i32 %11, %struct.sockaddr* %12, i64 %13)
br label %15
15: ; preds = %15, %0
%16 = call i32 @time(i32* null)
%17 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @send(i32 %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %18, i32 0)
%20 = call i32 @sleep(i32 1)
br label %15
}