#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*/ strncasecmp(char *, char *, int);
char *has_kernel_opt(char *buf) {
  int idx = 0;
  if (!strncasecmp(buf, "kernel", 6))
    idx = 6;
  else if (!strncasecmp(buf, "k", 1))
    idx = 1;
  if (idx && (buf[idx] == '\0' || buf[idx] == ','))
    return buf;
  return NULL;
}


x86 assembly (clang, -O0):
<has_kernel_opt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xed2(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncasecmp@plt>
cmp    $0x0,%eax
jne    114d <has_kernel_opt+0x3d>
movl   $0x6,-0x14(%rbp)
jmp    1177 <has_kernel_opt+0x67>
mov    -0x10(%rbp),%rdi
lea    0xeaf(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncasecmp@plt>
cmp    $0x0,%eax
jne    1172 <has_kernel_opt+0x62>
movl   $0x1,-0x14(%rbp)
jmp    1177 <has_kernel_opt+0x67>
cmpl   $0x0,-0x14(%rbp)
je     11b8 <has_kernel_opt+0xa8>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11ab <has_kernel_opt+0x9b>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2c,%eax
jne    11b8 <has_kernel_opt+0xa8>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11c0 <has_kernel_opt+0xb0>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<has_kernel_opt>:
push   %rbx
mov    %rdi,%rbx
lea    0xee5(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncasecmp@plt>
test   %eax,%eax
je     1148 <has_kernel_opt+0x38>
lea    0xed7(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1030 <strncasecmp@plt>
test   %eax,%eax
jne    1158 <has_kernel_opt+0x48>
mov    $0x1,%eax
jmp    114d <has_kernel_opt+0x3d>
mov    $0x6,%eax
mov    (%rbx,%rax,1),%al
test   %al,%al
je     115a <has_kernel_opt+0x4a>
cmp    $0x2c,%al
je     115a <has_kernel_opt+0x4a>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [7 x i8] c"kernel\00"
@.str.1 = [2 x i8] c"k\00"
define i8* @has_kernel_opt(i8* %0) {
%2 = tail call i32 @strncasecmp(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%3 = icmp eq i32 %2, 0
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = tail call i32 @strncasecmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %1, %4
%8 = phi i64 [ 1, %4 ], [ 6, %1 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
switch i8 %10, label %11 [
i8 0, label %12
i8 44, label %12
]
11: ; preds = %7, %4
br label %12
12: ; preds = %7, %7, %11
%13 = phi i8* [ null, %11 ], [ %0, %7 ], [ %0, %7 ]
ret i8* %13
}