#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;
};
typedef int /*<<< orphan*/ name_enc;
typedef int /*<<< orphan*/ filename;
typedef int /*<<< orphan*/ dirname;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int ENOENT;
int O_CLOEXEC;
int O_CREAT;
int O_NOFOLLOW;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int errno;
char *link_find_prioritized(struct udev_device *, int, char *, char *, int);
int /*<<< orphan*/ node_symlink(struct udev *, char const *, char const *);
int open(char *, int, int);
int /*<<< orphan*/ rmdir(char *);
int strlen(int /*<<< orphan*/);
char *udev_device_get_id_filename(struct udev_device *);
int /*<<< orphan*/ udev_device_get_syspath(struct udev_device *);
struct udev *udev_device_get_udev(struct udev_device *);
int /*<<< orphan*/ udev_get_dev_path(struct udev *);
char *udev_get_run_path(struct udev *);
int /*<<< orphan*/ udev_log_null(struct udev *, char *, char const *, ...);
scalar_t__ unlink(char const *);
int util_create_path(struct udev *, char *);
int /*<<< orphan*/ util_delete_path(struct udev *, char const *);
int /*<<< orphan*/ util_path_encode(char const *, char *, int);
int /*<<< orphan*/ util_strscpyl(char *, int, char *, char *, char *,
                                 int /*<<< orphan*/ *);
void link_update(struct udev_device *dev, const char *slink, bool add) {
  struct udev *udev = udev_device_get_udev(dev);
  char name_enc[1024];
  char filename[1024 * 2];
  char dirname[1024];
  const char *target;
  char buf[1024];
  udev_log_null(udev, "update symlink '%s' of '%s'\n", slink,
                udev_device_get_syspath(dev));
  util_path_encode(&slink[strlen(udev_get_dev_path(udev)) + 1], name_enc,
                   sizeof(name_enc));
  util_strscpyl(dirname, sizeof(dirname), udev_get_run_path(udev), "/links/",
                name_enc, NULL);
  util_strscpyl(filename, sizeof(filename), dirname, "/",
                udev_device_get_id_filename(dev), NULL);
  if (!add) {
    udev_log_null(udev, "removing index: '%s'\n", filename);
    if (unlink(filename) == 0)
      rmdir(dirname);
  }
  target = link_find_prioritized(dev, add, dirname, buf, sizeof(buf));
  if (target == NULL) {
    udev_log_null(udev, "no reference left, remove '%s'\n", slink);
    if (unlink(slink) == 0)
      util_delete_path(udev, slink);
  } else {
    udev_log_null(udev, "creating link '%s' to '%s'\n", slink, target);
    node_symlink(udev, target, slink);
  }
  if (add) {
    int err;
    udev_log_null(udev, "creating index: '%s'\n", filename);
    do {
      int fd;
      err = util_create_path(udev, filename);
      if (err != 0 && err != -ENOENT)
        break;
      fd = open(filename, O_WRONLY | O_CREAT | O_CLOEXEC | O_TRUNC | O_NOFOLLOW,
                0444);
      if (fd >= 0)
        close(fd);
      else
        err = -errno;
    } while (err == -ENOENT);
  }
}


