#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 {
  int /*<<< orphan*/ d_name;
};

/* Variables and functions */
int sscanf(int /*<<< orphan*/, char *, unsigned short *, unsigned char *,
           unsigned char *, unsigned char *);
int pci_select(const struct dirent *entry) {
  unsigned short dom = 0;
  unsigned char bus = 0, dev = 0, func = 0;
  if (sscanf(entry->d_name, "%4hx:%2hhx:%2hhx.%1hhx", &dom, &bus, &dev,
             &func) == 4)
    return (1);
  return (0);
}


x86 assembly (clang, -O0):
<pci_select>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movw   $0x0,-0x12(%rbp)
movb   $0x0,-0x13(%rbp)
movb   $0x0,-0x14(%rbp)
movb   $0x0,-0x15(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
lea    0xec5(%rip),%rsi
lea    -0x12(%rbp),%rdx
lea    -0x13(%rbp),%rcx
lea    -0x14(%rbp),%r8
lea    -0x15(%rbp),%r9
call   1030 <sscanf@plt>
cmp    $0x4,%eax
jne    1165 <pci_select+0x55>
movl   $0x1,-0x4(%rbp)
jmp    116c <pci_select+0x5c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pci_select>:
push   %rax
movw   $0x0,0x6(%rsp)
movb   $0x0,0x5(%rsp)
movb   $0x0,0x4(%rsp)
movb   $0x0,0x3(%rsp)
mov    (%rdi),%edi
lea    0xed0(%rip),%rsi
lea    0x6(%rsp),%rdx
lea    0x5(%rsp),%rcx
lea    0x4(%rsp),%r8
lea    0x3(%rsp),%r9
call   1030 <sscanf@plt>
xor    %ecx,%ecx
cmp    $0x4,%eax
sete   %cl
mov    %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [23 x i8] c"%4hx:%2hhx:%2hhx.%1hhx\00"
define i32 @pci_select(%struct.dirent* %0) {
%2 = alloca i32
%3 = alloca %struct.dirent*
%4 = alloca i16
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
store %struct.dirent* %0, %struct.dirent** %3
store i16 0, i16* %4
store i8 0, i8* %5
store i8 0, i8* %6
store i8 0, i8* %7
%8 = load %struct.dirent*, %struct.dirent** %3
%9 = getelementptr inbounds %struct.dirent, %struct.dirent* %8, i32 0, i32 0
%10 = load i32, i32* %9
%11 = call i32 @sscanf(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i16* %4, i8* %5, i8* %6, i8* %7)
%12 = icmp eq i32 %11, 4
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 1, i32* %2
br label %15
14: ; preds = %1
store i32 0, i32* %2
br label %15
15: ; preds = %14, %13
%16 = load i32, i32* %2
ret i32 %16
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [23 x i8] c"%4hx:%2hhx:%2hhx.%1hhx\00"
define i32 @pci_select(%struct.dirent* nocapture %0) {
%2 = alloca i16
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8
%6 = bitcast i16* %2 to i8*
store i16 0, i16* %2
store i8 0, i8* %3
store i8 0, i8* %4
store i8 0, i8* %5
%7 = getelementptr inbounds %struct.dirent, %struct.dirent* %0, i64 0, i32 0
%8 = load i32, i32* %7
%9 = call i32 @sscanf(i32 %8, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i16* %2, i8* %3, i8* %4, i8* %5)
%10 = icmp eq i32 %9, 4
%11 = zext i1 %10 to i32
ret i32 %11
}