#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 timezone {
  int dummy;
};
struct timeval {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, struct timezone *);
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 env) {
  struct timeval tv;
  struct timezone tz;
  gettimeofday(&tv, &tz);
  printf("%-6s[%llu.%06u] %-8s %s (%s)\n", source,
         (unsigned long long)tv.tv_sec, (unsigned int)tv.tv_usec,
         udev_device_get_action(device), udev_device_get_devpath(device),
         udev_device_get_subsystem(device));
  if (env) {
    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    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <gettimeofday@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rax
mov    %eax,-0x44(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <udev_device_get_action@plt>
mov    %eax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   10b0 <udev_device_get_devpath@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <udev_device_get_subsystem@plt>
mov    -0x58(%rbp),%rsi
mov    -0x50(%rbp),%rdx
mov    -0x44(%rbp),%ecx
mov    -0x40(%rbp),%r8d
mov    -0x3c(%rbp),%r9d
lea    0xdfe(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
je     1279 <print_device+0xe9>
mov    -0x8(%rbp),%rdi
call   1090 <udev_device_get_properties_list_entry@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     126b <print_device+0xdb>
mov    -0x38(%rbp),%rdi
call   10a0 <udev_list_entry_get_name@plt>
mov    %rax,-0x60(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <udev_list_entry_get_value@plt>
mov    -0x60(%rbp),%rsi
mov    %rax,%rdx
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1080 <udev_list_entry_get_next@plt>
mov    %rax,-0x38(%rbp)
jmp    1223 <print_device+0x93>
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x70,%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,0xc(%rsp)
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0x18(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1050 <gettimeofday@plt>
mov    0x20(%rsp),%r13
mov    0x18(%rsp),%r12d
mov    %rbx,%rdi
call   1080 <udev_device_get_action@plt>
mov    %eax,%ebp
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    0xe08(%rip),%rdi
mov    %r15,%rsi
mov    %r13,%rdx
mov    %r12d,%ecx
mov    %ebp,%r8d
mov    %r14d,%r9d
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0xc(%rsp)
je     127b <print_device+0xdb>
mov    %rbx,%rdi
call   10a0 <udev_device_get_properties_list_entry@plt>
test   %rax,%rax
je     1263 <print_device+0xc3>
mov    %rax,%rbx
lea    0xdf2(%rip),%r14
nopl   0x0(%rax)
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   1040 <printf@plt>
mov    %rbx,%rdi
call   1090 <udev_list_entry_get_next@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1230 <print_device+0x90>
mov    $0xa,%edi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    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.timeval = type { i64, i64 }
%struct.timezone = type { i32 }
%struct.udev_list_entry = type { i32 }
@.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.timeval
%8 = alloca %struct.timezone
%9 = alloca %struct.udev_list_entry*
store %struct.udev_device* %0, %struct.udev_device** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = call i32 @gettimeofday(%struct.timeval* %7, %struct.timezone* %8)
%11 = load i8*, i8** %5
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%13 = load i64, i64* %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%15 = load i64, i64* %14
%16 = trunc i64 %15 to i32
%17 = load %struct.udev_device*, %struct.udev_device** %4
%18 = call i32 @udev_device_get_action(%struct.udev_device* %17)
%19 = load %struct.udev_device*, %struct.udev_device** %4
%20 = call i32 @udev_device_get_devpath(%struct.udev_device* %19)
%21 = load %struct.udev_device*, %struct.udev_device** %4
%22 = call i32 @udev_device_get_subsystem(%struct.udev_device* %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %11, i64 %13, i32 %16, i32 %18, i32 %20, i32 %22)
%24 = load i32, i32* %6
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %43
26: ; preds = %3
%27 = load %struct.udev_device*, %struct.udev_device** %4
%28 = call %struct.udev_list_entry* @udev_device_get_properties_list_entry(%struct.udev_device* %27)
store %struct.udev_list_entry* %28, %struct.udev_list_entry** %9
br label %29
29: ; preds = %38, %26
%30 = load %struct.udev_list_entry*, %struct.udev_list_entry** %9
%31 = icmp ne %struct.udev_list_entry* %30, null
br i1 %31, label %32, label %41
32: ; preds = %29
%33 = load %struct.udev_list_entry*, %struct.udev_list_entry** %9
%34 = call i8* @udev_list_entry_get_name(%struct.udev_list_entry* %33)
%35 = load %struct.udev_list_entry*, %struct.udev_list_entry** %9
%36 = call i8* @udev_list_entry_get_value(%struct.udev_list_entry* %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %34, i8* %36)
br label %38
38: ; preds = %32
%39 = load %struct.udev_list_entry*, %struct.udev_list_entry** %9
%40 = call %struct.udev_list_entry* @udev_list_entry_get_next(%struct.udev_list_entry* %39)
store %struct.udev_list_entry* %40, %struct.udev_list_entry** %9
br label %29
41: ; preds = %29
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %43
43: ; preds = %41, %3
ret void
}

LLVM IR (-O2):
%struct.udev_device = type { i32 }
%struct.timeval = type { i64, i64 }
%struct.timezone = type { i32 }
%struct.udev_list_entry = type { i32 }
@.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.timeval
%5 = alloca %struct.timezone
%6 = bitcast %struct.timeval* %4 to i8*
%7 = bitcast %struct.timezone* %5 to i8*
%8 = call i32 @gettimeofday(%struct.timeval* %4, %struct.timezone* %5)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%10 = load i64, i64* %9
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%12 = load i64, i64* %11
%13 = trunc i64 %12 to i32
%14 = tail call i32 @udev_device_get_action(%struct.udev_device* %0)
%15 = tail call i32 @udev_device_get_devpath(%struct.udev_device* %0)
%16 = tail call i32 @udev_device_get_subsystem(%struct.udev_device* %0)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %1, i64 %10, 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 = tail 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 = tail call i8* @udev_list_entry_get_name(%struct.udev_list_entry* %23)
%25 = tail call i8* @udev_list_entry_get_value(%struct.udev_list_entry* %23)
%26 = tail 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 = tail 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 = tail call i32 @putchar(i32 10)
br label %31
31: ; preds = %29, %3
ret void
}