#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*/ strcat(char *, char *);
int strlen(char *);
scalar_t__ strncasecmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
void openddr_convert_bb(char *pattern) {
  char *orig = pattern;
  char new[512];
  *new = '\0';
  if (strncasecmp(orig, "blackberry", 10))
    return;
  strcat(new, "blackberry.?");
  orig += 10;
  if (*orig == ' ')
    orig++;
  if (strlen(orig) > 8)
    return;
  strcat(new, orig);
  strcat(new, ".?");
  strncpy(pattern, new, 512 - 1);
  pattern[512 - 1] = '\0';
}


x86 assembly (clang, -O0):
<openddr_convert_bb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movb   $0x0,-0x210(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe97(%rip),%rsi
mov    $0xa,%edx
call   1050 <strncasecmp@plt>
cmp    $0x0,%rax
je     1182 <openddr_convert_bb+0x42>
jmp    1217 <openddr_convert_bb+0xd7>
lea    -0x210(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0xa,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    11bd <openddr_convert_bb+0x7d>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x8,%eax
jle    11d4 <openddr_convert_bb+0x94>
jmp    1217 <openddr_convert_bb+0xd7>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
lea    -0x210(%rbp),%rdi
lea    0xe23(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    -0x210(%rbp),%rsi
mov    $0x1ff,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
movb   $0x0,0x1ff(%rax)
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openddr_convert_bb>:
push   %r15
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rdi,%rbx
movb   $0x0,(%rsp)
lea    0xea6(%rip),%rsi
mov    $0xa,%edx
call   1050 <strncasecmp@plt>
test   %rax,%rax
jne    11c9 <openddr_convert_bb+0x89>
lea    0xe9b(%rip),%rsi
mov    %rsp,%rdi
call   1060 <strcat@plt>
lea    0xa(%rbx),%r14
lea    0xb(%rbx),%rax
cmpb   $0x20,0xa(%rbx)
cmove  %rax,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    $0x8,%eax
jg     11c9 <openddr_convert_bb+0x89>
mov    %rsp,%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
lea    0xe6b(%rip),%rsi
mov    %r15,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x1ff,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x1ff(%rbx)
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"blackberry\00"
@.str.1 = [13 x i8] c"blackberry.?\00"
@.str.2 = [3 x i8] c".?\00"
define void @openddr_convert_bb(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [512 x i8]
store i8* %0, i8** %2
%5 = load i8*, i8** %2
store i8* %5, i8** %3
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
store i8 0, i8* %6
%7 = load i8*, i8** %3
%8 = call i64 @strncasecmp(i8* %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 10)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
br label %39
11: ; preds = %1
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%13 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 10
store i8* %15, i8** %3
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 32
br i1 %19, label %20, label %23
20: ; preds = %11
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %3
br label %23
23: ; preds = %20, %11
%24 = load i8*, i8** %3
%25 = call i32 @strlen(i8* %24)
%26 = icmp sgt i32 %25, 8
br i1 %26, label %27, label %28
27: ; preds = %23
br label %39
28: ; preds = %23
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%30 = load i8*, i8** %3
%31 = call i32 @strcat(i8* %29, i8* %30)
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%33 = call i32 @strcat(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%34 = load i8*, i8** %2
%35 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%36 = call i32 @strncpy(i8* %34, i8* %35, i32 511)
%37 = load i8*, i8** %2
%38 = getelementptr inbounds i8, i8* %37, i64 511
store i8 0, i8* %38
br label %39
39: ; preds = %28, %27, %10
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"blackberry\00"
@.str.1 = [13 x i8] c"blackberry.?\00"
@.str.2 = [3 x i8] c".?\00"
define void @openddr_convert_bb(i8* %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
store i8 0, i8* %3
%4 = tail call i64 @strncasecmp(i8* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 10)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %20
6: ; preds = %1
%7 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%8 = getelementptr inbounds i8, i8* %0, i64 10
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 32
%11 = getelementptr inbounds i8, i8* %0, i64 11
%12 = select i1 %10, i8* %11, i8* %8
%13 = call i32 @strlen(i8* %12)
%14 = icmp sgt i32 %13, 8
br i1 %14, label %20, label %15
15: ; preds = %6
%16 = call i32 @strcat(i8* %3, i8* %12)
%17 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @strncpy(i8* %0, i8* %3, i32 511)
%19 = getelementptr inbounds i8, i8* %0, i64 511
store i8 0, i8* %19
br label %20
20: ; preds = %6, %1, %15
ret void
}