#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 /*<<< orphan*/ close(int);
int /*<<< orphan*/ ismtp_waitfor(int, char);
int /*<<< orphan*/ smtp_write(int, char *);
int ismtp_end_mail(int fd) {
  smtp_write(fd, "\n.\n");
  if (!ismtp_waitfor(fd, '2')) {
    close(fd);
    return -1;
  }
  smtp_write(fd, "QUIT\n");
  if (!ismtp_waitfor(fd, '2')) {
    close(fd);
    return -1;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<ismtp_end_mail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    0xebb(%rip),%rsi
call   1030 <smtp_write@plt>
mov    -0x8(%rbp),%edi
mov    $0x32,%esi
call   1050 <ismtp_waitfor@plt>
cmp    $0x0,%eax
jne    1174 <ismtp_end_mail+0x44>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bc <ismtp_end_mail+0x8c>
mov    -0x8(%rbp),%edi
lea    0xe86(%rip),%rsi
call   1030 <smtp_write@plt>
mov    -0x8(%rbp),%edi
mov    $0x32,%esi
call   1050 <ismtp_waitfor@plt>
cmp    $0x0,%eax
jne    11ad <ismtp_end_mail+0x7d>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bc <ismtp_end_mail+0x8c>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ismtp_end_mail>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0xec4(%rip),%rsi
call   1030 <smtp_write@plt>
mov    %ebx,%edi
mov    $0x32,%esi
call   1050 <ismtp_waitfor@plt>
test   %eax,%eax
je     117b <ismtp_end_mail+0x4b>
lea    0xeac(%rip),%rsi
mov    %ebx,%edi
call   1030 <smtp_write@plt>
mov    %ebx,%edi
mov    $0x32,%esi
call   1050 <ismtp_waitfor@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1040 <close@plt>
cmp    $0x1,%ebp
sbb    %eax,%eax
jmp    1187 <ismtp_end_mail+0x57>
mov    %ebx,%edi
call   1040 <close@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"\0A.\0A\00"
@.str.1 = [6 x i8] c"QUIT\0A\00"
define i32 @ismtp_end_mail(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = call i32 @smtp_write(i32 %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* %3
%7 = call i32 @ismtp_waitfor(i32 %6, i8 signext 50)
%8 = icmp ne i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = load i32, i32* %3
%11 = call i32 @close(i32 %10)
store i32 -1, i32* %2
br label %24
12: ; preds = %1
%13 = load i32, i32* %3
%14 = call i32 @smtp_write(i32 %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* %3
%16 = call i32 @ismtp_waitfor(i32 %15, i8 signext 50)
%17 = icmp ne i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %12
%19 = load i32, i32* %3
%20 = call i32 @close(i32 %19)
store i32 -1, i32* %2
br label %24
21: ; preds = %12
%22 = load i32, i32* %3
%23 = call i32 @close(i32 %22)
store i32 0, i32* %2
br label %24
24: ; preds = %21, %18, %9
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@.str = [4 x i8] c"\0A.\0A\00"
@.str.1 = [6 x i8] c"QUIT\0A\00"
define i32 @ismtp_end_mail(i32 %0) {
%2 = tail call i32 @smtp_write(i32 %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @ismtp_waitfor(i32 %0, i8 signext 50)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @close(i32 %0)
br label %13
7: ; preds = %1
%8 = tail call i32 @smtp_write(i32 %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @ismtp_waitfor(i32 %0, i8 signext 50)
%10 = icmp eq i32 %9, 0
%11 = tail call i32 @close(i32 %0)
%12 = sext i1 %10 to i32
br label %13
13: ; preds = %7, %5
%14 = phi i32 [ -1, %5 ], [ %12, %7 ]
ret i32 %14
}