#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_syspath(struct udev *, char const *);
int /*<<< orphan*/ udev_device_unref(struct udev_device *);
int test_device(struct udev *udev, const char *syspath) {
  struct udev_device *device;
  printf("looking at device: %s\n", syspath);
  device = udev_device_new_from_syspath(udev, syspath);
  if (device == NULL) {
    printf("no device found\n");
    return -1;
  }
  print_device(device);
  udev_device_unref(device);
  return 0;
}


x86 assembly (clang, -O0):
<test_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <udev_device_new_from_syspath@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1198 <test_device+0x58>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <test_device+0x71>
mov    -0x20(%rbp),%rdi
call   1060 <print_device@plt>
mov    -0x20(%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>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xe9f(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <udev_device_new_from_syspath@plt>
test   %rax,%rax
je     1190 <test_device+0x40>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <print_device@plt>
mov    %rbx,%rdi
call   1060 <udev_device_unref@plt>
jmp    11a2 <test_device+0x52>
lea    0xe80(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.udev = type { i32 }
%struct.udev_device = type { i32 }
@.str = [23 x i8] c"looking at device: %s\0A\00"
@.str.1 = [17 x i8] c"no device found\0A\00"
define i32 @test_device(%struct.udev* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.udev*
%5 = alloca i8*
%6 = alloca %struct.udev_device*
store %struct.udev* %0, %struct.udev** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load %struct.udev*, %struct.udev** %4
%10 = load i8*, i8** %5
%11 = call %struct.udev_device* @udev_device_new_from_syspath(%struct.udev* %9, i8* %10)
store %struct.udev_device* %11, %struct.udev_device** %6
%12 = load %struct.udev_device*, %struct.udev_device** %6
%13 = icmp eq %struct.udev_device* %12, null
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %21
16: ; preds = %2
%17 = load %struct.udev_device*, %struct.udev_device** %6
%18 = call i32 @print_device(%struct.udev_device* %17)
%19 = load %struct.udev_device*, %struct.udev_device** %6
%20 = call i32 @udev_device_unref(%struct.udev_device* %19)
store i32 0, i32* %3
br label %21
21: ; preds = %16, %14
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
%struct.udev = type { i32 }
%struct.udev_device = type { i32 }
@.str = [23 x i8] c"looking at device: %s\0A\00"
@str = [16 x i8] c"no device found\00"
define i32 @test_device(%struct.udev* %0, i8* %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %1)
%4 = tail call %struct.udev_device* @udev_device_new_from_syspath(%struct.udev* %0, i8* %1)
%5 = icmp eq %struct.udev_device* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %11
8: ; preds = %2
%9 = tail call i32 @print_device(%struct.udev_device* %4)
%10 = tail call i32 @udev_device_unref(%struct.udev_device* %4)
br label %11
11: ; preds = %8, %6
%12 = phi i32 [ -1, %6 ], [ 0, %8 ]
ret i32 %12
}