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

/* Variables and functions */
int /*<<< orphan*/ print_record(struct udev_device *);
struct udev_device *udev_device_new_from_syspath(struct udev *,
                                                 int /*<<< orphan*/);
int /*<<< orphan*/ udev_device_unref(struct udev_device *);
struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *);
struct udev_enumerate *udev_enumerate_new(struct udev *);
int /*<<< orphan*/ udev_enumerate_scan_devices(struct udev_enumerate *);
int /*<<< orphan*/ udev_enumerate_unref(struct udev_enumerate *);
int /*<<< orphan*/ udev_list_entry_get_name(struct udev_list_entry *);
struct udev_list_entry *udev_list_entry_get_next(struct udev_list_entry *);
int export_devices(struct udev *udev) {
  struct udev_enumerate *udev_enumerate;
  struct udev_list_entry *list_entry;
  udev_enumerate = udev_enumerate_new(udev);
  if (udev_enumerate == NULL)
    return -1;
  udev_enumerate_scan_devices(udev_enumerate);
  for (list_entry = udev_enumerate_get_list_entry(udev_enumerate);
       list_entry != NULL; list_entry = udev_list_entry_get_next(list_entry)) {
    struct udev_device *device;
    device = udev_device_new_from_syspath(udev,
                                          udev_list_entry_get_name(list_entry));
    if (device != NULL) {
      print_record(device);
      udev_device_unref(device);
    }
  }
  udev_enumerate_unref(udev_enumerate);
  return 0;
}


