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

/* Variables and functions */
int /*<<< orphan*/ udev_enumerate_add_syspath(struct udev_enumerate *,
                                              int /*<<< orphan*/);
struct udev *udev_enumerate_get_udev(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 *);
struct udev_list_entry *udev_queue_get_failed_list_entry(struct udev_queue *);
struct udev_queue *udev_queue_new(struct udev *);
int scan_failed(struct udev_enumerate *udev_enumerate) {
  struct udev *udev = udev_enumerate_get_udev(udev_enumerate);
  struct udev_queue *udev_queue;
  struct udev_list_entry *list_entry;
  udev_queue = udev_queue_new(udev);
  if (udev_queue == NULL)
    return -1;
  for (list_entry = udev_queue_get_failed_list_entry(udev_queue);
       list_entry != NULL; list_entry = udev_list_entry_get_next(list_entry))
    udev_enumerate_add_syspath(udev_enumerate,
                               udev_list_entry_get_name(list_entry));
  return 0;
}


x86 assembly (clang, -O0):
<scan_failed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <udev_enumerate_get_udev@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <udev_queue_new@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119d <scan_failed+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ea <scan_failed+0x8a>
mov    -0x20(%rbp),%rdi
call   1060 <udev_queue_get_failed_list_entry@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11e3 <scan_failed+0x83>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <udev_list_entry_get_name@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   1030 <udev_enumerate_add_syspath@plt>
mov    -0x28(%rbp),%rdi
call   1040 <udev_list_entry_get_next@plt>
mov    %rax,-0x28(%rbp)
jmp    11aa <scan_failed+0x4a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_failed>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1050 <udev_enumerate_get_udev@plt>
mov    %rax,%rdi
call   1070 <udev_queue_new@plt>
test   %rax,%rax
je     11b4 <scan_failed+0x54>
mov    %rax,%rdi
call   1060 <udev_queue_get_failed_list_entry@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     11ba <scan_failed+0x5a>
mov    %rax,%rbp
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1080 <udev_list_entry_get_name@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <udev_enumerate_add_syspath@plt>
mov    %rbp,%rdi
call   1040 <udev_list_entry_get_next@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1190 <scan_failed+0x30>
jmp    11ba <scan_failed+0x5a>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.udev_enumerate = type { i32 }
%struct.udev = type { i32 }
%struct.udev_queue = type { i32 }
%struct.udev_list_entry = type { i32 }
define i32 @scan_failed(%struct.udev_enumerate* %0) {
%2 = alloca i32
%3 = alloca %struct.udev_enumerate*
%4 = alloca %struct.udev*
%5 = alloca %struct.udev_queue*
%6 = alloca %struct.udev_list_entry*
store %struct.udev_enumerate* %0, %struct.udev_enumerate** %3
%7 = load %struct.udev_enumerate*, %struct.udev_enumerate** %3
%8 = call %struct.udev* @udev_enumerate_get_udev(%struct.udev_enumerate* %7)
store %struct.udev* %8, %struct.udev** %4
%9 = load %struct.udev*, %struct.udev** %4
%10 = call %struct.udev_queue* @udev_queue_new(%struct.udev* %9)
store %struct.udev_queue* %10, %struct.udev_queue** %5
%11 = load %struct.udev_queue*, %struct.udev_queue** %5
%12 = icmp eq %struct.udev_queue* %11, null
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 -1, i32* %2
br label %29
14: ; preds = %1
%15 = load %struct.udev_queue*, %struct.udev_queue** %5
%16 = call %struct.udev_list_entry* @udev_queue_get_failed_list_entry(%struct.udev_queue* %15)
store %struct.udev_list_entry* %16, %struct.udev_list_entry** %6
br label %17
17: ; preds = %25, %14
%18 = load %struct.udev_list_entry*, %struct.udev_list_entry** %6
%19 = icmp ne %struct.udev_list_entry* %18, null
br i1 %19, label %20, label %28
20: ; preds = %17
%21 = load %struct.udev_enumerate*, %struct.udev_enumerate** %3
%22 = load %struct.udev_list_entry*, %struct.udev_list_entry** %6
%23 = call i32 @udev_list_entry_get_name(%struct.udev_list_entry* %22)
%24 = call i32 @udev_enumerate_add_syspath(%struct.udev_enumerate* %21, i32 %23)
br label %25
25: ; preds = %20
%26 = load %struct.udev_list_entry*, %struct.udev_list_entry** %6
%27 = call %struct.udev_list_entry* @udev_list_entry_get_next(%struct.udev_list_entry* %26)
store %struct.udev_list_entry* %27, %struct.udev_list_entry** %6
br label %17
28: ; preds = %17
store i32 0, i32* %2
br label %29
29: ; preds = %28, %13
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
%struct.udev_enumerate = type { i32 }
%struct.udev = type { i32 }
%struct.udev_queue = type { i32 }
%struct.udev_list_entry = type { i32 }
define i32 @scan_failed(%struct.udev_enumerate* %0) {
%2 = tail call %struct.udev* @udev_enumerate_get_udev(%struct.udev_enumerate* %0)
%3 = tail call %struct.udev_queue* @udev_queue_new(%struct.udev* %2)
%4 = icmp eq %struct.udev_queue* %3, null
br i1 %4, label %14, label %5
5: ; preds = %1
%6 = tail call %struct.udev_list_entry* @udev_queue_get_failed_list_entry(%struct.udev_queue* %3)
%7 = icmp eq %struct.udev_list_entry* %6, null
br i1 %7, label %14, label %8
8: ; preds = %5, %8
%9 = phi %struct.udev_list_entry* [ %12, %8 ], [ %6, %5 ]
%10 = tail call i32 @udev_list_entry_get_name(%struct.udev_list_entry* %9)
%11 = tail call i32 @udev_enumerate_add_syspath(%struct.udev_enumerate* %0, i32 %10)
%12 = tail call %struct.udev_list_entry* @udev_list_entry_get_next(%struct.udev_list_entry* %9)
%13 = icmp eq %struct.udev_list_entry* %12, null
br i1 %13, label %14, label %8
14: ; preds = %8, %5, %1
%15 = phi i32 [ -1, %1 ], [ 0, %5 ], [ 0, %8 ]
ret i32 %15
}