#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 udev_device {
  int dummy;
};
struct udev {
  int dummy;
};

/* Variables and functions */
int EINVAL;
scalar_t__ fnmatch(char const *, char const *, int /*<<< orphan*/);
char *udev_device_get_sysattr_value(struct udev_device *, char const *);
struct udev_device *udev_device_new_from_syspath(struct udev *, char const *);
int /*<<< orphan*/ udev_device_unref(struct udev_device *);
int match_sysattr_value(struct udev *udev, const char *syspath,
                        const char *sysattr, const char *match_val) {
  struct udev_device *device;
  const char *val = NULL;
  int match = 0;
  device = udev_device_new_from_syspath(udev, syspath);
  if (device == NULL)
    return -EINVAL;
  val = udev_device_get_sysattr_value(device, sysattr);
  if (val == NULL)
    goto exit;
  if (match_val == NULL) {
    match = 1;
    goto exit;
  }
  if (fnmatch(match_val, val, 0) == 0) {
    match = 1;
    goto exit;
  }
exit:
  udev_device_unref(device);
  return match;
}


x86 assembly (clang, -O0):
<match_sysattr_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <udev_device_new_from_syspath@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1196 <match_sysattr_value+0x56>
xor    %eax,%eax
mov    0x2e54(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1207 <match_sysattr_value+0xc7>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <udev_device_get_sysattr_value@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11b7 <match_sysattr_value+0x77>
jmp    11f8 <match_sysattr_value+0xb8>
cmpq   $0x0,-0x28(%rbp)
jne    11ce <match_sysattr_value+0x8e>
movl   $0x1,-0x3c(%rbp)
jmp    11f8 <match_sysattr_value+0xb8>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
xor    %edx,%edx
call   1030 <fnmatch@plt>
cmp    $0x0,%rax
jne    11f3 <match_sysattr_value+0xb3>
movl   $0x1,-0x3c(%rbp)
jmp    11f8 <match_sysattr_value+0xb8>
jmp    11f8 <match_sysattr_value+0xb8>
mov    -0x30(%rbp),%rdi
call   1050 <udev_device_unref@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match_sysattr_value>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rdx,%rbp
call   1040 <udev_device_new_from_syspath@plt>
test   %rax,%rax
je     1184 <match_sysattr_value+0x44>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1060 <udev_device_get_sysattr_value@plt>
test   %rax,%rax
je     1191 <match_sysattr_value+0x51>
test   %r14,%r14
je     1195 <match_sysattr_value+0x55>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %edx,%edx
call   1030 <fnmatch@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
jmp    119a <match_sysattr_value+0x5a>
mov    0x2e55(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
jmp    11a2 <match_sysattr_value+0x62>
xor    %ebp,%ebp
jmp    119a <match_sysattr_value+0x5a>
mov    $0x1,%ebp
mov    %rbx,%rdi
call   1050 <udev_device_unref@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.udev = type { i32 }
%struct.udev_device = type { i32 }
@EINVAL = global i32 0
define i32 @match_sysattr_value(%struct.udev* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca %struct.udev*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca %struct.udev_device*
%11 = alloca i8*
%12 = alloca i32
store %struct.udev* %0, %struct.udev** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i8* null, i8** %11
store i32 0, i32* %12
%13 = load %struct.udev*, %struct.udev** %6
%14 = load i8*, i8** %7
%15 = call %struct.udev_device* @udev_device_new_from_syspath(%struct.udev* %13, i8* %14)
store %struct.udev_device* %15, %struct.udev_device** %10
%16 = load %struct.udev_device*, %struct.udev_device** %10
%17 = icmp eq %struct.udev_device* %16, null
br i1 %17, label %18, label %21
18: ; preds = %4
%19 = load i32, i32* @EINVAL
%20 = sub nsw i32 0, %19
store i32 %20, i32* %5
br label %43
21: ; preds = %4
%22 = load %struct.udev_device*, %struct.udev_device** %10
%23 = load i8*, i8** %8
%24 = call i8* @udev_device_get_sysattr_value(%struct.udev_device* %22, i8* %23)
store i8* %24, i8** %11
%25 = load i8*, i8** %11
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %28
27: ; preds = %21
br label %39
28: ; preds = %21
%29 = load i8*, i8** %9
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %32
31: ; preds = %28
store i32 1, i32* %12
br label %39
32: ; preds = %28
%33 = load i8*, i8** %9
%34 = load i8*, i8** %11
%35 = call i64 @fnmatch(i8* %33, i8* %34, i32 0)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %32
store i32 1, i32* %12
br label %39
38: ; preds = %32
br label %39
39: ; preds = %38, %37, %31, %27
%40 = load %struct.udev_device*, %struct.udev_device** %10
%41 = call i32 @udev_device_unref(%struct.udev_device* %40)
%42 = load i32, i32* %12
store i32 %42, i32* %5
br label %43
43: ; preds = %39, %18
%44 = load i32, i32* %5
ret i32 %44
}

LLVM IR (-O2):
%struct.udev = type { i32 }
%struct.udev_device = type { i32 }
@EINVAL = global i32 0
define i32 @match_sysattr_value(%struct.udev* %0, i8* %1, i8* %2, i8* %3) {
%5 = tail call %struct.udev_device* @udev_device_new_from_syspath(%struct.udev* %0, i8* %1)
%6 = icmp eq %struct.udev_device* %5, null
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = load i32, i32* @EINVAL
%9 = sub nsw i32 0, %8
br label %22
10: ; preds = %4
%11 = tail call i8* @udev_device_get_sysattr_value(%struct.udev_device* %5, i8* %2)
%12 = icmp eq i8* %11, null
br i1 %12, label %19, label %13
13: ; preds = %10
%14 = icmp eq i8* %3, null
br i1 %14, label %19, label %15
15: ; preds = %13
%16 = tail call i64 @fnmatch(i8* %3, i8* %11, i32 0)
%17 = icmp eq i64 %16, 0
%18 = zext i1 %17 to i32
br label %19
19: ; preds = %15, %13, %10
%20 = phi i32 [ 0, %10 ], [ 1, %13 ], [ %18, %15 ]
%21 = tail call i32 @udev_device_unref(%struct.udev_device* %5)
br label %22
22: ; preds = %19, %7
%23 = phi i32 [ %9, %7 ], [ %20, %19 ]
ret i32 %23
}