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

/* Variables and functions */
int /*<<< orphan*/ print_device(struct udev_device *);
int /*<<< orphan*/ printf(char *);
struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *,
                                                           char *, char *);
int /*<<< orphan*/ udev_device_unref(struct udev_device *);
int test_device_subsys_name(struct udev *udev) {
  struct udev_device *device;
  printf("looking up device: 'block':'sda'\n");
  device = udev_device_new_from_subsystem_sysname(udev, "block", "sda");
  if (device == NULL)
    return -1;
  print_device(device);
  udev_device_unref(device);
  printf("looking up device: 'subsystem':'pci'\n");
  device = udev_device_new_from_subsystem_sysname(udev, "subsystem", "pci");
  if (device == NULL)
    return -1;
  print_device(device);
  udev_device_unref(device);
  printf("looking up device: 'drivers':'scsi:sd'\n");
  device = udev_device_new_from_subsystem_sysname(udev, "drivers", "scsi:sd");
  if (device == NULL)
    return -1;
  print_device(device);
  udev_device_unref(device);
  printf("looking up device: 'module':'printk'\n");
  device = udev_device_new_from_subsystem_sysname(udev, "module", "printk");
  if (device == NULL)
    return -1;
  print_device(device);
  udev_device_unref(device);
  return 0;
}


