#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 sock {
  int dummy;
};
typedef int /*<<< orphan*/ SSL_CTX;

/* Variables and functions */
int smtp_ehlo(struct sock *, char const *);
int /*<<< orphan*/ smtp_get_msg(struct sock *, int);
int /*<<< orphan*/ smtp_starttls(struct sock *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sock_connect(struct sock *, char const *, char const *);
int smtp_connect(struct sock *sock, const char *hostname, const char *service,
                 SSL_CTX *ctx) {
  sock_connect(sock, hostname, service);
  smtp_get_msg(sock, 1);
  if (ctx)
    smtp_starttls(sock, ctx);
  return smtp_ehlo(sock, hostname);
}


x86 assembly (clang, -O0):
<smtp_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <sock_connect@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1050 <smtp_get_msg@plt>
cmpq   $0x0,-0x20(%rbp)
je     118f <smtp_connect+0x4f>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <smtp_starttls@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <smtp_ehlo@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smtp_connect>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
call   1060 <sock_connect@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1050 <smtp_get_msg@plt>
test   %r15,%r15
je     1170 <smtp_connect+0x30>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <smtp_starttls@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <smtp_ehlo@plt>

LLVM IR (-O0):
%struct.sock = type { i32 }
define i32 @smtp_connect(%struct.sock* %0, i8* %1, i8* %2, i32* %3) {
%5 = alloca %struct.sock*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
store %struct.sock* %0, %struct.sock** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32* %3, i32** %8
%9 = load %struct.sock*, %struct.sock** %5
%10 = load i8*, i8** %6
%11 = load i8*, i8** %7
%12 = call i32 @sock_connect(%struct.sock* %9, i8* %10, i8* %11)
%13 = load %struct.sock*, %struct.sock** %5
%14 = call i32 @smtp_get_msg(%struct.sock* %13, i32 1)
%15 = load i32*, i32** %8
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %4
%18 = load %struct.sock*, %struct.sock** %5
%19 = load i32*, i32** %8
%20 = call i32 @smtp_starttls(%struct.sock* %18, i32* %19)
br label %21
21: ; preds = %17, %4
%22 = load %struct.sock*, %struct.sock** %5
%23 = load i8*, i8** %6
%24 = call i32 @smtp_ehlo(%struct.sock* %22, i8* %23)
ret i32 %24
}

LLVM IR (-O2):
%struct.sock = type { i32 }
define i32 @smtp_connect(%struct.sock* %0, i8* %1, i8* %2, i32* %3) {
%5 = tail call i32 @sock_connect(%struct.sock* %0, i8* %1, i8* %2)
%6 = tail call i32 @smtp_get_msg(%struct.sock* %0, i32 1)
%7 = icmp eq i32* %3, null
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = tail call i32 @smtp_starttls(%struct.sock* %0, i32* %3)
br label %10
10: ; preds = %8, %4
%11 = tail call i32 @smtp_ehlo(%struct.sock* %0, i8* %1)
ret i32 %11
}