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

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ smtp_readline(int, char *, int);
int /*<<< orphan*/ stdin;
size_t strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ writen(int, char *, size_t);
void str_cli(int sockfd) {
  ssize_t n;
  size_t len;
  char line[100];
  char mail_data[] =
      "From: Sender <sender@example.org>\r\n"
      "Message-Id: <200908251906.k7GKfq6v011871@tree.slackware.lan>\r\n"
      "Date: Tue, 25 Aug 2009 19:06:38 -0500\r\n"
      "To: Recipient1 <rcpt1@example.org>, Recipient2 <rcpt2@example.org>\r\n"
      "Subject: Register with the Linux counter project\r\n"
      "User-Agent: nail 11.25 7/29/05\r\n"
      "MIME-Version: 1.0\r\n"
      "Content-Type: text/plain; charset=us-ascii\r\n"
      "Content-Transfer-Encoding: 7bit\r\n"
      "\r\n"
      "(Adapted from a question in the Linux-FAQ)\r\n"
      "\r\n"
      "How Many People Use Linux?\r\n"
      "\r\n"
      "Linux is freely available, and no one is required to register with\r\n"
      "any central authority, so it is difficult to know.  Several "
      "businesses\r\n"
      "survive solely on selling and supporting Linux.  Linux newsgroups "
      "are\r\n"
      "some of the most heavily read on Usenet.  Accurate numbers are hard "
      "to\r\n"
      "come by, but the number is almost certainly in the millions.\r\n"
      "\r\n";
  for (;;) {
    if ((n = smtp_readline(sockfd, line, 4096)) == 0) {
      printf("Closed connection!\n");
      return;
    }
    printf("R: |%s|\n", line);
    fgets(line, 100, stdin);
    len = strlen(line);
    line[len - 1] = '\0';
    len--;
    if (0 == strncmp(line, "mdata", 5)) {
      len = strlen(mail_data);
      writen(sockfd, mail_data, len);
      writen(sockfd, ".\r\n", 3);
      printf("Mail data sent!\n");
    } else {
      printf("C: |%s|\n", line);
      line[len++] = '\r';
      line[len++] = '\n';
      line[len++] = '\0';
      writen(sockfd, line, len - 1);
    }
  }
}


