#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 */
struct dirent {
  char *d_name;
};

/* Variables and functions */
int sscanf(char *, char *, int *, int *, ...);
scalar_t__ strstr(char *, char *);
int scan_ctrl_paths_filter(const struct dirent *d) {
  int id, cntlid, nsid;
  if (d->d_name[0] == '.')
    return 0;
  if (strstr(d->d_name, "nvme")) {
    if (sscanf(d->d_name, "nvme%dc%dn%d", &id, &cntlid, &nsid) == 3)
      return 1;
    if (sscanf(d->d_name, "nvme%dn%d", &id, &nsid) == 2)
      return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<scan_ctrl_paths_filter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    114b <scan_ctrl_paths_filter+0x2b>
movl   $0x0,-0x4(%rbp)
jmp    11dc <scan_ctrl_paths_filter+0xbc>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xea7(%rip),%rsi
call   1040 <strstr@plt>
cmp    $0x0,%rax
je     11d5 <scan_ctrl_paths_filter+0xb5>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe8f(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%r8
mov    $0x0,%al
call   1030 <sscanf@plt>
cmp    $0x3,%eax
jne    119e <scan_ctrl_paths_filter+0x7e>
movl   $0x1,-0x4(%rbp)
jmp    11dc <scan_ctrl_paths_filter+0xbc>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe66(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
mov    $0x0,%al
call   1030 <sscanf@plt>
cmp    $0x2,%eax
jne    11d0 <scan_ctrl_paths_filter+0xb0>
movl   $0x1,-0x4(%rbp)
jmp    11dc <scan_ctrl_paths_filter+0xbc>
jmp    11d5 <scan_ctrl_paths_filter+0xb5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_ctrl_paths_filter>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    (%rdi),%rdi
xor    %ebp,%ebp
cmpb   $0x2e,(%rdi)
je     1190 <scan_ctrl_paths_filter+0x70>
lea    0xec6(%rip),%rsi
call   1040 <strstr@plt>
test   %rax,%rax
je     118e <scan_ctrl_paths_filter+0x6e>
mov    (%rbx),%rdi
lea    0xeb7(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x14(%rsp),%rcx
lea    0xc(%rsp),%r8
xor    %eax,%eax
call   1030 <sscanf@plt>
mov    $0x1,%ebp
cmp    $0x3,%eax
je     1190 <scan_ctrl_paths_filter+0x70>
mov    (%rbx),%rdi
lea    0xe9a(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
xor    %eax,%eax
call   1030 <sscanf@plt>
cmp    $0x2,%eax
je     1190 <scan_ctrl_paths_filter+0x70>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [5 x i8] c"nvme\00"
@.str.1 = [13 x i8] c"nvme%dc%dn%d\00"
@.str.2 = [10 x i8] c"nvme%dn%d\00"
define i32 @scan_ctrl_paths_filter(%struct.dirent* nocapture %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = getelementptr inbounds %struct.dirent, %struct.dirent* %0, i64 0, i32 0
%9 = load i8*, i8** %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 46
br i1 %11, label %24, label %12
12: ; preds = %1
%13 = tail call i64 @strstr(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %23, label %15
15: ; preds = %12
%16 = load i8*, i8** %8
%17 = call i32 (i8*, i8*, i32*, i32*, ...) @sscanf(i8* %16, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3, i32* %4)
%18 = icmp eq i32 %17, 3
br i1 %18, label %24, label %19
19: ; preds = %15
%20 = load i8*, i8** %8
%21 = call i32 (i8*, i8*, i32*, i32*, ...) @sscanf(i8* %20, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* %2, i32* %4)
%22 = icmp eq i32 %21, 2
br i1 %22, label %24, label %23
23: ; preds = %19, %12
br label %24
24: ; preds = %19, %15, %1, %23
%25 = phi i32 [ 0, %23 ], [ 0, %1 ], [ 1, %15 ], [ 1, %19 ]
ret i32 %25
}