x86 assembly (clang, -O0):
<export_devices>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <udev_enumerate_new@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c0 <export_devices+0x30>
movl   $0xffffffff,-0x4(%rbp)
jmp    1245 <export_devices+0xb5>
mov    -0x18(%rbp),%rdi
call   1030 <udev_enumerate_scan_devices@plt>
mov    -0x18(%rbp),%rdi
call   1070 <udev_enumerate_get_list_entry@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1235 <export_devices+0xa5>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   10b0 <udev_list_entry_get_name@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   1060 <udev_device_new_from_syspath@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     121e <export_devices+0x8e>
mov    -0x28(%rbp),%rdi
call   1090 <print_record@plt>
mov    -0x28(%rbp),%rdi
call   1080 <udev_device_unref@plt>
jmp    1223 <export_devices+0x93>
mov    -0x20(%rbp),%rdi
call   1050 <udev_list_entry_get_next@plt>
mov    %rax,-0x20(%rbp)
jmp    11d6 <export_devices+0x46>
mov    -0x18(%rbp),%rdi
call   10a0 <udev_enumerate_unref@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<export_devices>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1040 <udev_enumerate_new@plt>
test   %rax,%rax
je     1218 <export_devices+0x88>
mov    %rax,%r14
mov    %rax,%rdi
call   1030 <udev_enumerate_scan_devices@plt>
mov    %r14,%rdi
call   1070 <udev_enumerate_get_list_entry@plt>
test   %rax,%rax
je     120c <export_devices+0x7c>
mov    %rax,%rbx
jmp    11e0 <export_devices+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <udev_list_entry_get_next@plt>
mov    %rax,%rbx
test   %rax,%rax
je     120c <export_devices+0x7c>
mov    %rbx,%rdi
call   10b0 <udev_list_entry_get_name@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1060 <udev_device_new_from_syspath@plt>
test   %rax,%rax
je     11d0 <export_devices+0x40>
mov    %rax,%r12
mov    %rax,%rdi
call   1090 <print_record@plt>
mov    %r12,%rdi
call   1080 <udev_device_unref@plt>
jmp    11d0 <export_devices+0x40>
mov    %r14,%rdi
call   10a0 <udev_enumerate_unref@plt>
xor    %eax,%eax
jmp    121d <export_devices+0x8d>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.udev = type { i32 }
%struct.udev_enumerate = type { i32 }
%struct.udev_list_entry = type { i32 }
%struct.udev_device = type { i32 }
define i32 @export_devices(%struct.udev* %0) {
%2 = alloca i32
%3 = alloca %struct.udev*
%4 = alloca %struct.udev_enumerate*
%5 = alloca %struct.udev_list_entry*
%6 = alloca %struct.udev_device*
store %struct.udev* %0, %struct.udev** %3
%7 = load %struct.udev*, %struct.udev** %3
%8 = call %struct.udev_enumerate* @udev_enumerate_new(%struct.udev* %7)
store %struct.udev_enumerate* %8, %struct.udev_enumerate** %4
%9 = load %struct.udev_enumerate*, %struct.udev_enumerate** %4
%10 = icmp eq %struct.udev_enumerate* %9, null
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 -1, i32* %2
br label %39
12: ; preds = %1
%13 = load %struct.udev_enumerate*, %struct.udev_enumerate** %4
%14 = call i32 @udev_enumerate_scan_devices(%struct.udev_enumerate* %13)
%15 = load %struct.udev_enumerate*, %struct.udev_enumerate** %4
%16 = call %struct.udev_list_entry* @udev_enumerate_get_list_entry(%struct.udev_enumerate* %15)
store %struct.udev_list_entry* %16, %struct.udev_list_entry** %5
br label %17
17: ; preds = %33, %12
%18 = load %struct.udev_list_entry*, %struct.udev_list_entry** %5
%19 = icmp ne %struct.udev_list_entry* %18, null
br i1 %19, label %20, label %36
20: ; preds = %17
%21 = load %struct.udev*, %struct.udev** %3
%22 = load %struct.udev_list_entry*, %struct.udev_list_entry** %5
%23 = call i32 @udev_list_entry_get_name(%struct.udev_list_entry* %22)
%24 = call %struct.udev_device* @udev_device_new_from_syspath(%struct.udev* %21, i32 %23)
store %struct.udev_device* %24, %struct.udev_device** %6
%25 = load %struct.udev_device*, %struct.udev_device** %6
%26 = icmp ne %struct.udev_device* %25, null
br i1 %26, label %27, label %32
27: ; preds = %20
%28 = load %struct.udev_device*, %struct.udev_device** %6
%29 = call i32 @print_record(%struct.udev_device* %28)
%30 = load %struct.udev_device*, %struct.udev_device** %6
%31 = call i32 @udev_device_unref(%struct.udev_device* %30)
br label %32
32: ; preds = %27, %20
br label %33
33: ; preds = %32
%34 = load %struct.udev_list_entry*, %struct.udev_list_entry** %5
%35 = call %struct.udev_list_entry* @udev_list_entry_get_next(%struct.udev_list_entry* %34)
store %struct.udev_list_entry* %35, %struct.udev_list_entry** %5
br label %17
36: ; preds = %17
%37 = load %struct.udev_enumerate*, %struct.udev_enumerate** %4
%38 = call i32 @udev_enumerate_unref(%struct.udev_enumerate* %37)
store i32 0, i32* %2
br label %39
39: ; preds = %36, %11
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
%struct.udev = type { i32 }
%struct.udev_enumerate = type { i32 }
%struct.udev_list_entry = type { i32 }
%struct.udev_device = type { i32 }
define i32 @export_devices(%struct.udev* %0) {
%2 = tail call %struct.udev_enumerate* @udev_enumerate_new(%struct.udev* %0)
%3 = icmp eq %struct.udev_enumerate* %2, null
br i1 %3, label %21, label %4
4: ; preds = %1
%5 = tail call i32 @udev_enumerate_scan_devices(%struct.udev_enumerate* %2)
%6 = tail call %struct.udev_list_entry* @udev_enumerate_get_list_entry(%struct.udev_enumerate* %2)
%7 = icmp eq %struct.udev_list_entry* %6, null
br i1 %7, label %19, label %8
8: ; preds = %4, %16
%9 = phi %struct.udev_list_entry* [ %17, %16 ], [ %6, %4 ]
%10 = tail call i32 @udev_list_entry_get_name(%struct.udev_list_entry* %9)
%11 = tail call %struct.udev_device* @udev_device_new_from_syspath(%struct.udev* %0, i32 %10)
%12 = icmp eq %struct.udev_device* %11, null
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = tail call i32 @print_record(%struct.udev_device* %11)
%15 = tail call i32 @udev_device_unref(%struct.udev_device* %11)
br label %16
16: ; preds = %13, %8
%17 = tail call %struct.udev_list_entry* @udev_list_entry_get_next(%struct.udev_list_entry* %9)
%18 = icmp eq %struct.udev_list_entry* %17, null
br i1 %18, label %19, label %8
19: ; preds = %16, %4
%20 = tail call i32 @udev_enumerate_unref(%struct.udev_enumerate* %2)
br label %21
21: ; preds = %1, %19
%22 = phi i32 [ 0, %19 ], [ -1, %1 ]
ret i32 %22
}