#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 smtp_errorCode(char *);
int smtp_sendCommand(long, char *, unsigned long);
int sock_connect(long, unsigned long, unsigned short);
int sock_dataReady(long);
char *sock_getHostName();
int sock_readLine(long, char *, int, unsigned long);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int smtp_connect(long int sock, unsigned long addr, unsigned short port,
                 unsigned long timeout) {
  char buf[513];
  int smtpError;
  int err, i;
  err = sock_connect(sock, addr, port);
  if (err < 0)
    return err;
  err = sock_readLine(sock, buf, 513, timeout);
  if (err < 0)
    return err;
  smtpError = smtp_errorCode(buf);
  if (smtpError != 220)
    return smtpError;
  sprintf(buf, "HELO %s\r\n", sock_getHostName());
  err = smtp_sendCommand(sock, buf, timeout);
  if (err != 250)
    return err;
  while ((i = sock_dataReady(sock)) != 0) {
    err = sock_readLine(sock, buf, 513, timeout);
    if (err < 0)
      return err;
    err = smtp_errorCode(buf);
    if (err != 250)
      return err;
  }
  return 0;
}


x86 assembly (clang, -O0):
<smtp_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
mov    %dx,%ax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %ax,-0x1a(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movzwl -0x1a(%rbp),%edx
call   1080 <sock_connect@plt>
mov    %eax,-0x238(%rbp)
cmpl   $0x0,-0x238(%rbp)
jge    11c0 <smtp_connect+0x50>
mov    -0x238(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1320 <smtp_connect+0x1b0>
mov    -0x10(%rbp),%rdi
lea    -0x230(%rbp),%rsi
mov    -0x28(%rbp),%rcx
mov    $0x201,%edx
call   1050 <sock_readLine@plt>
mov    %eax,-0x238(%rbp)
cmpl   $0x0,-0x238(%rbp)
jge    11fa <smtp_connect+0x8a>
mov    -0x238(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1320 <smtp_connect+0x1b0>
lea    -0x230(%rbp),%rdi
call   1030 <smtp_errorCode@plt>
mov    %eax,-0x234(%rbp)
cmpl   $0xdc,-0x234(%rbp)
je     122a <smtp_connect+0xba>
mov    -0x234(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1320 <smtp_connect+0x1b0>
lea    -0x230(%rbp),%rax
mov    %rax,-0x248(%rbp)
mov    $0x0,%al
call   1060 <sock_getHostName@plt>
mov    -0x248(%rbp),%rdi
mov    %rax,%rdx
lea    0xdb0(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x230(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1090 <smtp_sendCommand@plt>
mov    %eax,-0x238(%rbp)
cmpl   $0xfa,-0x238(%rbp)
je     128d <smtp_connect+0x11d>
mov    -0x238(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1320 <smtp_connect+0x1b0>
jmp    1292 <smtp_connect+0x122>
mov    -0x10(%rbp),%rdi
call   1040 <sock_dataReady@plt>
mov    %eax,-0x23c(%rbp)
cmp    $0x0,%eax
je     1319 <smtp_connect+0x1a9>
mov    -0x10(%rbp),%rdi
lea    -0x230(%rbp),%rsi
mov    -0x28(%rbp),%rcx
mov    $0x201,%edx
call   1050 <sock_readLine@plt>
mov    %eax,-0x238(%rbp)
cmpl   $0x0,-0x238(%rbp)
jge    12e4 <smtp_connect+0x174>
mov    -0x238(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1320 <smtp_connect+0x1b0>
lea    -0x230(%rbp),%rdi
call   1030 <smtp_errorCode@plt>
mov    %eax,-0x238(%rbp)
cmpl   $0xfa,-0x238(%rbp)
je     1314 <smtp_connect+0x1a4>
mov    -0x238(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1320 <smtp_connect+0x1b0>
jmp    1292 <smtp_connect+0x122>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smtp_connect>:
push   %r15
push   %r14
push   %rbx
sub    $0x210,%rsp
mov    %rcx,%r14
mov    %rdi,%rbx
call   1080 <sock_connect@plt>
test   %eax,%eax
js     1226 <smtp_connect+0xb6>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0x201,%edx
mov    %r14,%rcx
call   1050 <sock_readLine@plt>
test   %eax,%eax
js     1226 <smtp_connect+0xb6>
mov    %rsp,%rdi
call   1030 <smtp_errorCode@plt>
cmp    $0xdc,%eax
jne    1226 <smtp_connect+0xb6>
xor    %eax,%eax
call   1060 <sock_getHostName@plt>
lea    0xe39(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rax,%rdx
call   1070 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1090 <smtp_sendCommand@plt>
cmp    $0xfa,%eax
jne    1226 <smtp_connect+0xb6>
mov    %rsp,%r15
nopl   (%rax)
mov    %rbx,%rdi
call   1040 <sock_dataReady@plt>
test   %eax,%eax
je     1224 <smtp_connect+0xb4>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x201,%edx
mov    %r14,%rcx
call   1050 <sock_readLine@plt>
test   %eax,%eax
js     1226 <smtp_connect+0xb6>
mov    %r15,%rdi
call   1030 <smtp_errorCode@plt>
cmp    $0xfa,%eax
je     11f0 <smtp_connect+0x80>
jmp    1226 <smtp_connect+0xb6>
xor    %eax,%eax
add    $0x210,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"HELO %s\0D\0A\00"
define i32 @smtp_connect(i64 %0, i64 %1, i16 zeroext %2, i64 %3) {
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
%8 = alloca i16
%9 = alloca i64
%10 = alloca [513 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i64 %0, i64* %6
store i64 %1, i64* %7
store i16 %2, i16* %8
store i64 %3, i64* %9
%14 = load i64, i64* %6
%15 = load i64, i64* %7
%16 = load i16, i16* %8
%17 = call i32 @sock_connect(i64 %14, i64 %15, i16 zeroext %16)
store i32 %17, i32* %12
%18 = load i32, i32* %12
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %4
%21 = load i32, i32* %12
store i32 %21, i32* %5
br label %73
22: ; preds = %4
%23 = load i64, i64* %6
%24 = getelementptr inbounds [513 x i8], [513 x i8]* %10, i64 0, i64 0
%25 = load i64, i64* %9
%26 = call i32 @sock_readLine(i64 %23, i8* %24, i32 513, i64 %25)
store i32 %26, i32* %12
%27 = load i32, i32* %12
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %22
%30 = load i32, i32* %12
store i32 %30, i32* %5
br label %73
31: ; preds = %22
%32 = getelementptr inbounds [513 x i8], [513 x i8]* %10, i64 0, i64 0
%33 = call i32 @smtp_errorCode(i8* %32)
store i32 %33, i32* %11
%34 = load i32, i32* %11
%35 = icmp ne i32 %34, 220
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = load i32, i32* %11
store i32 %37, i32* %5
br label %73
38: ; preds = %31
%39 = getelementptr inbounds [513 x i8], [513 x i8]* %10, i64 0, i64 0
%40 = call i8* (...) @sock_getHostName()
%41 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %40)
%42 = load i64, i64* %6
%43 = getelementptr inbounds [513 x i8], [513 x i8]* %10, i64 0, i64 0
%44 = load i64, i64* %9
%45 = call i32 @smtp_sendCommand(i64 %42, i8* %43, i64 %44)
store i32 %45, i32* %12
%46 = load i32, i32* %12
%47 = icmp ne i32 %46, 250
br i1 %47, label %48, label %50
48: ; preds = %38
%49 = load i32, i32* %12
store i32 %49, i32* %5
br label %73
50: ; preds = %38
br label %51
51: ; preds = %71, %50
%52 = load i64, i64* %6
%53 = call i32 @sock_dataReady(i64 %52)
store i32 %53, i32* %13
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %72
55: ; preds = %51
%56 = load i64, i64* %6
%57 = getelementptr inbounds [513 x i8], [513 x i8]* %10, i64 0, i64 0
%58 = load i64, i64* %9
%59 = call i32 @sock_readLine(i64 %56, i8* %57, i32 513, i64 %58)
store i32 %59, i32* %12
%60 = load i32, i32* %12
%61 = icmp slt i32 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %55
%63 = load i32, i32* %12
store i32 %63, i32* %5
br label %73
64: ; preds = %55
%65 = getelementptr inbounds [513 x i8], [513 x i8]* %10, i64 0, i64 0
%66 = call i32 @smtp_errorCode(i8* %65)
store i32 %66, i32* %12
%67 = load i32, i32* %12
%68 = icmp ne i32 %67, 250
br i1 %68, label %69, label %71
69: ; preds = %64
%70 = load i32, i32* %12
store i32 %70, i32* %5
br label %73
71: ; preds = %64
br label %51
72: ; preds = %51
store i32 0, i32* %5
br label %73
73: ; preds = %72, %69, %62, %48, %36, %29, %20
%74 = load i32, i32* %5
ret i32 %74
}

LLVM IR (-O2):
@.str = [10 x i8] c"HELO %s\0D\0A\00"
define i32 @smtp_connect(i64 %0, i64 %1, i16 zeroext %2, i64 %3) {
%5 = alloca [513 x i8]
%6 = getelementptr inbounds [513 x i8], [513 x i8]* %5, i64 0, i64 0
%7 = tail call i32 @sock_connect(i64 %0, i64 %1, i16 zeroext %2)
%8 = icmp slt i32 %7, 0
br i1 %8, label %29, label %9
9: ; preds = %4
%10 = call i32 @sock_readLine(i64 %0, i8* %6, i32 513, i64 %3)
%11 = icmp slt i32 %10, 0
br i1 %11, label %29, label %12
12: ; preds = %9
%13 = call i32 @smtp_errorCode(i8* %6)
%14 = icmp eq i32 %13, 220
br i1 %14, label %15, label %29
15: ; preds = %12
%16 = call i8* (...) @sock_getHostName()
%17 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @smtp_sendCommand(i64 %0, i8* %6, i64 %3)
%19 = icmp eq i32 %18, 250
br i1 %19, label %20, label %29
20: ; preds = %15, %26
%21 = call i32 @sock_dataReady(i64 %0)
%22 = icmp eq i32 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %20
%24 = call i32 @sock_readLine(i64 %0, i8* %6, i32 513, i64 %3)
%25 = icmp slt i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = call i32 @smtp_errorCode(i8* %6)
%28 = icmp eq i32 %27, 250
br i1 %28, label %20, label %29
29: ; preds = %20, %26, %23, %15, %12, %9, %4
%30 = phi i32 [ %7, %4 ], [ %10, %9 ], [ %13, %12 ], [ %18, %15 ], [ 0, %20 ], [ %27, %26 ], [ %24, %23 ]
ret i32 %30
}