#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 */
char *create_string(char const *);
int /*<<< orphan*/ strlen(char const *const);
scalar_t__ strncasecmp(char const *, char const *const, int /*<<< orphan*/);
int is_ipmi_dev(const char *dev, char **host_ref) {
  const char *const prefix = "ipmi:";
  if (dev == NULL) {
    return (0);
  }
  if (strncasecmp(dev, prefix, strlen(prefix)) != 0) {
    return (0);
  }
  dev += strlen(prefix);
  if (dev[0] == '\0') {
    return (0);
  }
  if (host_ref) {
    *host_ref = create_string(dev);
  }
  return (1);
}


x86 assembly (clang, -O0):
<is_ipmi_dev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xeb9(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1162 <is_ipmi_dev+0x32>
movl   $0x0,-0x4(%rbp)
jmp    11fb <is_ipmi_dev+0xcb>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xe8f(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
lea    0xe7d(%rip),%rsi
call   1050 <strncasecmp@plt>
cmp    $0x0,%rax
je     119e <is_ipmi_dev+0x6e>
movl   $0x0,-0x4(%rbp)
jmp    11fb <is_ipmi_dev+0xcb>
lea    0xe5b(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11d6 <is_ipmi_dev+0xa6>
movl   $0x0,-0x4(%rbp)
jmp    11fb <is_ipmi_dev+0xcb>
cmpq   $0x0,-0x18(%rbp)
je     11f4 <is_ipmi_dev+0xc4>
mov    -0x10(%rbp),%rdi
call   1040 <create_string@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_ipmi_dev>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r15d,%r15d
test   %rdi,%rdi
je     1193 <is_ipmi_dev+0x63>
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xeb4(%rip),%rbp
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1050 <strncasecmp@plt>
test   %rax,%rax
jne    1193 <is_ipmi_dev+0x63>
lea    0xe93(%rip),%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0x0,(%rbx,%rax,1)
je     1193 <is_ipmi_dev+0x63>
mov    $0x1,%r15d
test   %r14,%r14
je     1193 <is_ipmi_dev+0x63>
add    %rax,%rbx
mov    %rbx,%rdi
call   1040 <create_string@plt>
mov    %rax,(%r14)
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"ipmi:\00"
define i32 @is_ipmi_dev(i8* %0, i8** writeonly %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %18, label %4
4: ; preds = %2
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = tail call i64 @strncasecmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %4
%9 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %8
%15 = icmp eq i8** %1, null
br i1 %15, label %18, label %16
16: ; preds = %14
%17 = tail call i8* @create_string(i8* %11)
store i8* %17, i8** %1
br label %18
18: ; preds = %14, %16, %8, %4, %2
%19 = phi i32 [ 0, %2 ], [ 0, %4 ], [ 0, %8 ], [ 1, %16 ], [ 1, %14 ]
ret i32 %19
}