#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 {
  scalar_t__ sa_family;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
scalar_t__ AF_LOCAL;
int /*<<< orphan*/ ECONNREFUSED;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ errno;
char *get_in_addr(struct sockaddr const *);
int /*<<< orphan*/ inet_ntop(scalar_t__, char *, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int connect(int sockfd, struct sockaddr const *addr, socklen_t addrlen) {
  char s[INET6_ADDRSTRLEN];
  char *p = NULL;
  if (addr->sa_family == AF_LOCAL) {
    p = get_in_addr(addr);
    printf("!! Connection refused to: %s\n", p);
    return -1;
  } else {
    inet_ntop(addr->sa_family, get_in_addr(addr), s, sizeof s);
    p = s;
    errno = ECONNREFUSED;
    printf("!! Connection refused to: %s\n", p);
    return -1;
  }
}


x86 assembly (clang, -O0):
<connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2e9f(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x48(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e58(%rip),%rcx
cmp    (%rcx),%rax
jne    11c1 <connect+0x91>
mov    -0x10(%rbp),%rdi
call   1040 <get_in_addr@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xe57(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1223 <connect+0xf3>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <get_in_addr@plt>
mov    -0x50(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    %rax,%rsi
mov    -0x48(%rbp),%rax
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2dde(%rip),%rax
mov    (%rax),%ecx
mov    0x2dc5(%rip),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rsi
lea    0xdf0(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connect>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rdi
mov    0x2ea3(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    (%rsi),%r15
mov    0x2e7d(%rip),%rax
mov    (%rax),%r12
call   1040 <get_in_addr@plt>
cmp    %r12,%r15
jne    117c <connect+0x4c>
lea    0xe89(%rip),%rdi
mov    %rax,%rsi
jmp    11a9 <connect+0x79>
mov    %r15,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
call   1030 <inet_ntop@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    0x2e2b(%rip),%rcx
mov    %eax,(%rcx)
lea    0xe5a(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    $0xffffffff,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i64 }
@INET6_ADDRSTRLEN = global i32 0
@AF_LOCAL = global i64 0
@.str = [30 x i8] c"!! Connection refused to: %s\0A\00"
@ECONNREFUSED = global i32 0
@errno = global i32 0
define i32 @connect(i32 %0, %struct.sockaddr* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i32
store i32 %0, i32* %5
store %struct.sockaddr* %1, %struct.sockaddr** %6
store i32 %2, i32* %7
%12 = load i32, i32* @INET6_ADDRSTRLEN
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %8
%15 = alloca i8, i64 %13
store i64 %13, i64* %9
store i8* null, i8** %10
%16 = load %struct.sockaddr*, %struct.sockaddr** %6
%17 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %16, i32 0, i32 0
%18 = load i64, i64* %17
%19 = load i64, i64* @AF_LOCAL
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %26
21: ; preds = %3
%22 = load %struct.sockaddr*, %struct.sockaddr** %6
%23 = call i8* @get_in_addr(%struct.sockaddr* %22)
store i8* %23, i8** %10
%24 = load i8*, i8** %10
%25 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %24)
store i32 -1, i32* %4
store i32 1, i32* %11
br label %37
26: ; preds = %3
%27 = load %struct.sockaddr*, %struct.sockaddr** %6
%28 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %27, i32 0, i32 0
%29 = load i64, i64* %28
%30 = load %struct.sockaddr*, %struct.sockaddr** %6
%31 = call i8* @get_in_addr(%struct.sockaddr* %30)
%32 = trunc i64 %13 to i32
%33 = call i32 @inet_ntop(i64 %29, i8* %31, i8* %15, i32 %32)
store i8* %15, i8** %10
%34 = load i32, i32* @ECONNREFUSED
store i32 %34, i32* @errno
%35 = load i8*, i8** %10
%36 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %35)
store i32 -1, i32* %4
store i32 1, i32* %11
br label %37
37: ; preds = %26, %21
%38 = load i8*, i8** %8
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
%struct.sockaddr = type { i64 }
@INET6_ADDRSTRLEN = global i32 0
@AF_LOCAL = global i64 0
@.str = [30 x i8] c"!! Connection refused to: %s\0A\00"
@ECONNREFUSED = global i32 0
@errno = global i32 0
define i32 @connect(i32 %0, %struct.sockaddr* %1, i32 %2) {
%4 = load i32, i32* @INET6_ADDRSTRLEN
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %1, i64 0, i32 0
%8 = load i64, i64* %7
%9 = load i64, i64* @AF_LOCAL
%10 = icmp eq i64 %8, %9
%11 = tail call i8* @get_in_addr(%struct.sockaddr* %1)
br i1 %10, label %12, label %14
12: ; preds = %3
%13 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %18
14: ; preds = %3
%15 = call i32 @inet_ntop(i64 %8, i8* %11, i8* %6, i32 %4)
%16 = load i32, i32* @ECONNREFUSED
store i32 %16, i32* @errno
%17 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %18
18: ; preds = %14, %12
ret i32 -1
}