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


x86 assembly (clang, -O0):
<message_quoted_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xeaa(%rip),%rdi
mov    $0x8,%edx
call   1050 <strncasecmp@plt>
cmp    $0x0,%eax
jne    11bb <message_quoted_size+0x8b>
mov    -0x18(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1192 <message_quoted_size+0x62>
movl   $0x0,-0x4(%rbp)
jmp    1213 <message_quoted_size+0xe3>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0xa,%eax
jne    11af <message_quoted_size+0x7f>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11c0 <message_quoted_size+0x90>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11eb <message_quoted_size+0xbb>
jmp    11fc <message_quoted_size+0xcc>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11c0 <message_quoted_size+0x90>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<message_quoted_size>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xec3(%rip),%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1050 <strncasecmp@plt>
mov    %rbx,%rdi
test   %eax,%eax
jne    1173 <message_quoted_size+0x43>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11a7 <message_quoted_size+0x77>
cmpb   $0xa,0x1(%rax)
lea    0x1(%rax),%rdi
cmovne %rax,%rdi
add    $0x1,%rdi
mov    $0x1,%ebp
nopl   0x0(%rax,%rax,1)
mov    $0xa,%esi
call   1040 <strchr@plt>
lea    0x1(%rax),%rdi
add    $0x2,%ebp
test   %rax,%rax
jne    1180 <message_quoted_size+0x50>
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %eax,%eax
jmp    11a0 <message_quoted_size+0x70>

LLVM IR (-O0):
@.str = [9 x i8] c"subject:\00"
define i32 @message_quoted_size(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
store i8* %6, i8** %4
store i32 0, i32* %5
%7 = load i8*, i8** %3
%8 = call i32 @strncasecmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %7, i32 8)
%9 = icmp ne i32 %8, 0
br i1 %9, label %28, label %10
10: ; preds = %1
%11 = load i8*, i8** %4
%12 = call i8* @strchr(i8* %11, i8 signext 10)
store i8* %12, i8** %4
%13 = load i8*, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %10
store i32 0, i32* %2
br label %47
16: ; preds = %10
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 10
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %4
br label %25
25: ; preds = %22, %16
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %4
br label %28
28: ; preds = %25, %1
br label %29
29: ; preds = %28, %37
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
%32 = load i8*, i8** %4
%33 = call i8* @strchr(i8* %32, i8 signext 10)
store i8* %33, i8** %4
%34 = load i8*, i8** %4
%35 = icmp ne i8* %34, null
br i1 %35, label %37, label %36
36: ; preds = %29
br label %40
37: ; preds = %29
%38 = load i8*, i8** %4
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %4
br label %29
40: ; preds = %36
%41 = load i8*, i8** %3
%42 = call i32 @strlen(i8* %41)
%43 = load i32, i32* %5
%44 = mul nsw i32 %43, 2
%45 = add nsw i32 %42, %44
%46 = add nsw i32 %45, 1
store i32 %46, i32* %2
br label %47
47: ; preds = %40, %15
%48 = load i32, i32* %2
ret i32 %48
}

LLVM IR (-O2):
@.str = [9 x i8] c"subject:\00"
define i32 @message_quoted_size(i8* %0) {
%2 = tail call i32 @strncasecmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0, i32 8)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %13
4: ; preds = %1
%5 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 10)
%6 = icmp eq i8* %5, null
br i1 %6, label %27, label %7
7: ; preds = %4
%8 = getelementptr inbounds i8, i8* %5, i64 1
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 10
%11 = select i1 %10, i8* %8, i8* %5
%12 = getelementptr inbounds i8, i8* %11, i64 1
br label %13
13: ; preds = %7, %1
%14 = phi i8* [ %12, %7 ], [ %0, %1 ]
br label %15
15: ; preds = %13, %15
%16 = phi i8* [ %21, %15 ], [ %14, %13 ]
%17 = phi i32 [ %18, %15 ], [ 0, %13 ]
%18 = add nuw nsw i32 %17, 1
%19 = tail call i8* @strchr(i8* dereferenceable(1) %16, i8 signext 10)
%20 = icmp eq i8* %19, null
%21 = getelementptr inbounds i8, i8* %19, i64 1
br i1 %20, label %22, label %15
22: ; preds = %15
%23 = tail call i32 @strlen(i8* %0)
%24 = shl nuw nsw i32 %18, 1
%25 = or i32 %24, 1
%26 = add i32 %25, %23
br label %27
27: ; preds = %4, %22
%28 = phi i32 [ %26, %22 ], [ 0, %4 ]
ret i32 %28
}