#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 {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ cw_connect(int, struct sockaddr *, int, int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int sk_conn(struct sockaddr *name, int ssl) {
  int sock;
  if ((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
    perror("socket (socket.c:23)");
    return -1;
  }
  if (cw_connect(sock, (struct sockaddr *)name, sizeof(struct sockaddr), ssl) <
      0) {
    perror("connect (socket.c:29)");
    close(sock);
    return -1;
  }
  return sock;
}


x86 assembly (clang, -O0):
<sk_conn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    118c <sk_conn+0x4c>
lea    0xe85(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d0 <sk_conn+0x90>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%ecx
mov    $0x4,%edx
call   1040 <cw_connect@plt>
cmp    $0x0,%rax
jge    11ca <sk_conn+0x8a>
lea    0xe64(%rip),%rdi
call   1050 <perror@plt>
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d0 <sk_conn+0x90>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sk_conn>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbp
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
test   %eax,%eax
js     1187 <sk_conn+0x47>
mov    %eax,%ebx
mov    %eax,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
mov    %r14d,%ecx
call   1040 <cw_connect@plt>
test   %rax,%rax
js     1195 <sk_conn+0x55>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe72(%rip),%rdi
call   1050 <perror@plt>
jmp    11a8 <sk_conn+0x68>
lea    0xe79(%rip),%rdi
call   1050 <perror@plt>
mov    %ebx,%edi
call   1030 <close@plt>
mov    $0xffffffff,%ebx
jmp    1180 <sk_conn+0x40>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [21 x i8] c"socket (socket.c:23)\00"
@.str.1 = [22 x i8] c"connect (socket.c:29)\00"
define i32 @sk_conn(%struct.sockaddr* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr*
%5 = alloca i32
%6 = alloca i32
store %struct.sockaddr* %0, %struct.sockaddr** %4
store i32 %1, i32* %5
%7 = load i32, i32* @PF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %6
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %25
13: ; preds = %2
%14 = load i32, i32* %6
%15 = load %struct.sockaddr*, %struct.sockaddr** %4
%16 = load i32, i32* %5
%17 = call i64 @cw_connect(i32 %14, %struct.sockaddr* %15, i32 4, i32 %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* %6
%22 = call i32 @close(i32 %21)
store i32 -1, i32* %3
br label %25
23: ; preds = %13
%24 = load i32, i32* %6
store i32 %24, i32* %3
br label %25
25: ; preds = %23, %19, %11
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [21 x i8] c"socket (socket.c:23)\00"
@.str.1 = [22 x i8] c"connect (socket.c:29)\00"
define i32 @sk_conn(%struct.sockaddr* %0, i32 %1) {
%3 = load i32, i32* @PF_INET
%4 = load i32, i32* @SOCK_STREAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %15
9: ; preds = %2
%10 = tail call i64 @cw_connect(i32 %5, %struct.sockaddr* %0, i32 4, i32 %1)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @close(i32 %5)
br label %15
15: ; preds = %9, %12, %7
%16 = phi i32 [ -1, %7 ], [ -1, %12 ], [ %5, %9 ]
ret i32 %16
}