#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 errno;
char *malloc(scalar_t__);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
char *udev_device_get_devnode(struct udev_device *);
struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *,
                                                           char *, char *);
int /*<<< orphan*/ udev_device_unref(struct udev_device *);
struct udev *udev_new();
int /*<<< orphan*/ udev_unref(struct udev *);
char *suinput_get_uinput_path(void) {
  struct udev *udev;
  struct udev_device *udev_dev;
  const char *devnode;
  char *retval = NULL;
  int orig_errno;
  if ((udev = udev_new()) == NULL) {
    return NULL;
  }
  udev_dev = udev_device_new_from_subsystem_sysname(udev, "misc", "uinput");
  if (udev_dev == NULL) {
    goto out;
  }
  if ((devnode = udev_device_get_devnode(udev_dev)) == NULL) {
    goto out;
  }
  if ((retval = malloc(strlen(devnode) + 1)) == NULL) {
    goto out;
  }
  strcpy(retval, devnode);
out:
  orig_errno = errno;
  udev_device_unref(udev_dev);
  udev_unref(udev);
  errno = orig_errno;
  return retval;
}


x86 assembly (clang, -O0):
<suinput_get_uinput_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x28(%rbp)
mov    $0x0,%al
call   1030 <udev_new@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11b2 <suinput_get_uinput_path+0x32>
movq   $0x0,-0x8(%rbp)
jmp    1260 <suinput_get_uinput_path+0xe0>
mov    -0x10(%rbp),%rdi
lea    0xe43(%rip),%rsi
lea    0xe41(%rip),%rdx
call   1050 <udev_device_new_from_subsystem_sysname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11dd <suinput_get_uinput_path+0x5d>
jmp    122e <suinput_get_uinput_path+0xae>
mov    -0x18(%rbp),%rdi
call   10a0 <udev_device_get_devnode@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11f9 <suinput_get_uinput_path+0x79>
jmp    122e <suinput_get_uinput_path+0xae>
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1221 <suinput_get_uinput_path+0xa1>
jmp    122e <suinput_get_uinput_path+0xae>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <udev_device_unref@plt>
mov    -0x10(%rbp),%rdi
call   1070 <udev_unref@plt>
mov    -0x2c(%rbp),%ecx
mov    0x2d8a(%rip),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<suinput_get_uinput_path>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <udev_new@plt>
test   %rax,%rax
je     120e <suinput_get_uinput_path+0x8e>
mov    %rax,%r15
lea    0xe60(%rip),%rsi
lea    0xe5e(%rip),%rdx
mov    %rax,%rdi
call   1050 <udev_device_new_from_subsystem_sysname@plt>
mov    %rax,%r14
test   %rax,%rax
je     11ed <suinput_get_uinput_path+0x6d>
mov    %r14,%rdi
call   10a0 <udev_device_get_devnode@plt>
test   %rax,%rax
je     11ed <suinput_get_uinput_path+0x6d>
mov    %rax,%r12
mov    %rax,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%rdi
call   1080 <malloc@plt>
test   %rax,%rax
je     11ed <suinput_get_uinput_path+0x6d>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
jmp    11ef <suinput_get_uinput_path+0x6f>
xor    %ebx,%ebx
mov    0x2dea(%rip),%r12
mov    (%r12),%ebp
mov    %r14,%rdi
call   1090 <udev_device_unref@plt>
mov    %r15,%rdi
call   1070 <udev_unref@plt>
mov    %ebp,(%r12)
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.udev = type { i32 }
%struct.udev_device = type { i32 }
@.str = [5 x i8] c"misc\00"
@.str.1 = [7 x i8] c"uinput\00"
@errno = global i32 0
define i8* @suinput_get_uinput_path() {
%1 = alloca i8*
%2 = alloca %struct.udev*
%3 = alloca %struct.udev_device*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* null, i8** %5
%7 = call %struct.udev* (...) @udev_new()
store %struct.udev* %7, %struct.udev** %2
%8 = icmp eq %struct.udev* %7, null
br i1 %8, label %9, label %10
9: ; preds = %0
store i8* null, i8** %1
br label %40
10: ; preds = %0
%11 = load %struct.udev*, %struct.udev** %2
%12 = call %struct.udev_device* @udev_device_new_from_subsystem_sysname(%struct.udev* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store %struct.udev_device* %12, %struct.udev_device** %3
%13 = load %struct.udev_device*, %struct.udev_device** %3
%14 = icmp eq %struct.udev_device* %13, null
br i1 %14, label %15, label %16
15: ; preds = %10
br label %32
16: ; preds = %10
%17 = load %struct.udev_device*, %struct.udev_device** %3
%18 = call i8* @udev_device_get_devnode(%struct.udev_device* %17)
store i8* %18, i8** %4
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %21
20: ; preds = %16
br label %32
21: ; preds = %16
%22 = load i8*, i8** %4
%23 = call i64 @strlen(i8* %22)
%24 = add nsw i64 %23, 1
%25 = call i8* @malloc(i64 %24)
store i8* %25, i8** %5
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %28
27: ; preds = %21
br label %32
28: ; preds = %21
%29 = load i8*, i8** %5
%30 = load i8*, i8** %4
%31 = call i32 @strcpy(i8* %29, i8* %30)
br label %32
32: ; preds = %28, %27, %20, %15
%33 = load i32, i32* @errno
store i32 %33, i32* %6
%34 = load %struct.udev_device*, %struct.udev_device** %3
%35 = call i32 @udev_device_unref(%struct.udev_device* %34)
%36 = load %struct.udev*, %struct.udev** %2
%37 = call i32 @udev_unref(%struct.udev* %36)
%38 = load i32, i32* %6
store i32 %38, i32* @errno
%39 = load i8*, i8** %5
store i8* %39, i8** %1
br label %40
40: ; preds = %32, %9
%41 = load i8*, i8** %1
ret i8* %41
}

LLVM IR (-O2):
%struct.udev = type { i32 }
%struct.udev_device = type { i32 }
@.str = [5 x i8] c"misc\00"
@.str.1 = [7 x i8] c"uinput\00"
@errno = global i32 0
define i8* @suinput_get_uinput_path() {
%1 = tail call %struct.udev* (...) @udev_new()
%2 = icmp eq %struct.udev* %1, null
br i1 %2, label %21, label %3
3: ; preds = %0
%4 = tail call %struct.udev_device* @udev_device_new_from_subsystem_sysname(%struct.udev* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq %struct.udev_device* %4, null
br i1 %5, label %16, label %6
6: ; preds = %3
%7 = tail call i8* @udev_device_get_devnode(%struct.udev_device* %4)
%8 = icmp eq i8* %7, null
br i1 %8, label %16, label %9
9: ; preds = %6
%10 = tail call i64 @strlen(i8* %7)
%11 = add nsw i64 %10, 1
%12 = tail call i8* @malloc(i64 %11)
%13 = icmp eq i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %9
%15 = tail call i32 @strcpy(i8* %12, i8* %7)
br label %16
16: ; preds = %9, %6, %3, %14
%17 = phi i8* [ null, %3 ], [ null, %6 ], [ null, %9 ], [ %12, %14 ]
%18 = load i32, i32* @errno
%19 = tail call i32 @udev_device_unref(%struct.udev_device* %4)
%20 = tail call i32 @udev_unref(%struct.udev* %1)
store i32 %18, i32* @errno
br label %21
21: ; preds = %0, %16
%22 = phi i8* [ %17, %16 ], [ null, %0 ]
ret i8* %22
}