x86 assembly (clang, -O0):
<str_cli>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3b0,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x3b0(%rbp),%rdi
lea    0xe74(%rip),%rsi
mov    $0x328,%edx
call   1080 <memcpy@plt>
mov    -0x4(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x1000,%edx
call   1050 <smtp_readline@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jne    11ca <str_cli+0x5a>
lea    0x116e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
add    $0x3b0,%rsp
pop    %rbp
ret
lea    -0x80(%rbp),%rsi
lea    0x1167(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2e01(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1070 <fgets@plt>
lea    -0x80(%rbp),%rdi
call   1040 <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),%rdi
lea    0x1121(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1286 <str_cli+0x116>
lea    -0x3b0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x3b0(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1090 <writen@plt>
mov    -0x4(%rbp),%edi
lea    0x10e2(%rip),%rsi
mov    $0x3,%edx
call   1090 <writen@plt>
lea    0x10d5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12e8 <str_cli+0x178>
lea    -0x80(%rbp),%rsi
lea    0x10cf(%rip),%rdi
mov    $0x0,%al
call   1060 <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   1090 <writen@plt>
jmp    1196 <str_cli+0x26>

x86 assembly (clang, -O2):
<str_cli>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x398,%rsp
mov    %edi,%r14d
lea    0xe65(%rip),%rsi
lea    0x70(%rsp),%rdi
mov    $0x328,%edx
call   1090 <memcpy@plt>
mov    %rsp,%rbx
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1060 <smtp_readline@plt>
test   %eax,%eax
je     12b6 <str_cli+0x136>
lea    0x115c(%rip),%rbp
mov    0x2e15(%rip),%r12
lea    0x1157(%rip),%r15
jmp    1229 <str_cli+0xa9>
nopl   0x0(%rax)
lea    0x1154(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
movw   $0xa0d,-0x1(%rsp,%r13,1)
0a
mov    %r13,%rdx
add    $0x1,%rdx
movb   $0x0,0x1(%rsp,%r13,1)
mov    %r14d,%edi
mov    %rbx,%rsi
call   10a0 <writen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1060 <smtp_readline@plt>
test   %eax,%eax
je     12b6 <str_cli+0x136>
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1080 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rax,%r13
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11e0 <str_cli+0x60>
mov    %rbp,%r13
lea    0x70(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %r13,%rbp
mov    %rax,%rdx
call   10a0 <writen@plt>
mov    $0x3,%edx
mov    %r14d,%edi
lea    0x1097(%rip),%rsi
call   10a0 <writen@plt>
lea    0x1098(%rip),%rdi
call   1040 <puts@plt>
jmp    1211 <str_cli+0x91>
lea    0x1097(%rip),%rdi
call   1040 <puts@plt>
add    $0x398,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.str_cli.mail_data = [808 x i8] c"From: Sender <sender@example.org>\0D\0AMessage-Id: <200908251906.k7GKfq6v011871@tree.slackware.lan>\0D\0ADate: Tue, 25 Aug 2009 19:06:38 -0500\0D\0ATo: Recipient1 <rcpt1@example.org>, Recipient2 <rcpt2@example.org>\0D\0ASubject: Register with the Linux counter project\0D\0AUser-Agent: nail 11.25 7/29/05\0D\0AMIME-Version: 1.0\0D\0AContent-Type: text/plain; charset=us-ascii\0D\0AContent-Transfer-Encoding: 7bit\0D\0A\0D\0A(Adapted from a question in the Linux-FAQ)\0D\0A\0D\0AHow Many People Use Linux?\0D\0A\0D\0ALinux is freely available, and no one is required to register with\0D\0Aany central authority, so it is difficult to know. Several businesses\0D\0Asurvive solely on selling and supporting Linux. Linux newsgroups are\0D\0Asome of the most heavily read on Usenet. Accurate numbers are hard to\0D\0Acome by, but the number is almost certainly in the millions.\0D\0A\0D\0A\00"
@.str = [20 x i8] c"Closed connection!\0A\00"
@.str.1 = [9 x i8] c"R: |%s|\0A\00"
@stdin = global i32 0
@.str.2 = [6 x i8] c"mdata\00"
@.str.3 = [4 x i8] c".\0D\0A\00"
@.str.4 = [17 x i8] c"Mail data sent!\0A\00"
@.str.5 = [9 x i8] c"C: |%s|\0A\00"
define void @str_cli(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca [100 x i8]
%6 = alloca [808 x i8]
store i32 %0, i32* %2
%7 = bitcast [808 x i8]* %6 to i8*
br label %8
8: ; preds = %58, %1
%9 = load i32, i32* %2
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%11 = call i32 @smtp_readline(i32 %9, i8* %10, i32 4096)
store i32 %11, i32* %3
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
ret void
15: ; preds = %8
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%19 = load i32, i32* @stdin
%20 = call i32 @fgets(i8* %18, i32 100, i32 %19)
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%22 = call i64 @strlen(i8* %21)
store i64 %22, i64* %4
%23 = load i64, i64* %4
%24 = sub i64 %23, 1
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %24
store i8 0, i8* %25
%26 = load i64, i64* %4
%27 = add i64 %26, -1
store i64 %27, i64* %4
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%29 = call i64 @strncmp(i8* %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%30 = icmp eq i64 0, %29
br i1 %30, label %31, label %41
31: ; preds = %15
%32 = getelementptr inbounds [808 x i8], [808 x i8]* %6, i64 0, i64 0
%33 = call i64 @strlen(i8* %32)
store i64 %33, i64* %4
%34 = load i32, i32* %2
%35 = getelementptr inbounds [808 x i8], [808 x i8]* %6, i64 0, i64 0
%36 = load i64, i64* %4
%37 = call i32 @writen(i32 %34, i8* %35, i64 %36)
%38 = load i32, i32* %2
%39 = call i32 @writen(i32 %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 3)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %58
41: ; preds = %15
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %42)
%44 = load i64, i64* %4
%45 = add i64 %44, 1
store i64 %45, i64* %4
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %44
store i8 13, i8* %46
%47 = load i64, i64* %4
%48 = add i64 %47, 1
store i64 %48, i64* %4
%49 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %47
store i8 10, i8* %49
%50 = load i64, i64* %4
%51 = add i64 %50, 1
store i64 %51, i64* %4
%52 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %50
store i8 0, i8* %52
%53 = load i32, i32* %2
%54 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%55 = load i64, i64* %4
%56 = sub i64 %55, 1
%57 = call i32 @writen(i32 %53, i8* %54, i64 %56)
br label %58
58: ; preds = %41, %31
br label %8
}

LLVM IR (-O2):
@__const.str_cli.mail_data = [808 x i8] c"From: Sender <sender@example.org>\0D\0AMessage-Id: <200908251906.k7GKfq6v011871@tree.slackware.lan>\0D\0ADate: Tue, 25 Aug 2009 19:06:38 -0500\0D\0ATo: Recipient1 <rcpt1@example.org>, Recipient2 <rcpt2@example.org>\0D\0ASubject: Register with the Linux counter project\0D\0AUser-Agent: nail 11.25 7/29/05\0D\0AMIME-Version: 1.0\0D\0AContent-Type: text/plain; charset=us-ascii\0D\0AContent-Transfer-Encoding: 7bit\0D\0A\0D\0A(Adapted from a question in the Linux-FAQ)\0D\0A\0D\0AHow Many People Use Linux?\0D\0A\0D\0ALinux is freely available, and no one is required to register with\0D\0Aany central authority, so it is difficult to know. Several businesses\0D\0Asurvive solely on selling and supporting Linux. Linux newsgroups are\0D\0Asome of the most heavily read on Usenet. Accurate numbers are hard to\0D\0Acome by, but the number is almost certainly in the millions.\0D\0A\0D\0A\00"
@.str.1 = [9 x i8] c"R: |%s|\0A\00"
@stdin = global i32 0
@.str.2 = [6 x i8] c"mdata\00"
@.str.3 = [4 x i8] c".\0D\0A\00"
@.str.5 = [9 x i8] c"C: |%s|\0A\00"
@str = [16 x i8] c"Mail data sent!\00"
@str.6 = [19 x i8] c"Closed connection!\00"
define void @str_cli(i32 %0) {
%2 = alloca [100 x i8]
%3 = alloca [808 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [808 x i8], [808 x i8]* %3, i64 0, i64 0
%6 = call i32 @smtp_readline(i32 %0, i8* %4, i32 4096)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %30, %1
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.6, i64 0, i64 0))
ret void
10: ; preds = %1, %30
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%12 = load i32, i32* @stdin
%13 = call i32 @fgets(i8* %4, i32 100, i32 %12)
%14 = call i64 @strlen(i8* %4)
%15 = add i64 %14, -1
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %15
store i8 0, i8* %16
%17 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %10
%20 = call i64 @strlen(i8* %5)
%21 = call i32 @writen(i32 %0, i8* %5, i64 %20)
%22 = call i32 @writen(i32 %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 3)
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %30
24: ; preds = %10
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %4)
store i8 13, i8* %16
%26 = add i64 %14, 1
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %14
store i8 10, i8* %27
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %26
store i8 0, i8* %28
%29 = call i32 @writen(i32 %0, i8* %4, i64 %26)
br label %30
30: ; preds = %24, %19
%31 = call i32 @smtp_readline(i32 %0, i8* %4, i32 4096)
%32 = icmp eq i32 %31, 0
br i1 %32, label %8, label %10
}