#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*/ fatal(char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
char *strdup(char *);
char *strstr(char *, char *);
int /*<<< orphan*/ wrap(char *, int);
char *quote_email(char *raw) {
  int i, count;
  char *ret, *raw1;
  char *p;
  raw1 = raw = strdup(raw);
  if (!raw)
    fatal("strdup out of memory in quote_email");
  wrap(raw, 80);
  p = strstr(raw, "\n\n");
  if (p)
    raw = p + 2;
  for (i = count = 0; raw[i]; i++)
    if (raw[i] == '\n')
      count++;
  ret = malloc(i + count * 3 + 10);
  if (!ret)
    fatal("malloc out of memory in quote_email");
  p = ret;
  strcpy(p, "\n> ");
  p += 3;
  while (*raw) {
    if (*raw == '\n') {
      if (raw[1] != '>') {
        strcpy(p, "\n> ");
        p += 3;
      } else {
        strcpy(p, "\n>");
        p += 2;
      }
      raw++;
    } else {
      *p++ = *raw++;
    }
  }
  *p = 0;
  free(raw1);
  return ret;
}


x86 assembly (clang, -O0):
<quote_email>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11a4 <quote_email+0x34>
lea    0xe61(%rip),%rdi
call   1080 <fatal@plt>
mov    -0x8(%rbp),%rdi
mov    $0x50,%esi
call   1040 <wrap@plt>
mov    -0x8(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11dd <quote_email+0x6d>
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     122e <quote_email+0xbe>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    121b <quote_email+0xab>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1220 <quote_email+0xb0>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11eb <quote_email+0x7b>
mov    -0xc(%rbp),%edi
imul   $0x3,-0x10(%rbp),%eax
add    %eax,%edi
add    $0xa,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    125a <quote_email+0xea>
lea    0xdd2(%rip),%rdi
call   1080 <fatal@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xdde(%rip),%rsi
call   1050 <strcpy@plt>
mov    -0x28(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1321 <quote_email+0x1b1>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    12fa <quote_email+0x18a>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x3e,%eax
je     12cd <quote_email+0x15d>
mov    -0x28(%rbp),%rdi
lea    0xd94(%rip),%rsi
call   1050 <strcpy@plt>
mov    -0x28(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x28(%rbp)
jmp    12e9 <quote_email+0x179>
mov    -0x28(%rbp),%rdi
lea    0xd77(%rip),%rsi
call   1050 <strcpy@plt>
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    131c <quote_email+0x1ac>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
jmp    127e <quote_email+0x10e>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quote_email>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
call   1070 <strdup@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1194 <quote_email+0x24>
lea    0xe71(%rip),%rdi
call   1080 <fatal@plt>
mov    %r14,%rdi
mov    $0x50,%esi
call   1040 <wrap@plt>
lea    0xe7c(%rip),%rsi
mov    %r14,%rdi
call   1090 <strstr@plt>
lea    0x2(%rax),%rbp
test   %rax,%rax
cmove  %r14,%rbp
xor    %eax,%eax
xor    %ecx,%ecx
jmp    11d7 <quote_email+0x67>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%ecx
add    $0x1,%rax
movzbl 0x0(%rbp,%rax,1),%edx
cmp    $0xa,%dl
je     11d0 <quote_email+0x60>
test   %dl,%dl
jne    11d3 <quote_email+0x63>
lea    (%rcx,%rcx,2),%ecx
lea    (%rax,%rcx,1),%edi
add    $0xa,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1207 <quote_email+0x97>
lea    0xe25(%rip),%rdi
call   1080 <fatal@plt>
lea    0xe3d(%rip),%r12
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <strcpy@plt>
mov    %r15,%rbx
add    $0x3,%rbx
add    $0x1,%rbp
lea    0xe24(%rip),%r13
jmp    1243 <quote_email+0xd3>
nopl   (%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <strcpy@plt>
add    $0x3,%rbx
add    $0x1,%rbp
movzbl -0x1(%rbp),%eax
cmp    $0xa,%al
je     1260 <quote_email+0xf0>
test   %al,%al
je     127b <quote_email+0x10b>
mov    %al,(%rbx)
add    $0x1,%rbx
add    $0x1,%rbp
jmp    1243 <quote_email+0xd3>
nopl   0x0(%rax,%rax,1)
cmpb   $0x3e,0x0(%rbp)
jne    1230 <quote_email+0xc0>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <strcpy@plt>
add    $0x2,%rbx
add    $0x1,%rbp
jmp    1243 <quote_email+0xd3>
movb   $0x0,(%rbx)
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"strdup out of memory in quote_email\00"
@.str.1 = [3 x i8] c"\0A\0A\00"
@.str.2 = [36 x i8] c"malloc out of memory in quote_email\00"
@.str.3 = [4 x i8] c"\0A> \00"
@.str.4 = [3 x i8] c"\0A>\00"
define i8* @quote_email(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i8* @strdup(i8* %8)
store i8* %9, i8** %2
store i8* %9, i8** %6
%10 = load i8*, i8** %2
%11 = icmp ne i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %1
%13 = call i32 @fatal(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %1
%15 = load i8*, i8** %2
%16 = call i32 @wrap(i8* %15, i32 80)
%17 = load i8*, i8** %2
%18 = call i8* @strstr(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %18, i8** %7
%19 = load i8*, i8** %7
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = load i8*, i8** %7
%23 = getelementptr inbounds i8, i8* %22, i64 2
store i8* %23, i8** %2
br label %24
24: ; preds = %21, %14
store i32 0, i32* %4
store i32 0, i32* %3
br label %25
25: ; preds = %44, %24
%26 = load i8*, i8** %2
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = icmp ne i8 %30, 0
br i1 %31, label %32, label %47
32: ; preds = %25
%33 = load i8*, i8** %2
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 10
br i1 %39, label %40, label %43
40: ; preds = %32
%41 = load i32, i32* %4
%42 = add nsw i32 %41, 1
store i32 %42, i32* %4
br label %43
43: ; preds = %40, %32
br label %44
44: ; preds = %43
%45 = load i32, i32* %3
%46 = add nsw i32 %45, 1
store i32 %46, i32* %3
br label %25
47: ; preds = %25
%48 = load i32, i32* %3
%49 = load i32, i32* %4
%50 = mul nsw i32 %49, 3
%51 = add nsw i32 %48, %50
%52 = add nsw i32 %51, 10
%53 = call i8* @malloc(i32 %52)
store i8* %53, i8** %5
%54 = load i8*, i8** %5
%55 = icmp ne i8* %54, null
br i1 %55, label %58, label %56
56: ; preds = %47
%57 = call i32 @fatal(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %58
58: ; preds = %56, %47
%59 = load i8*, i8** %5
store i8* %59, i8** %7
%60 = load i8*, i8** %7
%61 = call i32 @strcpy(i8* %60, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%62 = load i8*, i8** %7
%63 = getelementptr inbounds i8, i8* %62, i64 3
store i8* %63, i8** %7
br label %64
64: ; preds = %98, %58
%65 = load i8*, i8** %2
%66 = load i8, i8* %65
%67 = icmp ne i8 %66, 0
br i1 %67, label %68, label %99
68: ; preds = %64
%69 = load i8*, i8** %2
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = icmp eq i32 %71, 10
br i1 %72, label %73, label %92
73: ; preds = %68
%74 = load i8*, i8** %2
%75 = getelementptr inbounds i8, i8* %74, i64 1
%76 = load i8, i8* %75
%77 = sext i8 %76 to i32
%78 = icmp ne i32 %77, 62
br i1 %78, label %79, label %84
79: ; preds = %73
%80 = load i8*, i8** %7
%81 = call i32 @strcpy(i8* %80, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%82 = load i8*, i8** %7
%83 = getelementptr inbounds i8, i8* %82, i64 3
store i8* %83, i8** %7
br label %89
84: ; preds = %73
%85 = load i8*, i8** %7
%86 = call i32 @strcpy(i8* %85, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%87 = load i8*, i8** %7
%88 = getelementptr inbounds i8, i8* %87, i64 2
store i8* %88, i8** %7
br label %89
89: ; preds = %84, %79
%90 = load i8*, i8** %2
%91 = getelementptr inbounds i8, i8* %90, i32 1
store i8* %91, i8** %2
br label %98
92: ; preds = %68
%93 = load i8*, i8** %2
%94 = getelementptr inbounds i8, i8* %93, i32 1
store i8* %94, i8** %2
%95 = load i8, i8* %93
%96 = load i8*, i8** %7
%97 = getelementptr inbounds i8, i8* %96, i32 1
store i8* %97, i8** %7
store i8 %95, i8* %96
br label %98
98: ; preds = %92, %89
br label %64
99: ; preds = %64
%100 = load i8*, i8** %7
store i8 0, i8* %100
%101 = load i8*, i8** %6
%102 = call i32 @free(i8* %101)
%103 = load i8*, i8** %5
ret i8* %103
}

LLVM IR (-O2):
@.str = [36 x i8] c"strdup out of memory in quote_email\00"
@.str.1 = [3 x i8] c"\0A\0A\00"
@.str.2 = [36 x i8] c"malloc out of memory in quote_email\00"
@.str.3 = [4 x i8] c"\0A> \00"
@.str.4 = [3 x i8] c"\0A>\00"
define i8* @quote_email(i8* nocapture %0) {
%2 = tail call i8* @strdup(i8* %0)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @fatal(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %1
%7 = tail call i32 @wrap(i8* %2, i32 80)
%8 = tail call i8* @strstr(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i8* %8, null
%10 = getelementptr inbounds i8, i8* %8, i64 2
%11 = select i1 %9, i8* %2, i8* %10
br label %12
12: ; preds = %19, %6
%13 = phi i64 [ %21, %19 ], [ 0, %6 ]
%14 = phi i32 [ %20, %19 ], [ 0, %6 ]
%15 = getelementptr inbounds i8, i8* %11, i64 %13
%16 = load i8, i8* %15
switch i8 %16, label %19 [
i8 0, label %22
i8 10, label %17
]
17: ; preds = %12
%18 = add nsw i32 %14, 1
br label %19
19: ; preds = %12, %17
%20 = phi i32 [ %18, %17 ], [ %14, %12 ]
%21 = add nuw i64 %13, 1
br label %12
22: ; preds = %12
%23 = trunc i64 %13 to i32
%24 = mul nsw i32 %14, 3
%25 = add i32 %24, 10
%26 = add i32 %25, %23
%27 = tail call i8* @malloc(i32 %26)
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %31
29: ; preds = %22
%30 = tail call i32 @fatal(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %29, %22
%32 = tail call i32 @strcpy(i8* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%33 = getelementptr inbounds i8, i8* %27, i64 3
br label %34
34: ; preds = %50, %31
%35 = phi i8* [ %11, %31 ], [ %52, %50 ]
%36 = phi i8* [ %33, %31 ], [ %51, %50 ]
%37 = load i8, i8* %35
switch i8 %37, label %48 [
i8 0, label %53
i8 10, label %38
]
38: ; preds = %34
%39 = getelementptr inbounds i8, i8* %35, i64 1
%40 = load i8, i8* %39
%41 = icmp eq i8 %40, 62
br i1 %41, label %45, label %42
42: ; preds = %38
%43 = tail call i32 @strcpy(i8* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%44 = getelementptr inbounds i8, i8* %36, i64 3
br label %50
45: ; preds = %38
%46 = tail call i32 @strcpy(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%47 = getelementptr inbounds i8, i8* %36, i64 2
br label %50
48: ; preds = %34
%49 = getelementptr inbounds i8, i8* %36, i64 1
store i8 %37, i8* %36
br label %50
50: ; preds = %42, %45, %48
%51 = phi i8* [ %49, %48 ], [ %44, %42 ], [ %47, %45 ]
%52 = getelementptr inbounds i8, i8* %35, i64 1
br label %34
53: ; preds = %34
store i8 0, i8* %36
%54 = tail call i32 @free(i8* %2)
ret i8* %27
}