#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 */

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int setup_tcp_client_socket(char *, char *, int);
int setup_unix_client_socket(char const *, int);
char *strdup(char const *);
scalar_t__ strncmp(char const *, char *, int);
char *strrchr(char *, char);
int setup_client_socket(const char *address, const char *default_port,
                        int nonblock) {
  char *addr, *port;
  int fd;
  if (strncmp(address, "unix://", 7) == 0) {
    return setup_unix_client_socket(address + 7, nonblock);
  } else {
    addr = strdup(address);
    if (!addr) {
      return -1;
    }
    port = strrchr(addr, ':');
    if (!port) {
      if (!default_port) {
        free(addr);
        return -1;
      }
      port = (char *)default_port;
    } else {
      *port++ = '\0';
    }
    fd = setup_tcp_client_socket(addr, port, nonblock);
    free(addr);
    return fd;
  }
}


x86 assembly (clang, -O0):
<setup_client_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe82(%rip),%rsi
mov    $0x7,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    11aa <setup_client_socket+0x4a>
mov    -0x10(%rbp),%rdi
add    $0x7,%rdi
mov    -0x1c(%rbp),%esi
call   1060 <setup_unix_client_socket@plt>
mov    %eax,-0x4(%rbp)
jmp    124c <setup_client_socket+0xec>
mov    -0x10(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ce <setup_client_socket+0x6e>
movl   $0xffffffff,-0x4(%rbp)
jmp    124c <setup_client_socket+0xec>
mov    -0x28(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1218 <setup_client_socket+0xb8>
cmpq   $0x0,-0x18(%rbp)
jne    120b <setup_client_socket+0xab>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124c <setup_client_socket+0xec>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    122a <setup_client_socket+0xca>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1070 <setup_tcp_client_socket@plt>
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_client_socket>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xe8c(%rip),%rsi
mov    $0x7,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     11b1 <setup_client_socket+0x51>
mov    %rbp,%rdi
call   1080 <strdup@plt>
test   %rax,%rax
je     11ed <setup_client_socket+0x8d>
mov    %rax,%rbp
mov    %rax,%rdi
mov    $0x3a,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     11c4 <setup_client_socket+0x64>
mov    %rax,%rbx
add    $0x1,%rbx
movb   $0x0,(%rax)
jmp    11c9 <setup_client_socket+0x69>
add    $0x7,%rbp
mov    %rbp,%rdi
mov    %r14d,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <setup_unix_client_socket@plt>
test   %rbx,%rbx
je     11e5 <setup_client_socket+0x85>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1070 <setup_tcp_client_socket@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
jmp    11f2 <setup_client_socket+0x92>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"unix://\00"
define i32 @setup_client_socket(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%11 = load i8*, i8** %5
%12 = call i64 @strncmp(i8* %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i64 7
%17 = load i32, i32* %7
%18 = call i32 @setup_unix_client_socket(i8* %16, i32 %17)
store i32 %18, i32* %4
br label %49
19: ; preds = %3
%20 = load i8*, i8** %5
%21 = call i8* @strdup(i8* %20)
store i8* %21, i8** %8
%22 = load i8*, i8** %8
%23 = icmp ne i8* %22, null
br i1 %23, label %25, label %24
24: ; preds = %19
store i32 -1, i32* %4
br label %49
25: ; preds = %19
%26 = load i8*, i8** %8
%27 = call i8* @strrchr(i8* %26, i8 signext 58)
store i8* %27, i8** %9
%28 = load i8*, i8** %9
%29 = icmp ne i8* %28, null
br i1 %29, label %38, label %30
30: ; preds = %25
%31 = load i8*, i8** %6
%32 = icmp ne i8* %31, null
br i1 %32, label %36, label %33
33: ; preds = %30
%34 = load i8*, i8** %8
%35 = call i32 @free(i8* %34)
store i32 -1, i32* %4
br label %49
36: ; preds = %30
%37 = load i8*, i8** %6
store i8* %37, i8** %9
br label %41
38: ; preds = %25
%39 = load i8*, i8** %9
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %9
store i8 0, i8* %39
br label %41
41: ; preds = %38, %36
%42 = load i8*, i8** %8
%43 = load i8*, i8** %9
%44 = load i32, i32* %7
%45 = call i32 @setup_tcp_client_socket(i8* %42, i8* %43, i32 %44)
store i32 %45, i32* %10
%46 = load i8*, i8** %8
%47 = call i32 @free(i8* %46)
%48 = load i32, i32* %10
store i32 %48, i32* %4
br label %49
49: ; preds = %41, %33, %24, %14
%50 = load i32, i32* %4
ret i32 %50
}

LLVM IR (-O2):
@.str = [8 x i8] c"unix://\00"
define i32 @setup_client_socket(i8* %0, i8* %1, i32 %2) {
%4 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = getelementptr inbounds i8, i8* %0, i64 7
%8 = tail call i32 @setup_unix_client_socket(i8* %7, i32 %2)
br label %25
9: ; preds = %3
%10 = tail call i8* @strdup(i8* %0)
%11 = icmp eq i8* %10, null
br i1 %11, label %25, label %12
12: ; preds = %9
%13 = tail call i8* @strrchr(i8* %10, i8 signext 58)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = icmp eq i8* %1, null
br i1 %16, label %17, label %21
17: ; preds = %15
%18 = tail call i32 @free(i8* %10)
br label %25
19: ; preds = %12
%20 = getelementptr inbounds i8, i8* %13, i64 1
store i8 0, i8* %13
br label %21
21: ; preds = %15, %19
%22 = phi i8* [ %20, %19 ], [ %1, %15 ]
%23 = tail call i32 @setup_tcp_client_socket(i8* %10, i8* %22, i32 %2)
%24 = tail call i32 @free(i8* %10)
br label %25
25: ; preds = %9, %21, %17, %6
%26 = phi i32 [ %8, %6 ], [ %23, %21 ], [ -1, %17 ], [ -1, %9 ]
ret i32 %26
}