#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 /*<<< orphan*/ PF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char const *);
char *strerror(int /*<<< orphan*/);
size_t strlen(char const *);
int otp_connect(const char *path) {
  int fd;
  struct sockaddr_un sa;
  size_t sp_len;
  sp_len = strlen(path);
  if (sp_len > sizeof(sa.sun_path) - 1) {
    fprintf(stderr, "otpauth: rendezvous point name too long\n");
    return -1;
  }
  sa.sun_family = AF_UNIX;
  (void)strcpy(sa.sun_path, path);
  if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) {
    fprintf(stderr, "otpauth: socket: %s\n", strerror(errno));
    return -1;
  }
  if (connect(fd, (struct sockaddr *)&sa, sizeof(sa.sun_family) + sp_len) ==
      -1) {
    fprintf(stderr, "otpauth: connect(%s): %s\n", path, strerror(errno));
    (void)close(fd);
    return -1;
  }
  return fd;
}


x86 assembly (clang, -O0):
<otp_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x3,-0x28(%rbp)
jbe    11b7 <otp_connect+0x47>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a1 <otp_connect+0x131>
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    122e <otp_connect+0xbe>
mov    0x2dd5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xe0e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a1 <otp_connect+0x131>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %eax,%edx
call   1070 <connect@plt>
cmp    $0xffffffff,%eax
jne    129b <otp_connect+0x12b>
mov    0x2d7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xdbe(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a1 <otp_connect+0x131>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<otp_connect>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
call   1040 <strlen@plt>
cmp    $0x4,%rax
jb     11a2 <otp_connect+0x32>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    0xe6a(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1250 <otp_connect+0xe0>
mov    %rax,%rbx
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
cmp    $0xffffffff,%eax
je     1226 <otp_connect+0xb6>
mov    %eax,%ebp
add    $0x4,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    %ebx,%edx
call   1070 <connect@plt>
cmp    $0xffffffff,%eax
jne    1255 <otp_connect+0xe5>
mov    0x2dd9(%rip),%rax
mov    (%rax),%ebx
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe30(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebp,%edi
call   1050 <close@plt>
jmp    1250 <otp_connect+0xe0>
mov    0x2da3(%rip),%rax
mov    (%rax),%ebx
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xde5(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [41 x i8] c"otpauth: rendezvous point name too long\0A\00"
@AF_UNIX = global i32 0
@PF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [21 x i8] c"otpauth: socket: %s\0A\00"
@errno = global i32 0
@.str.2 = [26 x i8] c"otpauth: connect(%s): %s\0A\00"
define i32 @otp_connect(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.sockaddr_un
%6 = alloca i64
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %6
%9 = load i64, i64* %6
%10 = icmp ugt i64 %9, 3
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %48
14: ; preds = %1
%15 = load i32, i32* @AF_UNIX
%16 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i32 0, i32 1
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i32 0, i32 0
%18 = load i32, i32* %17
%19 = load i8*, i8** %3
%20 = call i32 @strcpy(i32 %18, i8* %19)
%21 = load i32, i32* @PF_UNIX
%22 = load i32, i32* @SOCK_STREAM
%23 = call i32 @socket(i32 %21, i32 %22, i32 0)
store i32 %23, i32* %4
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %30
25: ; preds = %14
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %28)
store i32 -1, i32* %2
br label %48
30: ; preds = %14
%31 = load i32, i32* %4
%32 = bitcast %struct.sockaddr_un* %5 to %struct.sockaddr*
%33 = load i64, i64* %6
%34 = add i64 4, %33
%35 = trunc i64 %34 to i32
%36 = call i32 @connect(i32 %31, %struct.sockaddr* %32, i32 %35)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %46
38: ; preds = %30
%39 = load i32, i32* @stderr
%40 = load i8*, i8** %3
%41 = load i32, i32* @errno
%42 = call i8* @strerror(i32 %41)
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %40, i8* %42)
%44 = load i32, i32* %4
%45 = call i32 @close(i32 %44)
store i32 -1, i32* %2
br label %48
46: ; preds = %30
%47 = load i32, i32* %4
store i32 %47, i32* %2
br label %48
48: ; preds = %46, %38, %25, %11
%49 = load i32, i32* %2
ret i32 %49
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [41 x i8] c"otpauth: rendezvous point name too long\0A\00"
@AF_UNIX = global i32 0
@PF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [21 x i8] c"otpauth: socket: %s\0A\00"
@errno = global i32 0
@.str.2 = [26 x i8] c"otpauth: connect(%s): %s\0A\00"
define i32 @otp_connect(i8* %0) {
%2 = alloca %struct.sockaddr_un
%3 = bitcast %struct.sockaddr_un* %2 to i8*
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = icmp ugt i64 %4, 3
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %34
9: ; preds = %1
%10 = load i32, i32* @AF_UNIX
%11 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 1
store i32 %10, i32* %11
%12 = tail call i32 @strcpy(i32 undef, i8* %0)
%13 = load i32, i32* @PF_UNIX
%14 = load i32, i32* @SOCK_STREAM
%15 = tail call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %22
17: ; preds = %9
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %34
22: ; preds = %9
%23 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%24 = trunc i64 %4 to i32
%25 = add nuw nsw i32 %24, 4
%26 = call i32 @connect(i32 %15, %struct.sockaddr* %23, i32 %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %34
28: ; preds = %22
%29 = load i32, i32* @stderr
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %31)
%33 = call i32 @close(i32 %15)
br label %34
34: ; preds = %22, %28, %17, %6
%35 = phi i32 [ -1, %6 ], [ -1, %17 ], [ -1, %28 ], [ %15, %22 ]
ret i32 %35
}