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

/* Variables and functions */
int /*<<< orphan*/ AF_LOCAL;
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SHUT_RD;
int /*<<< orphan*/ SHUT_WR;
int /*<<< orphan*/ SOCK_STREAM;
int close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int shutdown(int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ std_error();
int /*<<< orphan*/ strncpy(scalar_t__ *, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  if (argc < 2) {
    printf("uncat /path/to/socket\n");
    return 0;
  }
  int fd = socket(AF_LOCAL, SOCK_STREAM, 0);
  if (fd == -1) {
    std_error();
    return 1;
  }
  int status = 0;
  struct sockaddr_un addr;
  addr.sun_family = AF_UNIX;
  strncpy(addr.sun_path, argv[1], sizeof(addr.sun_path) - 1);
  addr.sun_path[sizeof(addr.sun_path) - 1] = 0;
  if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
    std_error();
  } else {
    if (shutdown(fd, SHUT_WR) == -1)
      std_error();
    int r;
    char buf[4096];
    do {
      r = read(fd, buf, sizeof(buf));
      if (r > 0)
        write(1, buf, r);
    } while (r > 0);
    if (r == -1) {
      std_error();
      status = 2;
    }
    if (shutdown(fd, SHUT_RD) == -1)
      std_error();
  }
  if (close(fd) == -1)
    std_error();
  return status;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11cb <main+0x3b>
lea    0xe46(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1325 <main+0x195>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1204 <main+0x74>
mov    $0x0,%al
call   1090 <std_error@plt>
movl   $0x1,-0x4(%rbp)
jmp    1325 <main+0x195>
movl   $0x0,-0x18(%rbp)
mov    0x2dc6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x7,%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
movq   $0x0,0x38(%rax)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   10a0 <connect@plt>
cmp    $0xffffffff,%eax
jne    125f <main+0xcf>
mov    $0x0,%al
call   1090 <std_error@plt>
jmp    1307 <main+0x177>
mov    -0x14(%rbp),%edi
mov    0x2d7f(%rip),%rax
mov    (%rax),%esi
call   1050 <shutdown@plt>
cmp    $0xffffffff,%eax
jne    1280 <main+0xf0>
mov    $0x0,%al
call   1090 <std_error@plt>
jmp    1285 <main+0xf5>
mov    -0x14(%rbp),%edi
lea    -0x1030(%rbp),%rsi
mov    $0x1000,%edx
call   1080 <read@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jle    12ba <main+0x12a>
lea    -0x1030(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    $0x1,%edi
call   1040 <write@plt>
jmp    12bf <main+0x12f>
cmpl   $0x0,-0x2c(%rbp)
jg     1285 <main+0xf5>
cmpl   $0xffffffff,-0x2c(%rbp)
jne    12e1 <main+0x151>
mov    $0x0,%al
call   1090 <std_error@plt>
movl   $0x2,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2cf5(%rip),%rax
mov    (%rax),%esi
call   1050 <shutdown@plt>
cmp    $0xffffffff,%eax
jne    1302 <main+0x172>
mov    $0x0,%al
call   1090 <std_error@plt>
jmp    1307 <main+0x177>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    131f <main+0x18f>
mov    $0x0,%al
call   1090 <std_error@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x1,%edi
jg     1156 <main+0x16>
lea    0xeb3(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    %rsi,%rbx
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
cmp    $0xffffffff,%eax
jne    1185 <main+0x45>
xor    %eax,%eax
call   1050 <std_error@plt>
mov    $0x1,%eax
pop    %rbx
ret
mov    0x8(%rbx),%rsi
mov    $0x7,%edx
call   1030 <strncpy@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i64*, i32 }
%struct.sockaddr = type { i32 }
@.str = [23 x i8] c"uncat /path/to/socket\0A\00"
@AF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@AF_UNIX = global i32 0
@SHUT_WR = global i32 0
@SHUT_RD = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_un
%9 = alloca i32
%10 = alloca [4096 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %84
15: ; preds = %2
%16 = load i32, i32* @AF_LOCAL
%17 = load i32, i32* @SOCK_STREAM
%18 = call i32 @socket(i32 %16, i32 %17, i32 0)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 (...) @std_error()
store i32 1, i32* %3
br label %84
23: ; preds = %15
store i32 0, i32* %7
%24 = load i32, i32* @AF_UNIX
%25 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 1
store i32 %24, i32* %25
%26 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 0
%27 = load i64*, i64** %26
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @strncpy(i64* %27, i8* %30, i32 7)
%32 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 0
%33 = load i64*, i64** %32
%34 = getelementptr inbounds i64, i64* %33, i64 7
store i64 0, i64* %34
%35 = load i32, i32* %6
%36 = bitcast %struct.sockaddr_un* %8 to %struct.sockaddr*
%37 = call i32 @connect(i32 %35, %struct.sockaddr* %36, i32 16)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %41
39: ; preds = %23
%40 = call i32 (...) @std_error()
br label %76
41: ; preds = %23
%42 = load i32, i32* %6
%43 = load i32, i32* @SHUT_WR
%44 = call i32 @shutdown(i32 %42, i32 %43)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = call i32 (...) @std_error()
br label %48
48: ; preds = %46, %41
br label %49
49: ; preds = %60, %48
%50 = load i32, i32* %6
%51 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%52 = call i32 @read(i32 %50, i8* %51, i32 4096)
store i32 %52, i32* %9
%53 = load i32, i32* %9
%54 = icmp sgt i32 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %49
%56 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%57 = load i32, i32* %9
%58 = call i32 @write(i32 1, i8* %56, i32 %57)
br label %59
59: ; preds = %55, %49
br label %60
60: ; preds = %59
%61 = load i32, i32* %9
%62 = icmp sgt i32 %61, 0
br i1 %62, label %49, label %63
63: ; preds = %60
%64 = load i32, i32* %9
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %68
66: ; preds = %63
%67 = call i32 (...) @std_error()
store i32 2, i32* %7
br label %68
68: ; preds = %66, %63
%69 = load i32, i32* %6
%70 = load i32, i32* @SHUT_RD
%71 = call i32 @shutdown(i32 %69, i32 %70)
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %75
73: ; preds = %68
%74 = call i32 (...) @std_error()
br label %75
75: ; preds = %73, %68
br label %76
76: ; preds = %75, %39
%77 = load i32, i32* %6
%78 = call i32 @close(i32 %77)
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %82
80: ; preds = %76
%81 = call i32 (...) @std_error()
br label %82
82: ; preds = %80, %76
%83 = load i32, i32* %7
store i32 %83, i32* %3
br label %84
84: ; preds = %82, %21, %13
%85 = load i32, i32* %3
ret i32 %85
}

LLVM IR (-O2):
@AF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@AF_UNIX = global i32 0
@SHUT_WR = global i32 0
@SHUT_RD = global i32 0
@str = [22 x i8] c"uncat /path/to/socket\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %17
6: ; preds = %2
%7 = load i32, i32* @AF_LOCAL
%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 %13
11: ; preds = %6
%12 = tail call i32 (...) @std_error()
br label %17
13: ; preds = %6
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @strncpy(i64* undef, i8* %15, i32 7)
unreachable
17: ; preds = %11, %4
%18 = phi i32 [ 0, %4 ], [ 1, %11 ]
ret i32 %18
}