x86 assembly (clang, -O0):
<link_update>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1470,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <udev_device_get_udev@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x1468(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x1460(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <udev_device_get_syspath@plt>
mov    -0x1468(%rbp),%rdi
mov    -0x1460(%rbp),%rdx
mov    %eax,%ecx
lea    0xd97(%rip),%rsi
mov    $0x0,%al
call   1080 <udev_log_null@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x1458(%rbp)
mov    -0x20(%rbp),%rdi
call   10e0 <udev_get_dev_path@plt>
mov    %eax,%edi
call   10a0 <strlen@plt>
mov    -0x1458(%rbp),%rdi
add    $0x1,%eax
cltq
add    %rax,%rdi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   10f0 <util_path_encode@plt>
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1450(%rbp)
mov    -0x20(%rbp),%rdi
call   1130 <udev_get_run_path@plt>
mov    -0x1450(%rbp),%rdi
mov    %rax,%rdx
lea    -0x420(%rbp),%r8
mov    $0x400,%esi
lea    0xd3e(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r9d
call   1110 <util_strscpyl@plt>
lea    -0xc20(%rbp),%rax
mov    %rax,-0x1448(%rbp)
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1440(%rbp)
mov    -0x8(%rbp),%rdi
call   1100 <udev_device_get_id_filename@plt>
mov    -0x1448(%rbp),%rdi
mov    -0x1440(%rbp),%rdx
mov    %rax,%r8
mov    $0x800,%esi
lea    0xcf8(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r9d
call   1110 <util_strscpyl@plt>
cmpl   $0x0,-0x14(%rbp)
jne    137f <link_update+0x16f>
mov    -0x20(%rbp),%rdi
lea    -0xc20(%rbp),%rdx
lea    0xcd4(%rip),%rsi
mov    $0x0,%al
call   1080 <udev_log_null@plt>
lea    -0xc20(%rbp),%rdi
call   1050 <unlink@plt>
cmp    $0x0,%rax
jne    137a <link_update+0x16a>
lea    -0x1020(%rbp),%rdi
call   1090 <rmdir@plt>
jmp    137f <link_update+0x16f>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x1020(%rbp),%rdx
lea    -0x1430(%rbp),%rcx
mov    $0x400,%r8d
call   1070 <link_find_prioritized@plt>
mov    %rax,-0x1028(%rbp)
cmpq   $0x0,-0x1028(%rbp)
jne    13ef <link_update+0x1df>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xc78(%rip),%rsi
mov    $0x0,%al
call   1080 <udev_log_null@plt>
mov    -0x10(%rbp),%rdi
call   1050 <unlink@plt>
cmp    $0x0,%rax
jne    13ea <link_update+0x1da>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10b0 <util_delete_path@plt>
jmp    1420 <link_update+0x210>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x1028(%rbp),%rcx
lea    0xc56(%rip),%rsi
mov    $0x0,%al
call   1080 <udev_log_null@plt>
mov    -0x20(%rbp),%rdi
mov    -0x1028(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1060 <node_symlink@plt>
cmpl   $0x0,-0x14(%rbp)
je     1519 <link_update+0x309>
mov    -0x20(%rbp),%rdi
lea    -0xc20(%rbp),%rdx
lea    0xc3b(%rip),%rsi
mov    $0x0,%al
call   1080 <udev_log_null@plt>
mov    -0x20(%rbp),%rdi
lea    -0xc20(%rbp),%rsi
call   10d0 <util_create_path@plt>
mov    %eax,-0x1434(%rbp)
cmpl   $0x0,-0x1434(%rbp)
je     1484 <link_update+0x274>
mov    -0x1434(%rbp),%eax
xor    %ecx,%ecx
mov    0x2b43(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
je     1484 <link_update+0x274>
jmp    1514 <link_update+0x304>
lea    -0xc20(%rbp),%rdi
mov    0x2b1e(%rip),%rax
mov    (%rax),%esi
mov    0x2b5d(%rip),%rax
or     (%rax),%esi
mov    0x2b04(%rip),%rax
or     (%rax),%esi
mov    0x2b3b(%rip),%rax
or     (%rax),%esi
mov    0x2b3a(%rip),%rax
or     (%rax),%esi
mov    $0x124,%edx
call   1120 <open@plt>
mov    %eax,-0x1438(%rbp)
cmpl   $0x0,-0x1438(%rbp)
jl     14e5 <link_update+0x2d5>
mov    -0x1438(%rbp),%edi
call   10c0 <close@plt>
jmp    14f6 <link_update+0x2e6>
xor    %eax,%eax
mov    0x2ada(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x1434(%rbp)
jmp    14fb <link_update+0x2eb>
mov    -0x1434(%rbp),%eax
xor    %ecx,%ecx
mov    0x2aae(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
je     1443 <link_update+0x233>
jmp    1519 <link_update+0x309>
add    $0x1470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<link_update>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1418,%rsp
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbp
call   1040 <udev_device_get_udev@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1030 <udev_device_get_syspath@plt>
lea    0xdbf(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1080 <udev_log_null@plt>
mov    %rbx,%rdi
call   10e0 <udev_get_dev_path@plt>
mov    %eax,%edi
call   10a0 <strlen@plt>
cltq
lea    (%rax,%r15,1),%rdi
add    $0x1,%rdi
lea    0x1010(%rsp),%r12
mov    %r12,%rsi
mov    $0x400,%edx
call   10f0 <util_path_encode@plt>
mov    %rbx,0x8(%rsp)
mov    %rbx,%rdi
call   1130 <udev_get_run_path@plt>
lea    0xd8b(%rip),%rcx
lea    0x10(%rsp),%r13
mov    %r13,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
mov    %r12,%r8
xor    %r9d,%r9d
call   1110 <util_strscpyl@plt>
mov    %rbp,%rdi
call   1100 <udev_device_get_id_filename@plt>
lea    0xd67(%rip),%rcx
lea    0x410(%rsp),%rdi
mov    $0x800,%esi
mov    %r13,%rdx
mov    %rax,%r8
xor    %r9d,%r9d
call   1110 <util_strscpyl@plt>
test   %r14d,%r14d
jne    1311 <link_update+0x101>
lea    0xd42(%rip),%rsi
lea    0x410(%rsp),%rbx
mov    0x8(%rsp),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <udev_log_null@plt>
mov    %rbx,%rdi
call   1050 <unlink@plt>
test   %rax,%rax
jne    1311 <link_update+0x101>
lea    0x10(%rsp),%rdi
call   1090 <rmdir@plt>
lea    0x10(%rsp),%rdx
lea    0xc10(%rsp),%rcx
mov    %rbp,%rdi
mov    %r14d,%esi
mov    $0x400,%r8d
call   1070 <link_find_prioritized@plt>
test   %rax,%rax
je     1363 <link_update+0x153>
mov    %rax,%rbx
lea    0xd1d(%rip),%rsi
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
mov    %r15,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <udev_log_null@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1060 <node_symlink@plt>
jmp    1393 <link_update+0x183>
lea    0xcd1(%rip),%rsi
mov    0x8(%rsp),%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1080 <udev_log_null@plt>
mov    %r15,%rdi
call   1050 <unlink@plt>
test   %rax,%rax
jne    1393 <link_update+0x183>
mov    0x8(%rsp),%rdi
mov    %r15,%rsi
call   10b0 <util_delete_path@plt>
test   %r14d,%r14d
je     1444 <link_update+0x234>
lea    0xcd4(%rip),%rsi
lea    0x410(%rsp),%rbp
mov    0x8(%rsp),%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1080 <udev_log_null@plt>
mov    0x2be7(%rip),%r13
mov    0x2c20(%rip),%r12
mov    0x2c21(%rip),%r14
mov    0x2be2(%rip),%r15
jmp    13ec <link_update+0x1dc>
nopl   0x0(%rax,%rax,1)
mov    %eax,%edi
call   10c0 <close@plt>
add    (%r15),%ebx
jne    1444 <link_update+0x234>
mov    0x8(%rsp),%rdi
mov    %rbp,%rsi
call   10d0 <util_create_path@plt>
mov    %eax,%ebx
test   %eax,%eax
je     1406 <link_update+0x1f6>
mov    (%r15),%eax
add    %ebx,%eax
jne    1444 <link_update+0x234>
mov    0x2beb(%rip),%rax
mov    (%rax),%esi
mov    0x2b9a(%rip),%rax
or     (%rax),%esi
or     0x0(%r13),%esi
or     (%r12),%esi
or     (%r14),%esi
mov    %rbp,%rdi
mov    $0x124,%edx
call   1120 <open@plt>
test   %eax,%eax
jns    13e0 <link_update+0x1d0>
xor    %ebx,%ebx
mov    0x2b8b(%rip),%rax
sub    (%rax),%ebx
add    (%r15),%ebx
je     13ec <link_update+0x1dc>
add    $0x1418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.udev_device = type { i32 }
%struct.udev = type { i32 }
@.str = [29 x i8] c"update symlink '%s' of '%s'\0A\00"
@.str.1 = [8 x i8] c"/links/\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [22 x i8] c"removing index: '%s'\0A\00"
@.str.4 = [32 x i8] c"no reference left, remove '%s'\0A\00"
@.str.5 = [28 x i8] c"creating link '%s' to '%s'\0A\00"
@.str.6 = [22 x i8] c"creating index: '%s'\0A\00"
@ENOENT = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_CLOEXEC = global i32 0
@O_TRUNC = global i32 0
@O_NOFOLLOW = global i32 0
@errno = global i32 0
define void @link_update(%struct.udev_device* %0, i8* %1, i32 %2) {
%4 = alloca %struct.udev_device*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.udev*
%8 = alloca [1024 x i8]
%9 = alloca [2048 x i8]
%10 = alloca [1024 x i8]
%11 = alloca i8*
%12 = alloca [1024 x i8]
%13 = alloca i32
%14 = alloca i32
store %struct.udev_device* %0, %struct.udev_device** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%15 = load %struct.udev_device*, %struct.udev_device** %4
%16 = call %struct.udev* @udev_device_get_udev(%struct.udev_device* %15)
store %struct.udev* %16, %struct.udev** %7
%17 = load %struct.udev*, %struct.udev** %7
%18 = load i8*, i8** %5
%19 = load %struct.udev_device*, %struct.udev_device** %4
%20 = call i32 @udev_device_get_syspath(%struct.udev_device* %19)
%21 = call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %17, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %18, i32 %20)
%22 = load i8*, i8** %5
%23 = load %struct.udev*, %struct.udev** %7
%24 = call i32 @udev_get_dev_path(%struct.udev* %23)
%25 = call i32 @strlen(i32 %24)
%26 = add nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %22, i64 %27
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%30 = call i32 @util_path_encode(i8* %28, i8* %29, i32 1024)
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%32 = load %struct.udev*, %struct.udev** %7
%33 = call i8* @udev_get_run_path(%struct.udev* %32)
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%35 = call i32 @util_strscpyl(i8* %31, i32 1024, i8* %33, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %34, i32* null)
%36 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%38 = load %struct.udev_device*, %struct.udev_device** %4
%39 = call i8* @udev_device_get_id_filename(%struct.udev_device* %38)
%40 = call i32 @util_strscpyl(i8* %36, i32 2048, i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %39, i32* null)
%41 = load i32, i32* %6
%42 = icmp ne i32 %41, 0
br i1 %42, label %54, label %43
43: ; preds = %3
%44 = load %struct.udev*, %struct.udev** %7
%45 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%46 = call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %44, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %45)
%47 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%48 = call i64 @unlink(i8* %47)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %43
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%52 = call i32 @rmdir(i8* %51)
br label %53
53: ; preds = %50, %43
br label %54
54: ; preds = %53, %3
%55 = load %struct.udev_device*, %struct.udev_device** %4
%56 = load i32, i32* %6
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%59 = call i8* @link_find_prioritized(%struct.udev_device* %55, i32 %56, i8* %57, i8* %58, i32 1024)
store i8* %59, i8** %11
%60 = load i8*, i8** %11
%61 = icmp eq i8* %60, null
br i1 %61, label %62, label %74
62: ; preds = %54
%63 = load %struct.udev*, %struct.udev** %7
%64 = load i8*, i8** %5
%65 = call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %63, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %64)
%66 = load i8*, i8** %5
%67 = call i64 @unlink(i8* %66)
%68 = icmp eq i64 %67, 0
br i1 %68, label %69, label %73
69: ; preds = %62
%70 = load %struct.udev*, %struct.udev** %7
%71 = load i8*, i8** %5
%72 = call i32 @util_delete_path(%struct.udev* %70, i8* %71)
br label %73
73: ; preds = %69, %62
br label %83
74: ; preds = %54
%75 = load %struct.udev*, %struct.udev** %7
%76 = load i8*, i8** %5
%77 = load i8*, i8** %11
%78 = call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %75, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %76, i8* %77)
%79 = load %struct.udev*, %struct.udev** %7
%80 = load i8*, i8** %11
%81 = load i8*, i8** %5
%82 = call i32 @node_symlink(%struct.udev* %79, i8* %80, i8* %81)
br label %83
83: ; preds = %74, %73
%84 = load i32, i32* %6
%85 = icmp ne i32 %84, 0
br i1 %85, label %86, label %129
86: ; preds = %83
%87 = load %struct.udev*, %struct.udev** %7
%88 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%89 = call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %87, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* %88)
br label %90
90: ; preds = %123, %86
%91 = load %struct.udev*, %struct.udev** %7
%92 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%93 = call i32 @util_create_path(%struct.udev* %91, i8* %92)
store i32 %93, i32* %13
%94 = load i32, i32* %13
%95 = icmp ne i32 %94, 0
br i1 %95, label %96, label %102
96: ; preds = %90
%97 = load i32, i32* %13
%98 = load i32, i32* @ENOENT
%99 = sub nsw i32 0, %98
%100 = icmp ne i32 %97, %99
br i1 %100, label %101, label %102
101: ; preds = %96
br label %128
102: ; preds = %96, %90
%103 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%104 = load i32, i32* @O_WRONLY
%105 = load i32, i32* @O_CREAT
%106 = or i32 %104, %105
%107 = load i32, i32* @O_CLOEXEC
%108 = or i32 %106, %107
%109 = load i32, i32* @O_TRUNC
%110 = or i32 %108, %109
%111 = load i32, i32* @O_NOFOLLOW
%112 = or i32 %110, %111
%113 = call i32 @open(i8* %103, i32 %112, i32 292)
store i32 %113, i32* %14
%114 = load i32, i32* %14
%115 = icmp sge i32 %114, 0
br i1 %115, label %116, label %119
116: ; preds = %102
%117 = load i32, i32* %14
%118 = call i32 @close(i32 %117)
br label %122
119: ; preds = %102
%120 = load i32, i32* @errno
%121 = sub nsw i32 0, %120
store i32 %121, i32* %13
br label %122
122: ; preds = %119, %116
br label %123
123: ; preds = %122
%124 = load i32, i32* %13
%125 = load i32, i32* @ENOENT
%126 = sub nsw i32 0, %125
%127 = icmp eq i32 %124, %126
br i1 %127, label %90, label %128
128: ; preds = %123, %101
br label %129
129: ; preds = %128, %83
ret void
}

LLVM IR (-O2):
%struct.udev_device = type { i32 }
%struct.udev = type { i32 }
@.str = [29 x i8] c"update symlink '%s' of '%s'\0A\00"
@.str.1 = [8 x i8] c"/links/\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [22 x i8] c"removing index: '%s'\0A\00"
@.str.4 = [32 x i8] c"no reference left, remove '%s'\0A\00"
@.str.5 = [28 x i8] c"creating link '%s' to '%s'\0A\00"
@.str.6 = [22 x i8] c"creating index: '%s'\0A\00"
@ENOENT = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_CLOEXEC = global i32 0
@O_TRUNC = global i32 0
@O_NOFOLLOW = global i32 0
@errno = global i32 0
define void @link_update(%struct.udev_device* %0, i8* %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = alloca [2048 x i8]
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = tail call %struct.udev* @udev_device_get_udev(%struct.udev_device* %0)
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%13 = tail call i32 @udev_device_get_syspath(%struct.udev_device* %0)
%14 = tail call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %8, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %13)
%15 = tail call i32 @udev_get_dev_path(%struct.udev* %8)
%16 = tail call i32 @strlen(i32 %15)
%17 = add nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %1, i64 %18
%20 = call i32 @util_path_encode(i8* %19, i8* %9, i32 1024)
%21 = call i8* @udev_get_run_path(%struct.udev* %8)
%22 = call i32 @util_strscpyl(i8* %11, i32 1024, i8* %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %9, i32* null)
%23 = call i8* @udev_device_get_id_filename(%struct.udev_device* %0)
%24 = call i32 @util_strscpyl(i8* %10, i32 2048, i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %23, i32* null)
%25 = icmp eq i32 %2, 0
br i1 %25, label %26, label %32
26: ; preds = %3
%27 = call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %8, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%28 = call i64 @unlink(i8* %10)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 @rmdir(i8* %11)
br label %32
32: ; preds = %26, %30, %3
%33 = call i8* @link_find_prioritized(%struct.udev_device* %0, i32 %2, i8* %11, i8* %12, i32 1024)
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %41
35: ; preds = %32
%36 = call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %8, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %1)
%37 = call i64 @unlink(i8* %1)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %35
%40 = call i32 @util_delete_path(%struct.udev* %8, i8* %1)
br label %44
41: ; preds = %32
%42 = call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %8, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %1, i8* %33)
%43 = call i32 @node_symlink(%struct.udev* %8, i8* %33, i8* %1)
br label %44
44: ; preds = %35, %39, %41
br i1 %25, label %76, label %45
45: ; preds = %44
%46 = call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %8, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* %10)
br label %47
47: ; preds = %71, %45
%48 = call i32 @util_create_path(%struct.udev* %8, i8* %10)
%49 = icmp eq i32 %48, 0
br i1 %49, label %54, label %50
50: ; preds = %47
%51 = load i32, i32* @ENOENT
%52 = sub nsw i32 0, %51
%53 = icmp eq i32 %48, %52
br i1 %53, label %54, label %76
54: ; preds = %50, %47
%55 = load i32, i32* @O_WRONLY
%56 = load i32, i32* @O_CREAT
%57 = or i32 %56, %55
%58 = load i32, i32* @O_CLOEXEC
%59 = or i32 %57, %58
%60 = load i32, i32* @O_TRUNC
%61 = or i32 %59, %60
%62 = load i32, i32* @O_NOFOLLOW
%63 = or i32 %61, %62
%64 = call i32 @open(i8* %10, i32 %63, i32 292)
%65 = icmp sgt i32 %64, -1
br i1 %65, label %66, label %68
66: ; preds = %54
%67 = call i32 @close(i32 %64)
br label %71
68: ; preds = %54
%69 = load i32, i32* @errno
%70 = sub nsw i32 0, %69
br label %71
71: ; preds = %68, %66
%72 = phi i32 [ %70, %68 ], [ %48, %66 ]
%73 = load i32, i32* @ENOENT
%74 = sub nsw i32 0, %73
%75 = icmp eq i32 %72, %74
br i1 %75, label %47, label %76
76: ; preds = %50, %71, %44
ret void
}