#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 EINVAL;
int errno;
struct udev_device *udev_device_new_from_syspath(struct udev *, char const *);
int udev_device_read_uevent_file(struct udev_device *);
int udev_device_set_action(struct udev_device *, char const *);
int /*<<< orphan*/ udev_device_unref(struct udev_device *);
struct udev_device *udev_device_new_from_synthetic_event(struct udev *udev,
                                                         const char *syspath,
                                                         const char *action) {
  struct udev_device *ret;
  int r;
  if (!action) {
    errno = EINVAL;
    return NULL;
  }
  ret = udev_device_new_from_syspath(udev, syspath);
  if (!ret)
    return NULL;
  r = udev_device_read_uevent_file(ret);
  if (r < 0) {
    udev_device_unref(ret);
    errno = -r;
    return NULL;
  }
  r = udev_device_set_action(ret, action);
  if (r < 0) {
    udev_device_unref(ret);
    errno = -r;
    return NULL;
  }
  return ret;
}


x86 assembly (clang, -O0):
<udev_device_new_from_synthetic_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117e <udev_device_new_from_synthetic_event+0x3e>
mov    0x2e72(%rip),%rax
mov    (%rax),%ecx
mov    0x2e71(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    1227 <udev_device_new_from_synthetic_event+0xe7>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <udev_device_new_from_syspath@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a7 <udev_device_new_from_synthetic_event+0x67>
movq   $0x0,-0x8(%rbp)
jmp    1227 <udev_device_new_from_synthetic_event+0xe7>
mov    -0x28(%rbp),%rdi
call   1030 <udev_device_read_uevent_file@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    11e1 <udev_device_new_from_synthetic_event+0xa1>
mov    -0x28(%rbp),%rdi
call   1050 <udev_device_unref@plt>
xor    %ecx,%ecx
sub    -0x2c(%rbp),%ecx
mov    0x2e0e(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    1227 <udev_device_new_from_synthetic_event+0xe7>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <udev_device_set_action@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    121f <udev_device_new_from_synthetic_event+0xdf>
mov    -0x28(%rbp),%rdi
call   1050 <udev_device_unref@plt>
xor    %ecx,%ecx
sub    -0x2c(%rbp),%ecx
mov    0x2dd0(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    1227 <udev_device_new_from_synthetic_event+0xe7>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udev_device_new_from_synthetic_event>:
push   %rbp
push   %r14
push   %rbx
test   %rdx,%rdx
je     1182 <udev_device_new_from_synthetic_event+0x42>
mov    %rdx,%r14
call   1040 <udev_device_new_from_syspath@plt>
test   %rax,%rax
je     1194 <udev_device_new_from_synthetic_event+0x54>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <udev_device_read_uevent_file@plt>
test   %eax,%eax
js     1174 <udev_device_new_from_synthetic_event+0x34>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <udev_device_set_action@plt>
test   %eax,%eax
jns    1196 <udev_device_new_from_synthetic_event+0x56>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <udev_device_unref@plt>
neg    %ebp
jmp    118b <udev_device_new_from_synthetic_event+0x4b>
mov    0x2e4f(%rip),%rax
mov    (%rax),%ebp
mov    0x2e4e(%rip),%rax
mov    %ebp,(%rax)
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.udev_device = type { i32 }
%struct.udev = type { i32 }
@EINVAL = global i32 0
@errno = global i32 0
define %struct.udev_device* @udev_device_new_from_synthetic_event(%struct.udev* %0, i8* %1, i8* %2) {
%4 = alloca %struct.udev_device*
%5 = alloca %struct.udev*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.udev_device*
%9 = alloca i32
store %struct.udev* %0, %struct.udev** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %7
%11 = icmp ne i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %3
%13 = load i32, i32* @EINVAL
store i32 %13, i32* @errno
store %struct.udev_device* null, %struct.udev_device** %4
br label %44
14: ; preds = %3
%15 = load %struct.udev*, %struct.udev** %5
%16 = load i8*, i8** %6
%17 = call %struct.udev_device* @udev_device_new_from_syspath(%struct.udev* %15, i8* %16)
store %struct.udev_device* %17, %struct.udev_device** %8
%18 = load %struct.udev_device*, %struct.udev_device** %8
%19 = icmp ne %struct.udev_device* %18, null
br i1 %19, label %21, label %20
20: ; preds = %14
store %struct.udev_device* null, %struct.udev_device** %4
br label %44
21: ; preds = %14
%22 = load %struct.udev_device*, %struct.udev_device** %8
%23 = call i32 @udev_device_read_uevent_file(%struct.udev_device* %22)
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %21
%27 = load %struct.udev_device*, %struct.udev_device** %8
%28 = call i32 @udev_device_unref(%struct.udev_device* %27)
%29 = load i32, i32* %9
%30 = sub nsw i32 0, %29
store i32 %30, i32* @errno
store %struct.udev_device* null, %struct.udev_device** %4
br label %44
31: ; preds = %21
%32 = load %struct.udev_device*, %struct.udev_device** %8
%33 = load i8*, i8** %7
%34 = call i32 @udev_device_set_action(%struct.udev_device* %32, i8* %33)
store i32 %34, i32* %9
%35 = load i32, i32* %9
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %31
%38 = load %struct.udev_device*, %struct.udev_device** %8
%39 = call i32 @udev_device_unref(%struct.udev_device* %38)
%40 = load i32, i32* %9
%41 = sub nsw i32 0, %40
store i32 %41, i32* @errno
store %struct.udev_device* null, %struct.udev_device** %4
br label %44
42: ; preds = %31
%43 = load %struct.udev_device*, %struct.udev_device** %8
store %struct.udev_device* %43, %struct.udev_device** %4
br label %44
44: ; preds = %42, %37, %26, %20, %12
%45 = load %struct.udev_device*, %struct.udev_device** %4
ret %struct.udev_device* %45
}

LLVM IR (-O2):
%struct.udev_device = type { i32 }
%struct.udev = type { i32 }
@EINVAL = global i32 0
@errno = global i32 0
define %struct.udev_device* @udev_device_new_from_synthetic_event(%struct.udev* %0, i8* %1, i8* %2) {
%4 = icmp eq i8* %2, null
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = load i32, i32* @EINVAL
br label %22
7: ; preds = %3
%8 = tail call %struct.udev_device* @udev_device_new_from_syspath(%struct.udev* %0, i8* %1)
%9 = icmp eq %struct.udev_device* %8, null
br i1 %9, label %24, label %10
10: ; preds = %7
%11 = tail call i32 @udev_device_read_uevent_file(%struct.udev_device* %8)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = tail call i32 @udev_device_unref(%struct.udev_device* %8)
%15 = sub nsw i32 0, %11
br label %22
16: ; preds = %10
%17 = tail call i32 @udev_device_set_action(%struct.udev_device* %8, i8* %2)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = tail call i32 @udev_device_unref(%struct.udev_device* %8)
%21 = sub nsw i32 0, %17
br label %22
22: ; preds = %5, %13, %19
%23 = phi i32 [ %21, %19 ], [ %15, %13 ], [ %6, %5 ]
store i32 %23, i32* @errno
br label %24
24: ; preds = %22, %16, %7
%25 = phi %struct.udev_device* [ null, %7 ], [ %8, %16 ], [ null, %22 ]
ret %struct.udev_device* %25
}