#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 strlen(char const *);
scalar_t__ strncmp(char const *, char *, int);
char *strpbrk(char const *, char *);
bool editor_is_vim(const char *command) {
  const char *s;
  s = strpbrk(command, " \0\t");
  if (s == NULL) {
    s = command + strlen(command);
  }
  if (s - command < 3) {
    return (false);
  }
  if (strncmp(s - 3, "vim", 3) == 0) {
    return (true);
  }
  return (false);
}


x86 assembly (clang, -O0):
<editor_is_vim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <strpbrk@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117c <editor_is_vim+0x4c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x3,%rax
jge    119d <editor_is_vim+0x6d>
movl   $0x0,-0x4(%rbp)
jmp    11d3 <editor_is_vim+0xa3>
mov    -0x18(%rbp),%rdi
add    $0xfffffffffffffffd,%rdi
lea    0xe58(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11cc <editor_is_vim+0x9c>
movl   $0x1,-0x4(%rbp)
jmp    11d3 <editor_is_vim+0xa3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<editor_is_vim>:
push   %rbx
mov    %rdi,%rbx
mov    $0x20,%esi
call   1050 <strchr@plt>
test   %rax,%rax
jne    1150 <editor_is_vim+0x20>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
add    %rbx,%rax
mov    %rax,%rdx
sub    %rbx,%rdx
xor    %ecx,%ecx
cmp    $0x3,%rdx
jl     117e <editor_is_vim+0x4e>
add    $0xfffffffffffffffd,%rax
lea    0xe97(%rip),%rsi
mov    %rax,%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
mov    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c" \00\09\00"
@.str.1 = [4 x i8] c"vim\00"
define i32 @editor_is_vim(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i8* @strpbrk(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %10, i64 %13
store i8* %14, i8** %4
br label %15
15: ; preds = %9, %1
%16 = load i8*, i8** %4
%17 = load i8*, i8** %3
%18 = ptrtoint i8* %16 to i64
%19 = ptrtoint i8* %17 to i64
%20 = sub i64 %18, %19
%21 = icmp slt i64 %20, 3
br i1 %21, label %22, label %23
22: ; preds = %15
store i32 0, i32* %2
br label %30
23: ; preds = %15
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i64 -3
%26 = call i64 @strncmp(i8* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %23
store i32 1, i32* %2
br label %30
29: ; preds = %23
store i32 0, i32* %2
br label %30
30: ; preds = %29, %28, %22
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"vim\00"
define i32 @editor_is_vim(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i32 32)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i32 @strlen(i8* %0)
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
br label %8
8: ; preds = %4, %1
%9 = phi i8* [ %7, %4 ], [ %2, %1 ]
%10 = ptrtoint i8* %9 to i64
%11 = ptrtoint i8* %0 to i64
%12 = sub i64 %10, %11
%13 = icmp slt i64 %12, 3
br i1 %13, label %19, label %14
14: ; preds = %8
%15 = getelementptr inbounds i8, i8* %9, i64 -3
%16 = tail call i64 @strncmp(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%17 = icmp eq i64 %16, 0
%18 = zext i1 %17 to i32
br label %19
19: ; preds = %14, %8
%20 = phi i32 [ 0, %8 ], [ %18, %14 ]
ret i32 %20
}