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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ memset(struct sockaddr_un *, char, int);
int /*<<< orphan*/ printf(char *, char *);
size_t recv(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  struct sockaddr_un server_addr;
  int sockfd;
  char *socket_path = "/tmp/disnix-tcp-proxy.sock";
  char line[1024];
  ssize_t line_size;
  sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
  if (sockfd < 0)
    fprintf(stderr, "Error creating socket\n");
  memset(&server_addr, '\0', sizeof(server_addr));
  server_addr.sun_family = AF_UNIX;
  strcpy(server_addr.sun_path, socket_path);
  if (connect(sockfd, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0)
    fprintf(stderr, "Error connecting to TCP proxy: %s\n", strerror(errno));
  while ((line_size = recv(sockfd, line, 1024 - 1, 0)) > 0) {
    line[line_size] = '\0';
    printf("%s\n", line);
  }
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe50(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11f1 <main+0x61>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1090 <connect@plt>
cmp    $0x0,%rax
jge    1268 <main+0xd8>
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x43c(%rbp)
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x43c(%rbp),%edi
mov    %rax,%rdx
lea    0xdd1(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    126d <main+0xdd>
mov    -0x1c(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x3ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x438(%rbp)
cmp    $0x0,%rax
jbe    12bb <main+0x12b>
mov    -0x438(%rbp),%rax
movb   $0x0,-0x430(%rbp,%rax,1)
lea    -0x430(%rbp),%rsi
lea    0xda0(%rip),%rdi
call   1050 <printf@plt>
jmp    126d <main+0xdd>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x410,%rsp
mov    0x2e46(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    11d3 <main+0x43>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
lea    0xe4f(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rsp),%edi
lea    0xe07(%rip),%rsi
call   1040 <strcpy@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1090 <connect@plt>
test   %rax,%rax
jns    123d <main+0xad>
mov    0x2dbe(%rip),%rax
mov    (%rax),%ebx
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xe01(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0x3ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
je     1297 <main+0x107>
lea    0xdf4(%rip),%rbx
lea    0x10(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x0,0x10(%rsp,%rax,1)
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <printf@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x3ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
jne    1270 <main+0xe0>
mov    %r14d,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [27 x i8] c"/tmp/disnix-tcp-proxy.sock\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str.1 = [23 x i8] c"Error creating socket\0A\00"
@.str.2 = [35 x i8] c"Error connecting to TCP proxy: %s\0A\00"
@errno = global i32 0
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_un
%7 = alloca i32
%8 = alloca i8*
%9 = alloca [1024 x i8]
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8** %8
%11 = load i32, i32* @AF_UNIX
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %16, %2
%20 = call i32 @memset(%struct.sockaddr_un* %6, i8 signext 0, i32 8)
%21 = load i32, i32* @AF_UNIX
%22 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 1
store i32 %21, i32* %22
%23 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 0
%24 = load i32, i32* %23
%25 = load i8*, i8** %8
%26 = call i32 @strcpy(i32 %24, i8* %25)
%27 = load i32, i32* %7
%28 = bitcast %struct.sockaddr_un* %6 to %struct.sockaddr*
%29 = call i64 @connect(i32 %27, %struct.sockaddr* %28, i32 8)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %19
%32 = load i32, i32* @stderr
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %31, %19
br label %37
37: ; preds = %42, %36
%38 = load i32, i32* %7
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%40 = call i64 @recv(i32 %38, i8* %39, i32 1023, i32 0)
store i64 %40, i64* %10
%41 = icmp ugt i64 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %37
%43 = load i64, i64* %10
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 %43
store i8 0, i8* %44
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%46 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %45)
br label %37
47: ; preds = %37
%48 = load i32, i32* %7
%49 = call i32 @close(i32 %48)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [27 x i8] c"/tmp/disnix-tcp-proxy.sock\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str.1 = [23 x i8] c"Error creating socket\0A\00"
@.str.2 = [35 x i8] c"Error connecting to TCP proxy: %s\0A\00"
@errno = global i32 0
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca [1024 x i8]
%5 = bitcast %struct.sockaddr_un* %3 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @AF_UNIX
%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 = %2
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %11, %2
%15 = call i32 @memset(%struct.sockaddr_un* %3, i8 signext 0, i32 8)
%16 = load i32, i32* @AF_UNIX
%17 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %16, i32* %17
%18 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @strcpy(i32 %19, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%21 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%22 = call i64 @connect(i32 %9, %struct.sockaddr* %21, i32 8)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %14
%25 = load i32, i32* @stderr
%26 = load i32, i32* @errno
%27 = call i8* @strerror(i32 %26)
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %24, %14
%30 = call i64 @recv(i32 %9, i8* %6, i32 1023, i32 0)
%31 = icmp eq i64 %30, 0
br i1 %31, label %38, label %32
32: ; preds = %29, %32
%33 = phi i64 [ %36, %32 ], [ %30, %29 ]
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %33
store i8 0, i8* %34
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%36 = call i64 @recv(i32 %9, i8* %6, i32 1023, i32 0)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %32
38: ; preds = %32, %29
%39 = call i32 @close(i32 %9)
ret i32 0
}