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

/* Variables and functions */
scalar_t__ isprint(char const);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ skip_attribute(char const *);
size_t strlen(char const *);
struct udev_list_entry *
udev_device_get_sysattr_list_entry(struct udev_device *);
char *udev_device_get_sysattr_value(struct udev_device *, char const *);
struct udev *udev_device_get_udev(struct udev_device *);
char *udev_list_entry_get_name(struct udev_list_entry *);
struct udev_list_entry *udev_list_entry_get_next(struct udev_list_entry *);
int /*<<< orphan*/ udev_log_null(struct udev *, char *, char const *, ...);
void print_all_attributes(struct udev_device *device, const char *key) {
  struct udev *udev = udev_device_get_udev(device);
  struct udev_list_entry *sysattr;
  for (sysattr = udev_device_get_sysattr_list_entry(device); sysattr != NULL;
       sysattr = udev_list_entry_get_next(sysattr)) {
    const char *name;
    const char *value;
    size_t len;
    name = udev_list_entry_get_name(sysattr);
    if (skip_attribute(name))
      continue;
    value = udev_device_get_sysattr_value(device, name);
    if (value == NULL)
      continue;
    udev_log_null(udev, "attr '%s'='%s'\n", name, value);
    if (value[0] == '/')
      continue;
    len = strlen(value);
    while (len > 0 && isprint(value[len - 1]))
      len--;
    if (len > 0) {
      udev_log_null(udev, "attribute value of '%s' non-printable, skip\n",
                    name);
      continue;
    }
    printf("    %s{%s}==\"%s\"\n", key, name, value);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_all_attributes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <udev_device_get_udev@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <udev_device_get_sysattr_list_entry@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12f9 <print_all_attributes+0x159>
mov    -0x20(%rbp),%rdi
call   10c0 <udev_list_entry_get_name@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <skip_attribute@plt>
cmp    $0x0,%rax
je     11fa <print_all_attributes+0x5a>
jmp    12e7 <print_all_attributes+0x147>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10b0 <udev_device_get_sysattr_value@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    121b <print_all_attributes+0x7b>
jmp    12e7 <print_all_attributes+0x147>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xdd2(%rip),%rsi
mov    $0x0,%al
call   1060 <udev_log_null@plt>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    124a <print_all_attributes+0xaa>
jmp    12e7 <print_all_attributes+0x147>
mov    -0x30(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x38(%rbp)
mov    %al,-0x39(%rbp)
jbe    1286 <print_all_attributes+0xe6>
mov    -0x30(%rbp),%rax
mov    -0x38(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%edi
call   10a0 <isprint@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    1296 <print_all_attributes+0xf6>
jmp    12a7 <print_all_attributes+0x107>
mov    -0x38(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x38(%rbp)
jmp    1257 <print_all_attributes+0xb7>
cmpq   $0x0,-0x38(%rbp)
jbe    12cd <print_all_attributes+0x12d>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xd4f(%rip),%rsi
mov    $0x0,%al
call   1060 <udev_log_null@plt>
jmp    12e7 <print_all_attributes+0x147>
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1090 <udev_list_entry_get_next@plt>
mov    %rax,-0x20(%rbp)
jmp    11ca <print_all_attributes+0x2a>
lea    0xd4d(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_all_attributes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x10(%rsp)
mov    %rdi,%r12
call   1050 <udev_device_get_udev@plt>
mov    %rax,0x8(%rsp)
mov    %r12,%rdi
call   1040 <udev_device_get_sysattr_list_entry@plt>
test   %rax,%rax
je     12bb <print_all_attributes+0x10b>
mov    %rax,%rbx
lea    0xe15(%rip),%r15
jmp    1224 <print_all_attributes+0x74>
lea    0xe49(%rip),%rdi
mov    0x10(%rsp),%rsi
mov    %rbp,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1090 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10a0 <udev_list_entry_get_next@plt>
mov    %rax,%rbx
test   %rax,%rax
je     12bb <print_all_attributes+0x10b>
mov    %rbx,%rdi
call   10d0 <udev_list_entry_get_name@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1060 <skip_attribute@plt>
test   %rax,%rax
jne    1210 <print_all_attributes+0x60>
mov    %r12,%rdi
mov    %rbp,%rsi
call   10c0 <udev_device_get_sysattr_value@plt>
test   %rax,%rax
je     1210 <print_all_attributes+0x60>
mov    %rax,%r14
mov    0x8(%rsp),%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <udev_log_null@plt>
cmpb   $0x2f,(%r14)
je     1210 <print_all_attributes+0x60>
mov    %r14,%rdi
call   1080 <strlen@plt>
mov    %rax,%r13
cs nopw 0x0(%rax,%rax,1)
nop
sub    $0x1,%r13
jb     11ed <print_all_attributes+0x3d>
movsbl -0x1(%r14,%rax,1),%edi
call   10b0 <isprint@plt>
mov    %rax,%rcx
mov    %r13,%rax
test   %rcx,%rcx
jne    1280 <print_all_attributes+0xd0>
mov    0x8(%rsp),%rdi
lea    0xd64(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1070 <udev_log_null@plt>
jmp    1210 <print_all_attributes+0x60>
mov    $0xa,%edi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
%struct.udev_device = type { i32 }
%struct.udev = type { i32 }
%struct.udev_list_entry = type { i32 }
@.str = [16 x i8] c"attr '%s'='%s'\0A\00"
@.str.1 = [45 x i8] c"attribute value of '%s' non-printable, skip\0A\00"
@.str.2 = [18 x i8] c" %s{%s}==\22%s\22\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @print_all_attributes(%struct.udev_device* %0, i8* %1) {
%3 = alloca %struct.udev_device*
%4 = alloca i8*
%5 = alloca %struct.udev*
%6 = alloca %struct.udev_list_entry*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
store %struct.udev_device* %0, %struct.udev_device** %3
store i8* %1, i8** %4
%10 = load %struct.udev_device*, %struct.udev_device** %3
%11 = call %struct.udev* @udev_device_get_udev(%struct.udev_device* %10)
store %struct.udev* %11, %struct.udev** %5
%12 = load %struct.udev_device*, %struct.udev_device** %3
%13 = call %struct.udev_list_entry* @udev_device_get_sysattr_list_entry(%struct.udev_device* %12)
store %struct.udev_list_entry* %13, %struct.udev_list_entry** %6
br label %14
14: ; preds = %73, %2
%15 = load %struct.udev_list_entry*, %struct.udev_list_entry** %6
%16 = icmp ne %struct.udev_list_entry* %15, null
br i1 %16, label %17, label %76
17: ; preds = %14
%18 = load %struct.udev_list_entry*, %struct.udev_list_entry** %6
%19 = call i8* @udev_list_entry_get_name(%struct.udev_list_entry* %18)
store i8* %19, i8** %7
%20 = load i8*, i8** %7
%21 = call i64 @skip_attribute(i8* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
br label %73
24: ; preds = %17
%25 = load %struct.udev_device*, %struct.udev_device** %3
%26 = load i8*, i8** %7
%27 = call i8* @udev_device_get_sysattr_value(%struct.udev_device* %25, i8* %26)
store i8* %27, i8** %8
%28 = load i8*, i8** %8
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %31
30: ; preds = %24
br label %73
31: ; preds = %24
%32 = load %struct.udev*, %struct.udev** %5
%33 = load i8*, i8** %7
%34 = load i8*, i8** %8
%35 = call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %32, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %33, i8* %34)
%36 = load i8*, i8** %8
%37 = getelementptr inbounds i8, i8* %36, i64 0
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 47
br i1 %40, label %41, label %42
41: ; preds = %31
br label %73
42: ; preds = %31
%43 = load i8*, i8** %8
%44 = call i64 @strlen(i8* %43)
store i64 %44, i64* %9
br label %45
45: ; preds = %58, %42
%46 = load i64, i64* %9
%47 = icmp ugt i64 %46, 0
br i1 %47, label %48, label %56
48: ; preds = %45
%49 = load i8*, i8** %8
%50 = load i64, i64* %9
%51 = sub i64 %50, 1
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i8, i8* %52
%54 = call i64 @isprint(i8 signext %53)
%55 = icmp ne i64 %54, 0
br label %56
56: ; preds = %48, %45
%57 = phi i1 [ false, %45 ], [ %55, %48 ]
br i1 %57, label %58, label %61
58: ; preds = %56
%59 = load i64, i64* %9
%60 = add i64 %59, -1
store i64 %60, i64* %9
br label %45
61: ; preds = %56
%62 = load i64, i64* %9
%63 = icmp ugt i64 %62, 0
br i1 %63, label %64, label %68
64: ; preds = %61
%65 = load %struct.udev*, %struct.udev** %5
%66 = load i8*, i8** %7
%67 = call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %65, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %66)
br label %73
68: ; preds = %61
%69 = load i8*, i8** %4
%70 = load i8*, i8** %7
%71 = load i8*, i8** %8
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %69, i8* %70, i8* %71)
br label %73
73: ; preds = %68, %64, %41, %30, %23
%74 = load %struct.udev_list_entry*, %struct.udev_list_entry** %6
%75 = call %struct.udev_list_entry* @udev_list_entry_get_next(%struct.udev_list_entry* %74)
store %struct.udev_list_entry* %75, %struct.udev_list_entry** %6
br label %14
76: ; preds = %14
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.udev_device = type { i32 }
%struct.udev = type { i32 }
%struct.udev_list_entry = type { i32 }
@.str = [16 x i8] c"attr '%s'='%s'\0A\00"
@.str.1 = [45 x i8] c"attribute value of '%s' non-printable, skip\0A\00"
@.str.2 = [18 x i8] c" %s{%s}==\22%s\22\0A\00"
define void @print_all_attributes(%struct.udev_device* %0, i8* %1) {
%3 = tail call %struct.udev* @udev_device_get_udev(%struct.udev_device* %0)
%4 = tail call %struct.udev_list_entry* @udev_device_get_sysattr_list_entry(%struct.udev_device* %0)
%5 = icmp eq %struct.udev_list_entry* %4, null
br i1 %5, label %36, label %6
6: ; preds = %2, %33
%7 = phi %struct.udev_list_entry* [ %34, %33 ], [ %4, %2 ]
%8 = tail call i8* @udev_list_entry_get_name(%struct.udev_list_entry* %7)
%9 = tail call i64 @skip_attribute(i8* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %33
11: ; preds = %6
%12 = tail call i8* @udev_device_get_sysattr_value(%struct.udev_device* %0, i8* %8)
%13 = icmp eq i8* %12, null
br i1 %13, label %33, label %14
14: ; preds = %11
%15 = tail call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %3, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %8, i8* %12)
%16 = load i8, i8* %12
%17 = icmp eq i8 %16, 47
br i1 %17, label %33, label %18
18: ; preds = %14
%19 = tail call i64 @strlen(i8* %12)
br label %20
20: ; preds = %23, %18
%21 = phi i64 [ %19, %18 ], [ %24, %23 ]
%22 = icmp eq i64 %21, 0
br i1 %22, label %31, label %23
23: ; preds = %20
%24 = add i64 %21, -1
%25 = getelementptr inbounds i8, i8* %12, i64 %24
%26 = load i8, i8* %25
%27 = tail call i64 @isprint(i8 signext %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %20
29: ; preds = %23
%30 = tail call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %3, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %33
31: ; preds = %20
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %8, i8* %12)
br label %33
33: ; preds = %14, %11, %6, %31, %29
%34 = tail call %struct.udev_list_entry* @udev_list_entry_get_next(%struct.udev_list_entry* %7)
%35 = icmp eq %struct.udev_list_entry* %34, null
br i1 %35, label %36, label %6
36: ; preds = %33, %2
%37 = tail call i32 @putchar(i32 10)
ret void
}