#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 */
scalar_t__ strcasecmp(char *, char *);
int strlen(char *);
int check_readonly_mode(char *prog) {
  char *tmp = prog + strlen(prog) - strlen("swish-search");
  if (tmp < prog)
    return 0;
  if (strcasecmp(tmp, "swish-search") == 0)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<check_readonly_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
lea    0xeac(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rdx
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1188 <check_readonly_mode+0x68>
movl   $0x0,-0x4(%rbp)
jmp    11b5 <check_readonly_mode+0x95>
mov    -0x18(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11ae <check_readonly_mode+0x8e>
movl   $0x1,-0x4(%rbp)
jmp    11b5 <check_readonly_mode+0x95>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_readonly_mode>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
movslq %eax,%rbx
add    %r14,%rbx
lea    0xec7(%rip),%rdi
call   1040 <strlen@plt>
cltq
sub    %rax,%rbx
xor    %eax,%eax
cmp    %r14,%rbx
jb     1164 <check_readonly_mode+0x44>
lea    0xeaf(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"swish-search\00"
define i32 @check_readonly_mode(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %5, i64 %8
%10 = call i32 @strlen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%11 = sext i32 %10 to i64
%12 = sub i64 0, %11
%13 = getelementptr inbounds i8, i8* %9, i64 %12
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = load i8*, i8** %3
%16 = icmp ult i8* %14, %15
br i1 %16, label %17, label %18
17: ; preds = %1
store i32 0, i32* %2
br label %24
18: ; preds = %1
%19 = load i8*, i8** %4
%20 = call i64 @strcasecmp(i8* %19, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 1, i32* %2
br label %24
23: ; preds = %18
store i32 0, i32* %2
br label %24
24: ; preds = %23, %22, %17
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@.str = [13 x i8] c"swish-search\00"
define i32 @check_readonly_mode(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%6 = sext i32 %5 to i64
%7 = sub nsw i64 0, %6
%8 = getelementptr inbounds i8, i8* %4, i64 %7
%9 = icmp ult i8* %8, %0
br i1 %9, label %14, label %10
10: ; preds = %1
%11 = tail call i64 @strcasecmp(i8* %8, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
%13 = zext i1 %12 to i32
br label %14
14: ; preds = %10, %1
%15 = phi i32 [ 0, %1 ], [ %13, %10 ]
ret i32 %15
}