#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*/ strcpy(char *, char *);
int strlen(char *);
char *strstr(char *, char *);
int processLine(char *org, char *dst, char *pattern) {
  int i = 0;
  char *p = NULL;
  for (i = 0; i < strlen(org); i++) {
    if (org[i] == 0x0D || org[i] == 0x0A) {
      org[i] = 0;
      break;
    }
  }
  if ((p = strstr(org, pattern)) != NULL) {
    strcpy(dst, p + strlen(pattern));
    return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<processLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jge    11c4 <processLine+0x94>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
je     11a0 <processLine+0x70>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11b1 <processLine+0x81>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11c4 <processLine+0x94>
jmp    11b6 <processLine+0x86>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115a <processLine+0x2a>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1216 <processLine+0xe6>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rdi
cltq
add    %rax,%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x4(%rbp)
jmp    121d <processLine+0xed>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<processLine>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
call   1040 <strlen@plt>
test   %eax,%eax
jle    1177 <processLine+0x47>
xor    %ebx,%ebx
nopl   0x0(%rax)
movzbl (%r12,%rbx,1),%eax
cmp    $0xd,%al
je     1172 <processLine+0x42>
cmp    $0xa,%al
je     1172 <processLine+0x42>
add    $0x1,%rbx
mov    %r12,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1150 <processLine+0x20>
jmp    1177 <processLine+0x47>
movb   $0x0,(%r12,%rbx,1)
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     11a9 <processLine+0x79>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    $0x1,%eax
jmp    11ab <processLine+0x7b>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @processLine(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 0, i32* %8
store i8* null, i8** %9
store i32 0, i32* %8
br label %10
10: ; preds = %37, %3
%11 = load i32, i32* %8
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %40
15: ; preds = %10
%16 = load i8*, i8** %5
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 13
br i1 %22, label %31, label %23
23: ; preds = %15
%24 = load i8*, i8** %5
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 10
br i1 %30, label %31, label %36
31: ; preds = %23, %15
%32 = load i8*, i8** %5
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 0, i8* %35
br label %40
36: ; preds = %23
br label %37
37: ; preds = %36
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
br label %10
40: ; preds = %31, %10
%41 = load i8*, i8** %5
%42 = load i8*, i8** %7
%43 = call i8* @strstr(i8* %41, i8* %42)
store i8* %43, i8** %9
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %53
45: ; preds = %40
%46 = load i8*, i8** %6
%47 = load i8*, i8** %9
%48 = load i8*, i8** %7
%49 = call i32 @strlen(i8* %48)
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %47, i64 %50
%52 = call i32 @strcpy(i8* %46, i8* %51)
store i32 1, i32* %4
br label %54
53: ; preds = %40
store i32 0, i32* %4
br label %54
54: ; preds = %53, %45
%55 = load i32, i32* %4
ret i32 %55
}

LLVM IR (-O2):
define i32 @processLine(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %18
6: ; preds = %3, %13
%7 = phi i64 [ %14, %13 ], [ 0, %3 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
switch i8 %9, label %13 [
i8 13, label %10
i8 10, label %10
]
10: ; preds = %6, %6
%11 = and i64 %7, 4294967295
%12 = getelementptr inbounds i8, i8* %0, i64 %11
store i8 0, i8* %12
br label %18
13: ; preds = %6
%14 = add nuw nsw i64 %7, 1
%15 = tail call i32 @strlen(i8* %0)
%16 = sext i32 %15 to i64
%17 = icmp slt i64 %14, %16
br i1 %17, label %6, label %18
18: ; preds = %13, %3, %10
%19 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %2)
%20 = icmp eq i8* %19, null
br i1 %20, label %26, label %21
21: ; preds = %18
%22 = tail call i32 @strlen(i8* %2)
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %19, i64 %23
%25 = tail call i32 @strcpy(i8* %1, i8* %24)
br label %26
26: ; preds = %18, %21
%27 = phi i32 [ 1, %21 ], [ 0, %18 ]
ret i32 %27
}