#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 timespec {
  scalar_t__ tv_nsec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ udev_device_get_action(struct udev_device *);
int /*<<< orphan*/ udev_device_get_devpath(struct udev_device *);
struct udev_list_entry *
udev_device_get_properties_list_entry(struct udev_device *);
int /*<<< orphan*/ udev_device_get_subsystem(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 *);
char *udev_list_entry_get_value(struct udev_list_entry *);
void print_device(struct udev_device *device, const char *source, int prop) {
  struct timespec ts;
  clock_gettime(CLOCK_MONOTONIC, &ts);
  printf("%-6s[%llu.%06u] %-8s %s (%s)\n", source,
         (unsigned long long)ts.tv_sec, (unsigned int)ts.tv_nsec / 1000,
         udev_device_get_action(device), udev_device_get_devpath(device),
         udev_device_get_subsystem(device));
  if (prop) {
    struct udev_list_entry *list_entry;
    for (list_entry = udev_device_get_properties_list_entry(device);
         list_entry != NULL; list_entry = udev_list_entry_get_next(list_entry))
      printf("%s=%s\n", udev_list_entry_get_name(list_entry),
             udev_list_entry_get_value(list_entry));
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<print_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <udev_device_get_action@plt>
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   10b0 <udev_device_get_devpath@plt>
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <udev_device_get_subsystem@plt>
mov    -0x50(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x3c(%rbp),%ecx
mov    -0x38(%rbp),%r8d
mov    -0x34(%rbp),%r9d
lea    0xdf0(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
je     1287 <print_device+0xf7>
mov    -0x8(%rbp),%rdi
call   1090 <udev_device_get_properties_list_entry@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1279 <print_device+0xe9>
mov    -0x30(%rbp),%rdi
call   10a0 <udev_list_entry_get_name@plt>
mov    %rax,-0x58(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <udev_list_entry_get_value@plt>
mov    -0x58(%rbp),%rsi
mov    %rax,%rdx
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1080 <udev_list_entry_get_next@plt>
mov    %rax,-0x30(%rbp)
jmp    1231 <print_device+0xa1>
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_device>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,0x14(%rsp)
mov    %rsi,%r15
mov    %rdi,%rbx
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0x18(%rsp),%rsi
call   1040 <clock_gettime@plt>
mov    0x20(%rsp),%r12
mov    0x18(%rsp),%eax
imul   $0x10624dd3,%rax,%rbp
shr    $0x26,%rbp
mov    %rbx,%rdi
call   1080 <udev_device_get_action@plt>
mov    %eax,%r13d
mov    %rbx,%rdi
call   10c0 <udev_device_get_devpath@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1060 <udev_device_get_subsystem@plt>
mov    %eax,(%rsp)
lea    0xdf9(%rip),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %ebp,%ecx
mov    %r13d,%r8d
mov    %r14d,%r9d
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,0x14(%rsp)
je     127d <print_device+0xdd>
mov    %rbx,%rdi
call   10a0 <udev_device_get_properties_list_entry@plt>
test   %rax,%rax
je     1273 <print_device+0xd3>
mov    %rax,%rbx
lea    0xde4(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10b0 <udev_list_entry_get_name@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1070 <udev_list_entry_get_value@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1090 <udev_list_entry_get_next@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1240 <print_device+0xa0>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.udev_device = type { i32 }
%struct.timespec = type { i64, i64 }
%struct.udev_list_entry = type { i32 }
@CLOCK_MONOTONIC = global i32 0
@.str = [30 x i8] c"%-6s[%llu.%06u] %-8s %s (%s)\0A\00"
@.str.1 = [7 x i8] c"%s=%s\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @print_device(%struct.udev_device* %0, i8* %1, i32 %2) {
%4 = alloca %struct.udev_device*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.timespec
%8 = alloca %struct.udev_list_entry*
store %struct.udev_device* %0, %struct.udev_device** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i32, i32* @CLOCK_MONOTONIC
%10 = call i32 @clock_gettime(i32 %9, %struct.timespec* %7)
%11 = load i8*, i8** %5
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
%13 = load i64, i64* %12
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%15 = load i64, i64* %14
%16 = trunc i64 %15 to i32
%17 = udiv i32 %16, 1000
%18 = load %struct.udev_device*, %struct.udev_device** %4
%19 = call i32 @udev_device_get_action(%struct.udev_device* %18)
%20 = load %struct.udev_device*, %struct.udev_device** %4
%21 = call i32 @udev_device_get_devpath(%struct.udev_device* %20)
%22 = load %struct.udev_device*, %struct.udev_device** %4
%23 = call i32 @udev_device_get_subsystem(%struct.udev_device* %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %11, i64 %13, i32 %17, i32 %19, i32 %21, i32 %23)
%25 = load i32, i32* %6
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %44
27: ; preds = %3
%28 = load %struct.udev_device*, %struct.udev_device** %4
%29 = call %struct.udev_list_entry* @udev_device_get_properties_list_entry(%struct.udev_device* %28)
store %struct.udev_list_entry* %29, %struct.udev_list_entry** %8
br label %30
30: ; preds = %39, %27
%31 = load %struct.udev_list_entry*, %struct.udev_list_entry** %8
%32 = icmp ne %struct.udev_list_entry* %31, null
br i1 %32, label %33, label %42
33: ; preds = %30
%34 = load %struct.udev_list_entry*, %struct.udev_list_entry** %8
%35 = call i8* @udev_list_entry_get_name(%struct.udev_list_entry* %34)
%36 = load %struct.udev_list_entry*, %struct.udev_list_entry** %8
%37 = call i8* @udev_list_entry_get_value(%struct.udev_list_entry* %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %35, i8* %37)
br label %39
39: ; preds = %33
%40 = load %struct.udev_list_entry*, %struct.udev_list_entry** %8
%41 = call %struct.udev_list_entry* @udev_list_entry_get_next(%struct.udev_list_entry* %40)
store %struct.udev_list_entry* %41, %struct.udev_list_entry** %8
br label %30
42: ; preds = %30
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %44
44: ; preds = %42, %3
ret void
}

LLVM IR (-O2):
%struct.udev_device = type { i32 }
%struct.timespec = type { i64, i64 }
%struct.udev_list_entry = type { i32 }
@CLOCK_MONOTONIC = global i32 0
@.str = [30 x i8] c"%-6s[%llu.%06u] %-8s %s (%s)\0A\00"
@.str.1 = [7 x i8] c"%s=%s\0A\00"
define void @print_device(%struct.udev_device* %0, i8* %1, i32 %2) {
%4 = alloca %struct.timespec
%5 = bitcast %struct.timespec* %4 to i8*
%6 = load i32, i32* @CLOCK_MONOTONIC
%7 = call i32 @clock_gettime(i32 %6, %struct.timespec* %4)
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 1
%9 = load i64, i64* %8
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
%11 = load i64, i64* %10
%12 = trunc i64 %11 to i32
%13 = udiv i32 %12, 1000
%14 = call i32 @udev_device_get_action(%struct.udev_device* %0)
%15 = call i32 @udev_device_get_devpath(%struct.udev_device* %0)
%16 = call i32 @udev_device_get_subsystem(%struct.udev_device* %0)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %1, i64 %9, i32 %13, i32 %14, i32 %15, i32 %16)
%18 = icmp eq i32 %2, 0
br i1 %18, label %31, label %19
19: ; preds = %3
%20 = call %struct.udev_list_entry* @udev_device_get_properties_list_entry(%struct.udev_device* %0)
%21 = icmp eq %struct.udev_list_entry* %20, null
br i1 %21, label %29, label %22
22: ; preds = %19, %22
%23 = phi %struct.udev_list_entry* [ %27, %22 ], [ %20, %19 ]
%24 = call i8* @udev_list_entry_get_name(%struct.udev_list_entry* %23)
%25 = call i8* @udev_list_entry_get_value(%struct.udev_list_entry* %23)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %24, i8* %25)
%27 = call %struct.udev_list_entry* @udev_list_entry_get_next(%struct.udev_list_entry* %23)
%28 = icmp eq %struct.udev_list_entry* %27, null
br i1 %28, label %29, label %22
29: ; preds = %22, %19
%30 = call i32 @putchar(i32 10)
br label %31
31: ; preds = %29, %3
ret void
}