#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 */
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
int smtp_readline(int, char *, int);
int smtp_recv_mail_data(int, char **, size_t *);
int /*<<< orphan*/ smtp_send_reply(int, int, int /*<<< orphan*/ *,
                                   int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
size_t strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ writen(int, char *, size_t);
void service(int sockfd) {
  ssize_t n;
  size_t len, data_size;
  char line[100];
  char *data;
  smtp_send_reply(sockfd, 1, NULL, 0);
  for (;;) {
    if ((n = smtp_readline(sockfd, line, 100)) == 0)
      return;
    printf("C: |%s|\n", line);
    fgets(line, 100, stdin);
    len = strlen(line);
    line[len - 1] = '\0';
    len--;
    printf("R: |%s|\n", line);
    line[len++] = '\r';
    line[len++] = '\n';
    line[len++] = '\0';
    writen(sockfd, line, len - 1);
    if (0 == strncmp(line, "354", 3)) {
      printf("Mail data recv:\n");
      n = smtp_recv_mail_data(sockfd, &data, &data_size);
      data[n + 1] = '\0';
      printf("%s", data);
      printf("END OF MAIL\n");
      smtp_send_reply(sockfd, 3, NULL, 0);
      printf("R: |250 OK|\n");
      free(data);
    }
  }
}


x86 assembly (clang, -O0):
<service>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <smtp_send_reply@plt>
mov    -0x4(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
call   1060 <smtp_readline@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jne    11d7 <service+0x47>
add    $0x90,%rsp
pop    %rbp
ret
lea    -0x80(%rbp),%rsi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2df4(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1080 <fgets@plt>
lea    -0x80(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
movb   $0x0,-0x80(%rbp,%rax,1)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
lea    -0x80(%rbp),%rsi
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0xd,-0x80(%rbp,%rax,1)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0xa,-0x80(%rbp,%rax,1)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,-0x80(%rbp,%rax,1)
mov    -0x4(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    -0x10(%rbp),%rdx
sub    $0x1,%rdx
call   10b0 <writen@plt>
lea    -0x80(%rbp),%rdi
lea    0xd7f(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1333 <service+0x1a3>
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x88(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   10a0 <smtp_recv_mail_data@plt>
mov    %eax,-0x8(%rbp)
mov    -0x88(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x88(%rbp),%rsi
lea    0xd36(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xd2b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x4(%rbp),%edi
mov    $0x3,%esi
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <smtp_send_reply@plt>
lea    0xd17(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x88(%rbp),%rdi
call   1030 <free@plt>
jmp    11b1 <service+0x21>

x86 assembly (clang, -O2):
<service>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %edi,%ebp
mov    $0x1,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   10a0 <smtp_send_reply@plt>
lea    0x10(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1070 <smtp_readline@plt>
test   %eax,%eax
je     12fb <service+0x15b>
mov    0x2e07(%rip),%r14
lea    0xe21(%rip),%r15
lea    0xe23(%rip),%r12
jmp    1217 <service+0x77>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1070 <smtp_readline@plt>
test   %eax,%eax
je     12fb <service+0x15b>
lea    0xde2(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1090 <fgets@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %rax,%r13
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
movw   $0xa0d,-0x1(%r13,%rbx,1)
0a
movb   $0x0,0x11(%rsp,%r13,1)
add    $0x1,%r13
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r13,%rdx
call   10c0 <writen@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1200 <service+0x60>
lea    0xd85(%rip),%rdi
call   1050 <puts@plt>
mov    %ebp,%edi
mov    %rsp,%rsi
lea    0x8(%rsp),%rdx
call   10b0 <smtp_recv_mail_data@plt>
mov    (%rsp),%rcx
cltq
movb   $0x0,0x1(%rax,%rcx,1)
mov    (%rsp),%rsi
lea    0xd58(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xd5d(%rip),%rdi
call   1050 <puts@plt>
mov    %ebp,%edi
mov    $0x3,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   10a0 <smtp_send_reply@plt>
lea    0xd4d(%rip),%rdi
call   1050 <puts@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
jmp    1200 <service+0x60>
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"C: |%s|\0A\00"
@stdin = global i32 0
@.str.1 = [9 x i8] c"R: |%s|\0A\00"
@.str.2 = [4 x i8] c"354\00"
@.str.3 = [17 x i8] c"Mail data recv:\0A\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [13 x i8] c"END OF MAIL\0A\00"
@.str.6 = [13 x i8] c"R: |250 OK|\0A\00"
define void @service(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca [100 x i8]
%7 = alloca i8*
store i32 %0, i32* %2
%8 = load i32, i32* %2
%9 = call i32 @smtp_send_reply(i32 %8, i32 1, i32* null, i32 0)
br label %10
10: ; preds = %65, %1
%11 = load i32, i32* %2
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%13 = call i32 @smtp_readline(i32 %11, i8* %12, i32 100)
store i32 %13, i32* %3
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %10
ret void
16: ; preds = %10
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%20 = load i32, i32* @stdin
%21 = call i32 @fgets(i8* %19, i32 100, i32 %20)
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%23 = call i64 @strlen(i8* %22)
store i64 %23, i64* %4
%24 = load i64, i64* %4
%25 = sub i64 %24, 1
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %25
store i8 0, i8* %26
%27 = load i64, i64* %4
%28 = add i64 %27, -1
store i64 %28, i64* %4
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = load i64, i64* %4
%32 = add i64 %31, 1
store i64 %32, i64* %4
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %31
store i8 13, i8* %33
%34 = load i64, i64* %4
%35 = add i64 %34, 1
store i64 %35, i64* %4
%36 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %34
store i8 10, i8* %36
%37 = load i64, i64* %4
%38 = add i64 %37, 1
store i64 %38, i64* %4
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %37
store i8 0, i8* %39
%40 = load i32, i32* %2
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%42 = load i64, i64* %4
%43 = sub i64 %42, 1
%44 = call i32 @writen(i32 %40, i8* %41, i64 %43)
%45 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%46 = call i64 @strncmp(i8* %45, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%47 = icmp eq i64 0, %46
br i1 %47, label %48, label %65
48: ; preds = %16
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%50 = load i32, i32* %2
%51 = call i32 @smtp_recv_mail_data(i32 %50, i8** %7, i64* %5)
store i32 %51, i32* %3
%52 = load i8*, i8** %7
%53 = load i32, i32* %3
%54 = add nsw i32 %53, 1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %52, i64 %55
store i8 0, i8* %56
%57 = load i8*, i8** %7
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %57)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%60 = load i32, i32* %2
%61 = call i32 @smtp_send_reply(i32 %60, i32 3, i32* null, i32 0)
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%63 = load i8*, i8** %7
%64 = call i32 @free(i8* %63)
br label %65
65: ; preds = %48, %16
br label %10
}

LLVM IR (-O2):
@.str = [9 x i8] c"C: |%s|\0A\00"
@stdin = global i32 0
@.str.1 = [9 x i8] c"R: |%s|\0A\00"
@.str.2 = [4 x i8] c"354\00"
@.str.4 = [3 x i8] c"%s\00"
@str = [16 x i8] c"Mail data recv:\00"
@str.7 = [12 x i8] c"END OF MAIL\00"
@str.8 = [12 x i8] c"R: |250 OK|\00"
define void @service(i32 %0) {
%2 = alloca i64
%3 = alloca [100 x i8]
%4 = alloca i8*
%5 = bitcast i64* %2 to i8*
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = bitcast i8** %4 to i8*
%8 = tail call i32 @smtp_send_reply(i32 %0, i32 1, i32* null, i32 0)
%9 = call i32 @smtp_readline(i32 %0, i8* %6, i32 100)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %40, %1
ret void
12: ; preds = %1, %40
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %6)
%14 = load i32, i32* @stdin
%15 = call i32 @fgets(i8* %6, i32 100, i32 %14)
%16 = call i64 @strlen(i8* %6)
%17 = add i64 %16, -1
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %17
store i8 0, i8* %18
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %6)
store i8 13, i8* %18
%20 = add i64 %16, 1
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %16
store i8 10, i8* %21
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %20
store i8 0, i8* %22
%23 = call i32 @writen(i32 %0, i8* %6, i64 %20)
%24 = call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %40
26: ; preds = %12
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%28 = call i32 @smtp_recv_mail_data(i32 %0, i8** %4, i64* %2)
%29 = load i8*, i8** %4
%30 = add nsw i32 %28, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 0, i8* %32
%33 = load i8*, i8** %4
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %33)
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.7, i64 0, i64 0))
%36 = call i32 @smtp_send_reply(i32 %0, i32 3, i32* null, i32 0)
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.8, i64 0, i64 0))
%38 = load i8*, i8** %4
%39 = call i32 @free(i8* %38)
br label %40
40: ; preds = %26, %12
%41 = call i32 @smtp_readline(i32 %0, i8* %6, i32 100)
%42 = icmp eq i32 %41, 0
br i1 %42, label %11, label %12
}