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

/* Variables and functions */
scalar_t__ conn_connect(struct SSH_CONN *, struct SSH_CONN_CONFIG const *);
int /*<<< orphan*/ conn_free(struct SSH_CONN *);
struct SSH_CONN *conn_new();
struct SSH_CONN *ssh_conn_open(const struct SSH_CONN_CONFIG *cfg) {
  struct SSH_CONN *conn;
  if ((conn = conn_new()) == NULL)
    return NULL;
  if (conn_connect(conn, cfg) < 0) {
    conn_free(conn);
    return NULL;
  }
  return conn;
}


x86 assembly (clang, -O0):
<ssh_conn_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <conn_new@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    115e <ssh_conn_open+0x2e>
movq   $0x0,-0x8(%rbp)
jmp    1193 <ssh_conn_open+0x63>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <conn_connect@plt>
cmp    $0x0,%rax
jge    118b <ssh_conn_open+0x5b>
mov    -0x18(%rbp),%rdi
call   1030 <conn_free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1193 <ssh_conn_open+0x63>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssh_conn_open>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1040 <conn_new@plt>
test   %rax,%rax
je     115e <ssh_conn_open+0x2e>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <conn_connect@plt>
test   %rax,%rax
jns    1160 <ssh_conn_open+0x30>
mov    %rbx,%rdi
call   1030 <conn_free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.SSH_CONN = type { i32 }
%struct.SSH_CONN_CONFIG = type { i32 }
define %struct.SSH_CONN* @ssh_conn_open(%struct.SSH_CONN_CONFIG* %0) {
%2 = alloca %struct.SSH_CONN*
%3 = alloca %struct.SSH_CONN_CONFIG*
%4 = alloca %struct.SSH_CONN*
store %struct.SSH_CONN_CONFIG* %0, %struct.SSH_CONN_CONFIG** %3
%5 = call %struct.SSH_CONN* (...) @conn_new()
store %struct.SSH_CONN* %5, %struct.SSH_CONN** %4
%6 = icmp eq %struct.SSH_CONN* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
store %struct.SSH_CONN* null, %struct.SSH_CONN** %2
br label %18
8: ; preds = %1
%9 = load %struct.SSH_CONN*, %struct.SSH_CONN** %4
%10 = load %struct.SSH_CONN_CONFIG*, %struct.SSH_CONN_CONFIG** %3
%11 = call i64 @conn_connect(%struct.SSH_CONN* %9, %struct.SSH_CONN_CONFIG* %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load %struct.SSH_CONN*, %struct.SSH_CONN** %4
%15 = call i32 @conn_free(%struct.SSH_CONN* %14)
store %struct.SSH_CONN* null, %struct.SSH_CONN** %2
br label %18
16: ; preds = %8
%17 = load %struct.SSH_CONN*, %struct.SSH_CONN** %4
store %struct.SSH_CONN* %17, %struct.SSH_CONN** %2
br label %18
18: ; preds = %16, %13, %7
%19 = load %struct.SSH_CONN*, %struct.SSH_CONN** %2
ret %struct.SSH_CONN* %19
}

LLVM IR (-O2):
%struct.SSH_CONN = type { i32 }
%struct.SSH_CONN_CONFIG = type { i32 }
define %struct.SSH_CONN* @ssh_conn_open(%struct.SSH_CONN_CONFIG* %0) {
%2 = tail call %struct.SSH_CONN* (...) @conn_new()
%3 = icmp eq %struct.SSH_CONN* %2, null
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = tail call i64 @conn_connect(%struct.SSH_CONN* %2, %struct.SSH_CONN_CONFIG* %0)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @conn_free(%struct.SSH_CONN* %2)
br label %9
9: ; preds = %4, %1, %7
%10 = phi %struct.SSH_CONN* [ null, %7 ], [ null, %1 ], [ %2, %4 ]
ret %struct.SSH_CONN* %10
}