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

/* Variables and functions */
int /*<<< orphan*/ kex_free(struct SSH_KEX *);
struct SSH_KEX *kex_new(struct SSH_CONN *);
scalar_t__ kex_start(struct SSH_CONN *, struct SSH_KEX *);
int ssh_kex_run(struct SSH_CONN *conn) {
  struct SSH_KEX *kex;
  ;
  if ((kex = kex_new(conn)) == NULL)
    return -1;
  if (kex_start(conn, kex) < 0) {
    kex_free(kex);
    return -1;
  }
  kex_free(kex);
  ;
  return 0;
}


x86 assembly (clang, -O0):
<ssh_kex_run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <kex_new@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    115f <ssh_kex_run+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    119b <ssh_kex_run+0x6b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <kex_start@plt>
cmp    $0x0,%rax
jge    118b <ssh_kex_run+0x5b>
mov    -0x18(%rbp),%rdi
call   1040 <kex_free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    119b <ssh_kex_run+0x6b>
mov    -0x18(%rbp),%rdi
call   1040 <kex_free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssh_kex_run>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <kex_new@plt>
test   %rax,%rax
je     1160 <ssh_kex_run+0x30>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <kex_start@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <kex_free@plt>
sar    $0x3f,%r14
jmp    1166 <ssh_kex_run+0x36>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.SSH_CONN = type { i32 }
%struct.SSH_KEX = type { i32 }
define i32 @ssh_kex_run(%struct.SSH_CONN* %0) {
%2 = tail call %struct.SSH_KEX* @kex_new(%struct.SSH_CONN* %0)
%3 = icmp eq %struct.SSH_KEX* %2, null
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = tail call i64 @kex_start(%struct.SSH_CONN* %0, %struct.SSH_KEX* %2)
%6 = tail call i32 @kex_free(%struct.SSH_KEX* %2)
%7 = ashr i64 %5, 63
%8 = trunc i64 %7 to i32
br label %9
9: ; preds = %4, %1
%10 = phi i32 [ -1, %1 ], [ %8, %4 ]
ret i32 %10
}