#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_list_entry *sysattr;
  for (sysattr = udev_device_get_sysattr_list_entry(device); sysattr != NULL;
       sysattr = udev_list_entry_get_next(sysattr)) {
    struct udev *udev = udev_device_get_udev(device);
    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);
    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   1030 <udev_device_get_sysattr_list_entry@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12e4 <print_all_attributes+0x144>
mov    -0x8(%rbp),%rdi
call   1040 <udev_device_get_udev@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%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    12d2 <print_all_attributes+0x132>
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    12d2 <print_all_attributes+0x132>
mov    -0x20(%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),%rdi
call   1070 <strlen@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x38(%rbp)
mov    %al,-0x39(%rbp)
jbe    1271 <print_all_attributes+0xd1>
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    1281 <print_all_attributes+0xe1>
jmp    1292 <print_all_attributes+0xf2>
mov    -0x38(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x38(%rbp)
jmp    1242 <print_all_attributes+0xa2>
cmpq   $0x0,-0x38(%rbp)
jbe    12b8 <print_all_attributes+0x118>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xd64(%rip),%rsi
mov    $0x0,%al
call   1060 <udev_log_null@plt>
jmp    12d2 <print_all_attributes+0x132>
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xd72(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1090 <udev_list_entry_get_next@plt>
mov    %rax,-0x18(%rbp)
jmp    11bd <print_all_attributes+0x1d>
lea    0xd62(%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
push   %rax
mov    %rsi,(%rsp)
mov    %rdi,%r15
call   1040 <udev_device_get_sysattr_list_entry@plt>
test   %rax,%rax
je     1299 <print_all_attributes+0xe9>
mov    %rax,%rbx
jmp    1204 <print_all_attributes+0x54>
lea    0xe61(%rip),%rdi
mov    (%rsp),%rsi
mov    %rbp,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1090 <printf@plt>
nopl   (%rax)
mov    %rbx,%rdi
call   10a0 <udev_list_entry_get_next@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1299 <print_all_attributes+0xe9>
mov    %r15,%rdi
call   1050 <udev_device_get_udev@plt>
mov    %rax,%r13
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    11f0 <print_all_attributes+0x40>
mov    %r15,%rdi
mov    %rbp,%rsi
call   10c0 <udev_device_get_sysattr_value@plt>
test   %rax,%rax
je     11f0 <print_all_attributes+0x40>
mov    %rax,%r12
mov    %r13,%rdi
lea    0xdbc(%rip),%rsi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <udev_log_null@plt>
mov    %r12,%rdi
call   1080 <strlen@plt>
mov    %rax,%r14
nopl   0x0(%rax)
sub    $0x1,%r14
jb     11d5 <print_all_attributes+0x25>
movsbl -0x1(%r12,%rax,1),%edi
call   10b0 <isprint@plt>
mov    %rax,%rcx
mov    %r14,%rax
test   %rcx,%rcx
jne    1260 <print_all_attributes+0xb0>
mov    %r13,%rdi
lea    0xd86(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1070 <udev_log_null@plt>
jmp    11f0 <print_all_attributes+0x40>
mov    $0xa,%edi
add    $0x8,%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_list_entry = type { i32 }
%struct.udev = 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_list_entry*
%6 = alloca %struct.udev*
%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_list_entry* @udev_device_get_sysattr_list_entry(%struct.udev_device* %10)
store %struct.udev_list_entry* %11, %struct.udev_list_entry** %5
br label %12
12: ; preds = %66, %2
%13 = load %struct.udev_list_entry*, %struct.udev_list_entry** %5
%14 = icmp ne %struct.udev_list_entry* %13, null
br i1 %14, label %15, label %69
15: ; preds = %12
%16 = load %struct.udev_device*, %struct.udev_device** %3
%17 = call %struct.udev* @udev_device_get_udev(%struct.udev_device* %16)
store %struct.udev* %17, %struct.udev** %6
%18 = load %struct.udev_list_entry*, %struct.udev_list_entry** %5
%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 = %15
br label %66
24: ; preds = %15
%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 %66
31: ; preds = %24
%32 = load %struct.udev*, %struct.udev** %6
%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 = call i64 @strlen(i8* %36)
store i64 %37, i64* %9
br label %38
38: ; preds = %51, %31
%39 = load i64, i64* %9
%40 = icmp ugt i64 %39, 0
br i1 %40, label %41, label %49
41: ; preds = %38
%42 = load i8*, i8** %8
%43 = load i64, i64* %9
%44 = sub i64 %43, 1
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8, i8* %45
%47 = call i64 @isprint(i8 signext %46)
%48 = icmp ne i64 %47, 0
br label %49
49: ; preds = %41, %38
%50 = phi i1 [ false, %38 ], [ %48, %41 ]
br i1 %50, label %51, label %54
51: ; preds = %49
%52 = load i64, i64* %9
%53 = add i64 %52, -1
store i64 %53, i64* %9
br label %38
54: ; preds = %49
%55 = load i64, i64* %9
%56 = icmp ugt i64 %55, 0
br i1 %56, label %57, label %61
57: ; preds = %54
%58 = load %struct.udev*, %struct.udev** %6
%59 = load i8*, i8** %7
%60 = call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %58, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %59)
br label %66
61: ; preds = %54
%62 = load i8*, i8** %4
%63 = load i8*, i8** %7
%64 = load i8*, i8** %8
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %62, i8* %63, i8* %64)
br label %66
66: ; preds = %61, %57, %30, %23
%67 = load %struct.udev_list_entry*, %struct.udev_list_entry** %5
%68 = call %struct.udev_list_entry* @udev_list_entry_get_next(%struct.udev_list_entry* %67)
store %struct.udev_list_entry* %68, %struct.udev_list_entry** %5
br label %12
69: ; preds = %12
%70 = 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_list_entry = type { i32 }
%struct.udev = 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_list_entry* @udev_device_get_sysattr_list_entry(%struct.udev_device* %0)
%4 = icmp eq %struct.udev_list_entry* %3, null
br i1 %4, label %33, label %5
5: ; preds = %2, %30
%6 = phi %struct.udev_list_entry* [ %31, %30 ], [ %3, %2 ]
%7 = tail call %struct.udev* @udev_device_get_udev(%struct.udev_device* %0)
%8 = tail call i8* @udev_list_entry_get_name(%struct.udev_list_entry* %6)
%9 = tail call i64 @skip_attribute(i8* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %30
11: ; preds = %5
%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 %30, label %14
14: ; preds = %11
%15 = tail call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %8, i8* %12)
%16 = tail call i64 @strlen(i8* %12)
br label %17
17: ; preds = %20, %14
%18 = phi i64 [ %16, %14 ], [ %21, %20 ]
%19 = icmp eq i64 %18, 0
br i1 %19, label %28, label %20
20: ; preds = %17
%21 = add i64 %18, -1
%22 = getelementptr inbounds i8, i8* %12, i64 %21
%23 = load i8, i8* %22
%24 = tail call i64 @isprint(i8 signext %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %17
26: ; preds = %20
%27 = tail call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %7, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %30
28: ; preds = %17
%29 = 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 %30
30: ; preds = %11, %5, %28, %26
%31 = tail call %struct.udev_list_entry* @udev_list_entry_get_next(%struct.udev_list_entry* %6)
%32 = icmp eq %struct.udev_list_entry* %31, null
br i1 %32, label %33, label %5
33: ; preds = %30, %2
%34 = tail call i32 @putchar(i32 10)
ret void
}