#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 */
scalar_t__ strcmp(char *, char *);
int write(int, char *, int);
int ismtp_write_data(int fd, char *p) {
  int eom = 0;
  if (strcmp(p, "\n.\n") == 0) {
    eom = 1;
  }
  while (*p) {
    if (p[0] == '\r') {
      p++;
      continue;
    }
    if (p[0] == '\n') {
      if (write(fd, "\r", 1) != 1)
        return 0;
    }
    if (write(fd, p, 1) != 1)
      return 0;
    if (!eom && p[0] == '\n' && p[1] == '.') {
      if (write(fd, ".", 1) != 1)
        return 0;
    }
    p++;
  }
  return 1;
}


x86 assembly (clang, -O0):
<ismtp_write_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xebf(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1157 <ismtp_write_data+0x37>
movl   $0x1,-0x14(%rbp)
jmp    115c <ismtp_write_data+0x3c>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1258 <ismtp_write_data+0x138>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
jne    118a <ismtp_write_data+0x6a>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    115c <ismtp_write_data+0x3c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    11c8 <ismtp_write_data+0xa8>
mov    -0x8(%rbp),%edi
lea    0xe60(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     11c3 <ismtp_write_data+0xa3>
movl   $0x0,-0x4(%rbp)
jmp    125f <ismtp_write_data+0x13f>
jmp    11c8 <ismtp_write_data+0xa8>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     11ee <ismtp_write_data+0xce>
movl   $0x0,-0x4(%rbp)
jmp    125f <ismtp_write_data+0x13f>
cmpl   $0x0,-0x14(%rbp)
jne    1247 <ismtp_write_data+0x127>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1247 <ismtp_write_data+0x127>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2e,%eax
jne    1247 <ismtp_write_data+0x127>
mov    -0x8(%rbp),%edi
lea    0xde3(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     1242 <ismtp_write_data+0x122>
movl   $0x0,-0x4(%rbp)
jmp    125f <ismtp_write_data+0x13f>
jmp    1247 <ismtp_write_data+0x127>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    115c <ismtp_write_data+0x3c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ismtp_write_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%r13d
lea    0xec8(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
mov    %rax,%r14
lea    0xeba(%rip),%r15
lea    0xeb5(%rip),%r12
xor    %ebp,%ebp
jmp    1164 <ismtp_write_data+0x44>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0xa,%al
je     1180 <ismtp_write_data+0x60>
cmp    $0xd,%al
je     1160 <ismtp_write_data+0x40>
test   %al,%al
jne    1195 <ismtp_write_data+0x75>
jmp    11d1 <ismtp_write_data+0xb1>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13d,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jne    11d8 <ismtp_write_data+0xb8>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jne    11da <ismtp_write_data+0xba>
test   %r14,%r14
je     1160 <ismtp_write_data+0x40>
cmpb   $0xa,(%rbx)
jne    1160 <ismtp_write_data+0x40>
cmpb   $0x2e,0x1(%rbx)
jne    1160 <ismtp_write_data+0x40>
mov    %r13d,%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     1160 <ismtp_write_data+0x40>
jmp    11da <ismtp_write_data+0xba>
mov    $0x1,%ebp
jmp    11da <ismtp_write_data+0xba>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"\0A.\0A\00"
@.str.1 = [2 x i8] c"\0D\00"
@.str.2 = [2 x i8] c".\00"
define i32 @ismtp_write_data(i32 %0, i8* %1) {
%3 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br label %5
5: ; preds = %8, %2
%6 = phi i8* [ %1, %2 ], [ %9, %8 ]
%7 = load i8, i8* %6
switch i8 %7, label %13 [
i8 0, label %27
i8 13, label %8
i8 10, label %10
]
8: ; preds = %16, %17, %20, %24, %5
%9 = getelementptr inbounds i8, i8* %6, i64 1
br label %5
10: ; preds = %5
%11 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %27
13: ; preds = %5, %10
%14 = tail call i32 @write(i32 %0, i8* %6, i32 1)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %27
16: ; preds = %13
br i1 %4, label %8, label %17
17: ; preds = %16
%18 = load i8, i8* %6
%19 = icmp eq i8 %18, 10
br i1 %19, label %20, label %8
20: ; preds = %17
%21 = getelementptr inbounds i8, i8* %6, i64 1
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 46
br i1 %23, label %24, label %8
24: ; preds = %20
%25 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%26 = icmp eq i32 %25, 1
br i1 %26, label %8, label %27
27: ; preds = %5, %24, %13, %10
%28 = phi i32 [ 0, %10 ], [ 0, %13 ], [ 0, %24 ], [ 1, %5 ]
ret i32 %28
}