#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;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
char *udev_device_get_subsystem(struct udev_device *);
char *udev_device_get_syspath(struct udev_device *);
struct udev_device *udev_device_new_from_syspath(int /*<<< orphan*/,
                                                 int /*<<< orphan*/);
int /*<<< orphan*/ udev_device_unref(struct udev_device *);
struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *);
int /*<<< orphan*/ 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 *);
int test_enumerate_print_list(struct udev_enumerate *enumerate) {
  struct udev_list_entry *list_entry;
  int count = 0;
  for (list_entry = udev_enumerate_get_list_entry(enumerate);
       list_entry != NULL; list_entry = udev_list_entry_get_next(list_entry)) {
    struct udev_device *device;
    device = udev_device_new_from_syspath(udev_enumerate_get_udev(enumerate),
                                          udev_list_entry_get_name(list_entry));
    if (device != NULL) {
      printf("device: '%s' (%s)\n", udev_device_get_syspath(device),
             udev_device_get_subsystem(device));
      udev_device_unref(device);
      count++;
    }
  }
  printf("found %i devices\n\n", count);
  return count;
}


x86 assembly (clang, -O0):
<test_enumerate_print_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <udev_enumerate_get_list_entry@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     123d <test_enumerate_print_list+0xad>
mov    -0x8(%rbp),%rdi
call   1090 <udev_enumerate_get_udev@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   10b0 <udev_list_entry_get_name@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%esi
call   1070 <udev_device_new_from_syspath@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1226 <test_enumerate_print_list+0x96>
mov    -0x20(%rbp),%rdi
call   1030 <udev_device_get_syspath@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <udev_device_get_subsystem@plt>
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <udev_device_unref@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    122b <test_enumerate_print_list+0x9b>
mov    -0x10(%rbp),%rdi
call   1060 <udev_list_entry_get_next@plt>
mov    %rax,-0x10(%rbp)
jmp    11b0 <test_enumerate_print_list+0x20>
mov    -0x14(%rbp),%esi
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_enumerate_print_list>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1080 <udev_enumerate_get_list_entry@plt>
test   %rax,%rax
je     1224 <test_enumerate_print_list+0x94>
mov    %rax,%rbx
lea    0xe4e(%rip),%r15
xor    %r12d,%r12d
jmp    11d0 <test_enumerate_print_list+0x40>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <udev_list_entry_get_next@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1227 <test_enumerate_print_list+0x97>
mov    %r14,%rdi
call   1090 <udev_enumerate_get_udev@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   10b0 <udev_list_entry_get_name@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1070 <udev_device_new_from_syspath@plt>
test   %rax,%rax
je     11c0 <test_enumerate_print_list+0x30>
mov    %rax,%rbp
mov    %rax,%rdi
call   1030 <udev_device_get_syspath@plt>
mov    %rax,%r13
mov    %rbp,%rdi
call   1050 <udev_device_get_subsystem@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
call   10a0 <udev_device_unref@plt>
add    $0x1,%r12d
jmp    11c0 <test_enumerate_print_list+0x30>
xor    %r12d,%r12d
lea    0xde5(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.udev_enumerate = type { i32 }
%struct.udev_list_entry = type { i32 }
%struct.udev_device = type { i32 }
@.str = [19 x i8] c"device: '%s' (%s)\0A\00"
@.str.1 = [19 x i8] c"found %i devices\0A\0A\00"
define i32 @test_enumerate_print_list(%struct.udev_enumerate* %0) {
%2 = alloca %struct.udev_enumerate*
%3 = alloca %struct.udev_list_entry*
%4 = alloca i32
%5 = alloca %struct.udev_device*
store %struct.udev_enumerate* %0, %struct.udev_enumerate** %2
store i32 0, i32* %4
%6 = load %struct.udev_enumerate*, %struct.udev_enumerate** %2
%7 = call %struct.udev_list_entry* @udev_enumerate_get_list_entry(%struct.udev_enumerate* %6)
store %struct.udev_list_entry* %7, %struct.udev_list_entry** %3
br label %8
8: ; preds = %30, %1
%9 = load %struct.udev_list_entry*, %struct.udev_list_entry** %3
%10 = icmp ne %struct.udev_list_entry* %9, null
br i1 %10, label %11, label %33
11: ; preds = %8
%12 = load %struct.udev_enumerate*, %struct.udev_enumerate** %2
%13 = call i32 @udev_enumerate_get_udev(%struct.udev_enumerate* %12)
%14 = load %struct.udev_list_entry*, %struct.udev_list_entry** %3
%15 = call i32 @udev_list_entry_get_name(%struct.udev_list_entry* %14)
%16 = call %struct.udev_device* @udev_device_new_from_syspath(i32 %13, i32 %15)
store %struct.udev_device* %16, %struct.udev_device** %5
%17 = load %struct.udev_device*, %struct.udev_device** %5
%18 = icmp ne %struct.udev_device* %17, null
br i1 %18, label %19, label %29
19: ; preds = %11
%20 = load %struct.udev_device*, %struct.udev_device** %5
%21 = call i8* @udev_device_get_syspath(%struct.udev_device* %20)
%22 = load %struct.udev_device*, %struct.udev_device** %5
%23 = call i8* @udev_device_get_subsystem(%struct.udev_device* %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %23)
%25 = load %struct.udev_device*, %struct.udev_device** %5
%26 = call i32 @udev_device_unref(%struct.udev_device* %25)
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %29
29: ; preds = %19, %11
br label %30
30: ; preds = %29
%31 = load %struct.udev_list_entry*, %struct.udev_list_entry** %3
%32 = call %struct.udev_list_entry* @udev_list_entry_get_next(%struct.udev_list_entry* %31)
store %struct.udev_list_entry* %32, %struct.udev_list_entry** %3
br label %8
33: ; preds = %8
%34 = load i32, i32* %4
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
%struct.udev_enumerate = type { i32 }
%struct.udev_list_entry = type { i32 }
%struct.udev_device = type { i32 }
@.str = [19 x i8] c"device: '%s' (%s)\0A\00"
@.str.1 = [19 x i8] c"found %i devices\0A\0A\00"
define i32 @test_enumerate_print_list(%struct.udev_enumerate* %0) {
%2 = tail call %struct.udev_list_entry* @udev_enumerate_get_list_entry(%struct.udev_enumerate* %0)
%3 = icmp eq %struct.udev_list_entry* %2, null
br i1 %3, label %21, label %4
4: ; preds = %1, %17
%5 = phi %struct.udev_list_entry* [ %19, %17 ], [ %2, %1 ]
%6 = phi i32 [ %18, %17 ], [ 0, %1 ]
%7 = tail call i32 @udev_enumerate_get_udev(%struct.udev_enumerate* %0)
%8 = tail call i32 @udev_list_entry_get_name(%struct.udev_list_entry* %5)
%9 = tail call %struct.udev_device* @udev_device_new_from_syspath(i32 %7, i32 %8)
%10 = icmp eq %struct.udev_device* %9, null
br i1 %10, label %17, label %11
11: ; preds = %4
%12 = tail call i8* @udev_device_get_syspath(%struct.udev_device* %9)
%13 = tail call i8* @udev_device_get_subsystem(%struct.udev_device* %9)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %13)
%15 = tail call i32 @udev_device_unref(%struct.udev_device* %9)
%16 = add nsw i32 %6, 1
br label %17
17: ; preds = %11, %4
%18 = phi i32 [ %16, %11 ], [ %6, %4 ]
%19 = tail call %struct.udev_list_entry* @udev_list_entry_get_next(%struct.udev_list_entry* %5)
%20 = icmp eq %struct.udev_list_entry* %19, null
br i1 %20, label %21, label %4
21: ; preds = %17, %1
%22 = phi i32 [ 0, %1 ], [ %18, %17 ]
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %22)
ret i32 %22
}