#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;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int EINVAL;
int EXIT_FAILURE;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, size_t);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
char *strerror(int /*<<< orphan*/);
int strlen(char *);
int main(int count, char **args) {
  char *name = "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/hobbitalastair/backhand/refs/"
               "heads/master/src/connect.c";
  if (count > 0)
    name = args[0];
  if (count != 2) {
    fprintf(stderr, "usage: %s <socket>\n", name);
    return EINVAL;
  }
  char *path = args[1];
  if (strlen(path) >= 92) {
    fprintf(stderr, "%s: \"%s\" too long (max %zu bytes)\n", name, path,
            strlen(path));
    return EINVAL;
  }
  int sock = socket(AF_UNIX, SOCK_STREAM, 0);
  if (sock == -1) {
    fprintf(stderr, "%s: socket(): %s\n", name, strerror(errno));
    return EXIT_FAILURE;
  }
  struct sockaddr_un conn;
  conn.sun_family = AF_UNIX;
  strcpy(conn.sun_path, path);
  size_t len = strlen(path) + sizeof(conn.sun_family);
  if (connect(sock, (struct sockaddr *)(&conn), len) == -1) {
    fprintf(stderr, "%s: connect(): %s\n", name, strerror(errno));
    return EXIT_FAILURE;
  }
  char c = 0;
  read(sock, &c, 1);
  close(sock);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe60(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    11b9 <main+0x39>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ef <main+0x6f>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xebb(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    137c <main+0x1fc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x5c,%eax
jl     125f <main+0xdf>
mov    0x2dc4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    %eax,%r8d
lea    0xe5f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    137c <main+0x1fc>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
mov    0x2d61(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    12d0 <main+0x150>
mov    0x2d4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    0x2d28(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rdx
mov    %rax,%rcx
lea    0xe11(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2cfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    137c <main+0x1fc>
mov    0x2d11(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x30(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cltq
add    $0x4,%rax
mov    %rax,-0x38(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1080 <connect@plt>
cmp    $0xffffffff,%eax
jne    135f <main+0x1df>
mov    0x2cbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    0x2c99(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    -0x70(%rbp),%rdx
mov    %rax,%rcx
lea    0xd94(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2c6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    137c <main+0x1fc>
movb   $0x0,-0x39(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x39(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
test   %edi,%edi
jle    11d3 <main+0x53>
mov    (%rsi),%r14
cmp    $0x2,%edi
jne    11da <main+0x5a>
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x5c,%eax
jl     1208 <main+0x88>
mov    0x2e2a(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xee7(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    11f4 <main+0x74>
lea    0xe26(%rip),%r14
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
lea    0xea8(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dd9(%rip),%r15
mov    (%r15),%edi
mov    0x2db7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
cmp    $0xffffffff,%eax
je     1279 <main+0xf9>
mov    %eax,%ebp
mov    (%r15),%eax
mov    %eax,0x14(%rsp)
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movslq %eax,%rdx
add    $0x4,%rdx
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
call   1080 <connect@plt>
cmp    $0xffffffff,%eax
je     1299 <main+0x119>
movb   $0x0,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    11fd <main+0x7d>
mov    0x2d58(%rip),%rax
mov    (%rax),%ebx
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe32(%rip),%rsi
jmp    12b7 <main+0x137>
mov    0x2d38(%rip),%rax
mov    (%rax),%ebx
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe24(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2cf3(%rip),%rax
jmp    11fb <main+0x7b>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [146 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/hobbitalastair/backhand/refs/heads/master/src/connect.c\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"usage: %s <socket>\0A\00"
@EINVAL = global i32 0
@.str.2 = [35 x i8] c"%s: \22%s\22 too long (max %zu bytes)\0A\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [18 x i8] c"%s: socket(): %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.4 = [19 x i8] c"%s: connect(): %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca %struct.sockaddr_un
%10 = alloca i64
%11 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str, i64 0, i64 0), i8** %6
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
store i8* %17, i8** %6
br label %18
18: ; preds = %14, %2
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 2
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %6
%24 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = load i32, i32* @EINVAL
store i32 %25, i32* %3
br label %82
26: ; preds = %18
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
store i8* %29, i8** %7
%30 = load i8*, i8** %7
%31 = call i32 @strlen(i8* %30)
%32 = icmp sge i32 %31, 92
br i1 %32, label %33, label %41
33: ; preds = %26
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %6
%36 = load i8*, i8** %7
%37 = load i8*, i8** %7
%38 = call i32 @strlen(i8* %37)
%39 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %35, i8* %36, i32 %38)
%40 = load i32, i32* @EINVAL
store i32 %40, i32* %3
br label %82
41: ; preds = %26
%42 = load i32, i32* @AF_UNIX
%43 = load i32, i32* @SOCK_STREAM
%44 = call i32 @socket(i32 %42, i32 %43, i32 0)
store i32 %44, i32* %8
%45 = load i32, i32* %8
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %54
47: ; preds = %41
%48 = load i32, i32* @stderr
%49 = load i8*, i8** %6
%50 = load i32, i32* @errno
%51 = call i8* @strerror(i32 %50)
%52 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %49, i8* %51)
%53 = load i32, i32* @EXIT_FAILURE
store i32 %53, i32* %3
br label %82
54: ; preds = %41
%55 = load i32, i32* @AF_UNIX
%56 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %9, i32 0, i32 1
store i32 %55, i32* %56
%57 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %9, i32 0, i32 0
%58 = load i32, i32* %57
%59 = load i8*, i8** %7
%60 = call i32 @strcpy(i32 %58, i8* %59)
%61 = load i8*, i8** %7
%62 = call i32 @strlen(i8* %61)
%63 = sext i32 %62 to i64
%64 = add i64 %63, 4
store i64 %64, i64* %10
%65 = load i32, i32* %8
%66 = bitcast %struct.sockaddr_un* %9 to %struct.sockaddr*
%67 = load i64, i64* %10
%68 = call i32 @connect(i32 %65, %struct.sockaddr* %66, i64 %67)
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %77
70: ; preds = %54
%71 = load i32, i32* @stderr
%72 = load i8*, i8** %6
%73 = load i32, i32* @errno
%74 = call i8* @strerror(i32 %73)
%75 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %72, i8* %74)
%76 = load i32, i32* @EXIT_FAILURE
store i32 %76, i32* %3
br label %82
77: ; preds = %54
store i8 0, i8* %11
%78 = load i32, i32* %8
%79 = call i32 @read(i32 %78, i8* %11, i32 1)
%80 = load i32, i32* %8
%81 = call i32 @close(i32 %80)
br label %82
82: ; preds = %77, %70, %47, %33, %21
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [146 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/hobbitalastair/backhand/refs/heads/master/src/connect.c\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"usage: %s <socket>\0A\00"
@EINVAL = global i32 0
@.str.2 = [35 x i8] c"%s: \22%s\22 too long (max %zu bytes)\0A\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [18 x i8] c"%s: socket(): %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.4 = [19 x i8] c"%s: connect(): %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca i8
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = icmp eq i32 %0, 2
br i1 %8, label %14, label %9
9: ; preds = %2, %6
%10 = phi i8* [ %7, %6 ], [ getelementptr inbounds ([146 x i8], [146 x i8]* @.str, i64 0, i64 0), %2 ]
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%13 = load i32, i32* @EINVAL
br label %57
14: ; preds = %6
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32 @strlen(i8* %16)
%18 = icmp sgt i32 %17, 91
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = tail call i32 @strlen(i8* %16)
%22 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %7, i8* %16, i32 %21)
%23 = load i32, i32* @EINVAL
br label %57
24: ; preds = %14
%25 = load i32, i32* @AF_UNIX
%26 = load i32, i32* @SOCK_STREAM
%27 = tail call i32 @socket(i32 %25, i32 %26, i32 0)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %35
29: ; preds = %24
%30 = load i32, i32* @stderr
%31 = load i32, i32* @errno
%32 = tail call i8* @strerror(i32 %31)
%33 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %7, i8* %32)
%34 = load i32, i32* @EXIT_FAILURE
br label %57
35: ; preds = %24
%36 = bitcast %struct.sockaddr_un* %3 to i8*
%37 = load i32, i32* @AF_UNIX
%38 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %37, i32* %38
%39 = tail call i32 @strcpy(i32 undef, i8* %16)
%40 = tail call i32 @strlen(i8* %16)
%41 = sext i32 %40 to i64
%42 = add nsw i64 %41, 4
%43 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%44 = call i32 @connect(i32 %27, %struct.sockaddr* %43, i64 %42)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %52
46: ; preds = %35
%47 = load i32, i32* @stderr
%48 = load i32, i32* @errno
%49 = call i8* @strerror(i32 %48)
%50 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %7, i8* %49)
%51 = load i32, i32* @EXIT_FAILURE
br label %55
52: ; preds = %35
store i8 0, i8* %4
%53 = call i32 @read(i32 %27, i8* %4, i32 1)
%54 = call i32 @close(i32 %27)
br label %55
55: ; preds = %52, %46
%56 = phi i32 [ %51, %46 ], [ 0, %52 ]
br label %57
57: ; preds = %19, %55, %29, %9
%58 = phi i32 [ %13, %9 ], [ %23, %19 ], [ %34, %29 ], [ %56, %55 ]
ret i32 %58
}