#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 */
char *strchr(char const *, char);
int /*<<< orphan*/ strncasecmp(char *, char const *, int);
int message_quote(char const *inbuf, char *outbuf) {
  char const *s = inbuf;
  char *p = outbuf;
  p[0] = 0;
  if (!strncasecmp("subject:", inbuf, 8)) {
    s = strchr(s, '\n');
    if (!s)
      return 0;
    s++;
    if (*s == '\n')
      s++;
  }
  while (1) {
    if (!*s)
      break;
    *p++ = '>';
    *p++ = ' ';
    while (*s && *s != '\n')
      *p++ = *s++;
    if (!*s)
      break;
    *p++ = *s++;
  }
  *p = 0;
  return p - inbuf;
}


x86 assembly (clang, -O0):
<message_quote>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rsi
lea    0xeae(%rip),%rdi
mov    $0x8,%edx
call   1040 <strncasecmp@plt>
cmp    $0x0,%eax
jne    11bb <message_quote+0x9b>
mov    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118e <message_quote+0x6e>
movl   $0x0,-0x4(%rbp)
jmp    12a0 <message_quote+0x180>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    11b6 <message_quote+0x96>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11bb <message_quote+0x9b>
jmp    11c0 <message_quote+0xa0>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11d2 <message_quote+0xb2>
jmp    128b <message_quote+0x16b>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x3e,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x20,(%rax)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
je     121b <message_quote+0xfb>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    122b <message_quote+0x10b>
jmp    1252 <message_quote+0x132>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
jmp    11f6 <message_quote+0xd6>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1264 <message_quote+0x144>
jmp    128b <message_quote+0x16b>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
jmp    11c0 <message_quote+0xa0>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<message_quote>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
movb   $0x0,(%rsi)
lea    0xecc(%rip),%rdi
mov    %r14,%rsi
mov    $0x8,%edx
call   1040 <strncasecmp@plt>
mov    %r14,%rcx
test   %eax,%eax
je     114f <message_quote+0x2f>
cmpb   $0x0,(%rcx)
jne    1180 <message_quote+0x60>
jmp    11c3 <message_quote+0xa3>
mov    %r14,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11d3 <message_quote+0xb3>
lea    0x1(%rax),%rdx
mov    %rax,%rcx
add    $0x2,%rcx
cmpb   $0xa,0x1(%rax)
cmovne %rdx,%rcx
cmpb   $0x0,(%rcx)
je     11c3 <message_quote+0xa3>
nopl   0x0(%rax)
movw   $0x203e,(%rbx)
add    $0x2,%rbx
add    $0x1,%rcx
mov    %rbx,%rax
movzbl -0x1(%rcx),%edx
test   %dl,%dl
je     11c0 <message_quote+0xa0>
cmp    $0xa,%dl
je     11b0 <message_quote+0x90>
mov    %dl,(%rax)
add    $0x1,%rax
add    $0x1,%rcx
jmp    1190 <message_quote+0x70>
nopl   0x0(%rax)
lea    0x1(%rax),%rbx
movb   $0xa,(%rax)
cmpb   $0x0,(%rcx)
jne    1180 <message_quote+0x60>
add    $0x1,%rax
mov    %rax,%rbx
movb   $0x0,(%rbx)
sub    %r14d,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %ebx,%ebx
jmp    11c9 <message_quote+0xa9>

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

LLVM IR (-O2):
@.str = [9 x i8] c"subject:\00"
define i32 @message_quote(i8* %0, i8* %1) {
store i8 0, i8* %1
%3 = tail call i32 @strncasecmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0, i32 8)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %14
5: ; preds = %2
%6 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 10)
%7 = icmp eq i8* %6, null
br i1 %7, label %41, label %8
8: ; preds = %5
%9 = getelementptr inbounds i8, i8* %6, i64 1
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 10
%12 = getelementptr inbounds i8, i8* %6, i64 2
%13 = select i1 %11, i8* %12, i8* %9
br label %14
14: ; preds = %8, %2
%15 = phi i8* [ %0, %2 ], [ %13, %8 ]
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %35, label %18
18: ; preds = %14, %30
%19 = phi i8* [ %32, %30 ], [ %1, %14 ]
%20 = phi i8* [ %31, %30 ], [ %15, %14 ]
%21 = getelementptr inbounds i8, i8* %19, i64 1
store i8 62, i8* %19
%22 = getelementptr inbounds i8, i8* %19, i64 2
store i8 32, i8* %21
br label %23
23: ; preds = %27, %18
%24 = phi i8* [ %20, %18 ], [ %28, %27 ]
%25 = phi i8* [ %22, %18 ], [ %29, %27 ]
%26 = load i8, i8* %24
switch i8 %26, label %27 [
i8 0, label %35
i8 10, label %30
]
27: ; preds = %23
%28 = getelementptr inbounds i8, i8* %24, i64 1
%29 = getelementptr inbounds i8, i8* %25, i64 1
store i8 %26, i8* %25
br label %23
30: ; preds = %23
%31 = getelementptr inbounds i8, i8* %24, i64 1
%32 = getelementptr inbounds i8, i8* %25, i64 1
store i8 10, i8* %25
%33 = load i8, i8* %31
%34 = icmp eq i8 %33, 0
br i1 %34, label %35, label %18
35: ; preds = %30, %23, %14
%36 = phi i8* [ %1, %14 ], [ %25, %23 ], [ %32, %30 ]
store i8 0, i8* %36
%37 = ptrtoint i8* %36 to i64
%38 = ptrtoint i8* %0 to i64
%39 = sub i64 %37, %38
%40 = trunc i64 %39 to i32
br label %41
41: ; preds = %5, %35
%42 = phi i32 [ %40, %35 ], [ 0, %5 ]
ret i32 %42
}