#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 const);
size_t strlen(char const *);
size_t strlensum(char const *, char *, int /*<<< orphan*/ *);
size_t irc_multilinelen(char const *prefix, char const *suffix,
                        char const separator) {
  char const *next;
  size_t newlines;
  size_t prefixnlsum, suffixsum;
  if (prefix == NULL) {
    prefix = "";
  }
  if (suffix == NULL) {
    suffix = "";
  }
  next = suffix;
  for (next = strchr(next, separator), newlines = 0; next != NULL;
       next = strchr(next, separator)) {
    ++newlines;
    ++next;
  }
  prefixnlsum = (newlines + 1) * strlensum(prefix, "\r\n", NULL);
  suffixsum = strlen(suffix) - newlines;
  return (suffixsum + prefixnlsum);
}


x86 assembly (clang, -O0):
<irc_multilinelen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    115b <irc_multilinelen+0x2b>
lea    0xeab(%rip),%rax
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1171 <irc_multilinelen+0x41>
lea    0xe95(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11cb <irc_multilinelen+0x9b>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
jmp    1192 <irc_multilinelen+0x62>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe1e(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <strlensum@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
imul   %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
sub    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<irc_multilinelen>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r12
mov    %rdi,%r15
test   %rsi,%rsi
lea    0xeb8(%rip),%r14
cmove  %r14,%r12
mov    %r12,%rdi
mov    %edx,%esi
call   1040 <strchr@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1187 <irc_multilinelen+0x57>
movsbl %bpl,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbx
add    $0x1,%rax
mov    %rax,%rdi
mov    %ebp,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    1170 <irc_multilinelen+0x40>
test   %r15,%r15
cmovne %r15,%r14
lea    0x1(%rbx),%r15
lea    0xe67(%rip),%rsi
mov    %r14,%rdi
xor    %edx,%edx
call   1050 <strlensum@plt>
mov    %rax,%rbp
imul   %r15,%rbp
mov    %r12,%rdi
call   1030 <strlen@plt>
sub    %rbx,%rax
add    %rbp,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"\0D\0A\00"
define i64 @irc_multilinelen(i8* %0, i8* %1, i8 signext %2) {
%4 = icmp eq i8* %1, null
%5 = select i1 %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %1
%6 = tail call i8* @strchr(i8* dereferenceable(1) %5, i8 signext %2)
%7 = icmp eq i8* %6, null
br i1 %7, label %15, label %8
8: ; preds = %3, %8
%9 = phi i64 [ %11, %8 ], [ 0, %3 ]
%10 = phi i8* [ %13, %8 ], [ %6, %3 ]
%11 = add i64 %9, 1
%12 = getelementptr inbounds i8, i8* %10, i64 1
%13 = tail call i8* @strchr(i8* %12, i8 signext %2)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %8
15: ; preds = %8, %3
%16 = phi i64 [ 0, %3 ], [ %11, %8 ]
%17 = icmp eq i8* %0, null
%18 = select i1 %17, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %0
%19 = add i64 %16, 1
%20 = tail call i64 @strlensum(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* null)
%21 = mul i64 %20, %19
%22 = tail call i64 @strlen(i8* dereferenceable(1) %5)
%23 = sub i64 %22, %16
%24 = add i64 %23, %21
ret i64 %24
}