x86 assembly (clang, -O0):
<test_device_subsys_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xead(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xebf(%rip),%rsi
lea    0xebe(%rip),%rdx
call   1030 <udev_device_new_from_subsystem_sysname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118a <test_device_subsys_name+0x4a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1293 <test_device_subsys_name+0x153>
mov    -0x18(%rbp),%rdi
call   1060 <print_device@plt>
mov    -0x18(%rbp),%rdi
call   1050 <udev_device_unref@plt>
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe9f(%rip),%rsi
lea    0xea2(%rip),%rdx
call   1030 <udev_device_new_from_subsystem_sysname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11da <test_device_subsys_name+0x9a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1293 <test_device_subsys_name+0x153>
mov    -0x18(%rbp),%rdi
call   1060 <print_device@plt>
mov    -0x18(%rbp),%rdi
call   1050 <udev_device_unref@plt>
lea    0xe6d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe85(%rip),%rsi
lea    0xe86(%rip),%rdx
call   1030 <udev_device_new_from_subsystem_sysname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    122a <test_device_subsys_name+0xea>
movl   $0xffffffff,-0x4(%rbp)
jmp    1293 <test_device_subsys_name+0x153>
mov    -0x18(%rbp),%rdi
call   1060 <print_device@plt>
mov    -0x18(%rbp),%rdi
call   1050 <udev_device_unref@plt>
lea    0xe55(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe6b(%rip),%rsi
lea    0xe6b(%rip),%rdx
call   1030 <udev_device_new_from_subsystem_sysname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    127a <test_device_subsys_name+0x13a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1293 <test_device_subsys_name+0x153>
mov    -0x18(%rbp),%rdi
call   1060 <print_device@plt>
mov    -0x18(%rbp),%rdi
call   1050 <udev_device_unref@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_device_subsys_name>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    0xee8(%rip),%rdi
call   1030 <puts@plt>
lea    0xea6(%rip),%rsi
lea    0xea5(%rip),%rdx
mov    %rbx,%rdi
call   1040 <udev_device_new_from_subsystem_sysname@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
je     1240 <test_device_subsys_name+0x100>
mov    %rax,%rbp
mov    %rax,%rdi
call   1060 <print_device@plt>
mov    %rbp,%rdi
call   1050 <udev_device_unref@plt>
lea    0xec5(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6c(%rip),%rsi
lea    0xe6f(%rip),%rdx
mov    %rbx,%rdi
call   1040 <udev_device_new_from_subsystem_sysname@plt>
test   %rax,%rax
je     1240 <test_device_subsys_name+0x100>
mov    %rax,%rbp
mov    %rax,%rdi
call   1060 <print_device@plt>
mov    %rbp,%rdi
call   1050 <udev_device_unref@plt>
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
lea    0xe3c(%rip),%rsi
lea    0xe3d(%rip),%rdx
mov    %rbx,%rdi
call   1040 <udev_device_new_from_subsystem_sysname@plt>
test   %rax,%rax
je     1240 <test_device_subsys_name+0x100>
mov    %rax,%rbp
mov    %rax,%rdi
call   1060 <print_device@plt>
mov    %rbp,%rdi
call   1050 <udev_device_unref@plt>
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
lea    0xe12(%rip),%rsi
lea    0xe12(%rip),%rdx
mov    %rbx,%rdi
call   1040 <udev_device_new_from_subsystem_sysname@plt>
test   %rax,%rax
je     1240 <test_device_subsys_name+0x100>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <print_device@plt>
mov    %rbx,%rdi
call   1050 <udev_device_unref@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.udev = type { i32 }
%struct.udev_device = type { i32 }
@.str = [34 x i8] c"looking up device: 'block':'sda'\0A\00"
@.str.1 = [6 x i8] c"block\00"
@.str.2 = [4 x i8] c"sda\00"
@.str.3 = [38 x i8] c"looking up device: 'subsystem':'pci'\0A\00"
@.str.4 = [10 x i8] c"subsystem\00"
@.str.5 = [4 x i8] c"pci\00"
@.str.6 = [40 x i8] c"looking up device: 'drivers':'scsi:sd'\0A\00"
@.str.7 = [8 x i8] c"drivers\00"
@.str.8 = [8 x i8] c"scsi:sd\00"
@.str.9 = [38 x i8] c"looking up device: 'module':'printk'\0A\00"
@.str.10 = [7 x i8] c"module\00"
@.str.11 = [7 x i8] c"printk\00"
define i32 @test_device_subsys_name(%struct.udev* %0) {
%2 = alloca i32
%3 = alloca %struct.udev*
%4 = alloca %struct.udev_device*
store %struct.udev* %0, %struct.udev** %3
%5 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%6 = load %struct.udev*, %struct.udev** %3
%7 = call %struct.udev_device* @udev_device_new_from_subsystem_sysname(%struct.udev* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store %struct.udev_device* %7, %struct.udev_device** %4
%8 = load %struct.udev_device*, %struct.udev_device** %4
%9 = icmp eq %struct.udev_device* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %49
11: ; preds = %1
%12 = load %struct.udev_device*, %struct.udev_device** %4
%13 = call i32 @print_device(%struct.udev_device* %12)
%14 = load %struct.udev_device*, %struct.udev_device** %4
%15 = call i32 @udev_device_unref(%struct.udev_device* %14)
%16 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
%17 = load %struct.udev*, %struct.udev** %3
%18 = call %struct.udev_device* @udev_device_new_from_subsystem_sysname(%struct.udev* %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
store %struct.udev_device* %18, %struct.udev_device** %4
%19 = load %struct.udev_device*, %struct.udev_device** %4
%20 = icmp eq %struct.udev_device* %19, null
br i1 %20, label %21, label %22
21: ; preds = %11
store i32 -1, i32* %2
br label %49
22: ; preds = %11
%23 = load %struct.udev_device*, %struct.udev_device** %4
%24 = call i32 @print_device(%struct.udev_device* %23)
%25 = load %struct.udev_device*, %struct.udev_device** %4
%26 = call i32 @udev_device_unref(%struct.udev_device* %25)
%27 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0))
%28 = load %struct.udev*, %struct.udev** %3
%29 = call %struct.udev_device* @udev_device_new_from_subsystem_sysname(%struct.udev* %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
store %struct.udev_device* %29, %struct.udev_device** %4
%30 = load %struct.udev_device*, %struct.udev_device** %4
%31 = icmp eq %struct.udev_device* %30, null
br i1 %31, label %32, label %33
32: ; preds = %22
store i32 -1, i32* %2
br label %49
33: ; preds = %22
%34 = load %struct.udev_device*, %struct.udev_device** %4
%35 = call i32 @print_device(%struct.udev_device* %34)
%36 = load %struct.udev_device*, %struct.udev_device** %4
%37 = call i32 @udev_device_unref(%struct.udev_device* %36)
%38 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.9, i64 0, i64 0))
%39 = load %struct.udev*, %struct.udev** %3
%40 = call %struct.udev_device* @udev_device_new_from_subsystem_sysname(%struct.udev* %39, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0))
store %struct.udev_device* %40, %struct.udev_device** %4
%41 = load %struct.udev_device*, %struct.udev_device** %4
%42 = icmp eq %struct.udev_device* %41, null
br i1 %42, label %43, label %44
43: ; preds = %33
store i32 -1, i32* %2
br label %49
44: ; preds = %33
%45 = load %struct.udev_device*, %struct.udev_device** %4
%46 = call i32 @print_device(%struct.udev_device* %45)
%47 = load %struct.udev_device*, %struct.udev_device** %4
%48 = call i32 @udev_device_unref(%struct.udev_device* %47)
store i32 0, i32* %2
br label %49
49: ; preds = %44, %43, %32, %21, %10
%50 = load i32, i32* %2
ret i32 %50
}

LLVM IR (-O2):
%struct.udev = type { i32 }
%struct.udev_device = type { i32 }
@.str.1 = [6 x i8] c"block\00"
@.str.2 = [4 x i8] c"sda\00"
@.str.4 = [10 x i8] c"subsystem\00"
@.str.5 = [4 x i8] c"pci\00"
@.str.7 = [8 x i8] c"drivers\00"
@.str.8 = [8 x i8] c"scsi:sd\00"
@.str.10 = [7 x i8] c"module\00"
@.str.11 = [7 x i8] c"printk\00"
@str = [33 x i8] c"looking up device: 'block':'sda'\00"
@str.12 = [37 x i8] c"looking up device: 'subsystem':'pci'\00"
@str.13 = [39 x i8] c"looking up device: 'drivers':'scsi:sd'\00"
@str.14 = [37 x i8] c"looking up device: 'module':'printk'\00"
define i32 @test_device_subsys_name(%struct.udev* %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%3 = tail call %struct.udev_device* @udev_device_new_from_subsystem_sysname(%struct.udev* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%4 = icmp eq %struct.udev_device* %3, null
br i1 %4, label %26, label %5
5: ; preds = %1
%6 = tail call i32 @print_device(%struct.udev_device* %3)
%7 = tail call i32 @udev_device_unref(%struct.udev_device* %3)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.12, i64 0, i64 0))
%9 = tail call %struct.udev_device* @udev_device_new_from_subsystem_sysname(%struct.udev* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%10 = icmp eq %struct.udev_device* %9, null
br i1 %10, label %26, label %11
11: ; preds = %5
%12 = tail call i32 @print_device(%struct.udev_device* %9)
%13 = tail call i32 @udev_device_unref(%struct.udev_device* %9)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.13, i64 0, i64 0))
%15 = tail call %struct.udev_device* @udev_device_new_from_subsystem_sysname(%struct.udev* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
%16 = icmp eq %struct.udev_device* %15, null
br i1 %16, label %26, label %17
17: ; preds = %11
%18 = tail call i32 @print_device(%struct.udev_device* %15)
%19 = tail call i32 @udev_device_unref(%struct.udev_device* %15)
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.14, i64 0, i64 0))
%21 = tail call %struct.udev_device* @udev_device_new_from_subsystem_sysname(%struct.udev* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0))
%22 = icmp eq %struct.udev_device* %21, null
br i1 %22, label %26, label %23
23: ; preds = %17
%24 = tail call i32 @print_device(%struct.udev_device* %21)
%25 = tail call i32 @udev_device_unref(%struct.udev_device* %21)
br label %26
26: ; preds = %17, %11, %5, %1, %23
%27 = phi i32 [ 0, %23 ], [ -1, %1 ], [ -1, %5 ], [ -1, %11 ], [ -1, %17 ]
ret i32 %27
}