#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 */
typedef int /*<<< orphan*/ uid_t;
struct udev_list_entry {
  int dummy;
};
struct udev_device {
  int dummy;
};
struct udev {
  int dummy;
};
typedef int /*<<< orphan*/ mode_t;
typedef int /*<<< orphan*/ gid_t;
typedef int /*<<< orphan*/ filename;

/* Variables and functions */
int /*<<< orphan*/ link_update(struct udev_device *, char *, int);
int major(int /*<<< orphan*/);
int minor(int /*<<< orphan*/);
int /*<<< orphan*/ node_symlink(struct udev *, int /*<<< orphan*/, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *, int, int);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
struct udev_list_entry *
udev_device_get_devlinks_list_entry(struct udev_device *);
int /*<<< orphan*/ udev_device_get_devnode(struct udev_device *);
int /*<<< orphan*/ udev_device_get_devnum(struct udev_device *);
int /*<<< orphan*/ udev_device_get_subsystem(struct udev_device *);
struct udev *udev_device_get_udev(struct udev_device *);
char *udev_get_dev_path(struct udev *);
char *udev_list_entry_get_name(struct udev_list_entry *);
struct udev_list_entry *udev_list_entry_get_next(struct udev_list_entry *);
scalar_t__ udev_list_entry_get_num(struct udev_list_entry *);
int /*<<< orphan*/ udev_log_null(struct udev *, char *, int /*<<< orphan*/, int,
                                 int, int /*<<< orphan*/, int /*<<< orphan*/,
                                 int /*<<< orphan*/);
scalar_t__ udev_node_mknod(struct udev_device *, int /*<<< orphan*/ *,
                           int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int udev_node_add(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid) {
  struct udev *udev = udev_device_get_udev(dev);
  char filename[1024];
  struct udev_list_entry *list_entry;
  int err = 0;
  udev_log_null(
      udev,
      "creating device node '%s', devnum=%d:%d, mode=%#o, uid=%d, gid=%d\n",
      udev_device_get_devnode(dev), major(udev_device_get_devnum(dev)),
      minor(udev_device_get_devnum(dev)), mode, uid, gid);
  if (udev_node_mknod(dev, NULL, mode, uid, gid) != 0) {
    err = -1;
    goto exit;
  }
  snprintf(
      filename, sizeof(filename), "%s/%s/%u:%u", udev_get_dev_path(udev),
      strcmp(udev_device_get_subsystem(dev), "block") == 0 ? "block" : "char",
      major(udev_device_get_devnum(dev)), minor(udev_device_get_devnum(dev)));
  node_symlink(udev, udev_device_get_devnode(dev), filename);
  for (list_entry = udev_device_get_devlinks_list_entry(dev);
       list_entry != NULL; list_entry = udev_list_entry_get_next(list_entry)) {
    if (udev_list_entry_get_num(list_entry))
      node_symlink(udev, udev_device_get_devnode(dev),
                   udev_list_entry_get_name(list_entry));
    else
      link_update(dev, udev_list_entry_get_name(list_entry), 1);
  }
exit:
  return err;
}


x86 assembly (clang, -O0):
<udev_node_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x490,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <udev_device_get_udev@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x42c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x440(%rbp)
mov    -0x8(%rbp),%rdi
call   1130 <udev_device_get_devnode@plt>
mov    %eax,-0x434(%rbp)
mov    -0x8(%rbp),%rdi
call   1110 <udev_device_get_devnum@plt>
mov    %eax,%edi
call   1090 <major@plt>
mov    %eax,-0x430(%rbp)
mov    -0x8(%rbp),%rdi
call   1110 <udev_device_get_devnum@plt>
mov    %eax,%edi
call   1070 <minor@plt>
mov    -0x440(%rbp),%rdi
mov    -0x434(%rbp),%edx
mov    -0x430(%rbp),%ecx
mov    %eax,%r8d
mov    -0xc(%rbp),%r9d
mov    -0x10(%rbp),%r10d
mov    -0x14(%rbp),%eax
lea    0xd59(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1060 <udev_log_null@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%esi
call   10e0 <udev_node_mknod@plt>
cmp    $0x0,%rax
je     12e4 <udev_node_add+0xd4>
movl   $0xffffffff,-0x42c(%rbp)
ff ff ff
jmp    1479 <udev_node_add+0x269>
lea    -0x420(%rbp),%rax
mov    %rax,-0x468(%rbp)
mov    -0x20(%rbp),%rdi
call   10f0 <udev_get_dev_path@plt>
mov    %rax,-0x460(%rbp)
mov    -0x8(%rbp),%rdi
call   10a0 <udev_device_get_subsystem@plt>
mov    %eax,%edi
lea    0xd3b(%rip),%rsi
call   10d0 <strcmp@plt>
mov    %rax,%rdx
lea    0xd32(%rip),%rax
lea    0xd25(%rip),%rcx
cmp    $0x0,%rdx
cmove  %rcx,%rax
mov    %rax,-0x458(%rbp)
mov    -0x8(%rbp),%rdi
call   1110 <udev_device_get_devnum@plt>
mov    %eax,%edi
call   1090 <major@plt>
mov    %eax,-0x44c(%rbp)
mov    -0x8(%rbp),%rdi
call   1110 <udev_device_get_devnum@plt>
mov    %eax,%edi
call   1070 <minor@plt>
mov    -0x468(%rbp),%rdi
mov    -0x460(%rbp),%rcx
mov    -0x458(%rbp),%r8
mov    -0x44c(%rbp),%r9d
mov    $0x400,%esi
lea    0xcbc(%rip),%rdx
mov    %eax,(%rsp)
call   1080 <snprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x448(%rbp)
mov    -0x8(%rbp),%rdi
call   1130 <udev_device_get_devnode@plt>
mov    -0x448(%rbp),%rdi
mov    %eax,%esi
lea    -0x420(%rbp),%rdx
call   1050 <node_symlink@plt>
mov    -0x8(%rbp),%rdi
call   10b0 <udev_device_get_devlinks_list_entry@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
je     1474 <udev_node_add+0x264>
mov    -0x428(%rbp),%rdi
call   10c0 <udev_list_entry_get_num@plt>
cmp    $0x0,%rax
je     142c <udev_node_add+0x21c>
mov    -0x20(%rbp),%rax
mov    %rax,-0x478(%rbp)
mov    -0x8(%rbp),%rdi
call   1130 <udev_device_get_devnode@plt>
mov    %eax,-0x46c(%rbp)
mov    -0x428(%rbp),%rdi
call   1120 <udev_list_entry_get_name@plt>
mov    -0x478(%rbp),%rdi
mov    -0x46c(%rbp),%esi
mov    %rax,%rdx
call   1050 <node_symlink@plt>
jmp    1457 <udev_node_add+0x247>
mov    -0x8(%rbp),%rax
mov    %rax,-0x480(%rbp)
mov    -0x428(%rbp),%rdi
call   1120 <udev_list_entry_get_name@plt>
mov    -0x480(%rbp),%rdi
mov    %rax,%rsi
mov    $0x1,%edx
call   1030 <link_update@plt>
jmp    145c <udev_node_add+0x24c>
mov    -0x428(%rbp),%rdi
call   1100 <udev_list_entry_get_next@plt>
mov    %rax,-0x428(%rbp)
jmp    13c8 <udev_node_add+0x1b8>
jmp    1479 <udev_node_add+0x269>
mov    -0x42c(%rbp),%eax
add    $0x490,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udev_node_add>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rcx,0x8(%rsp)
mov    %edx,%r12d
mov    %esi,%ebx
mov    %rdi,%r13
call   1040 <udev_device_get_udev@plt>
mov    %rax,%r15
mov    %r13,%rdi
call   1130 <udev_device_get_devnode@plt>
mov    %eax,%ebp
mov    %r13,%rdi
call   1110 <udev_device_get_devnum@plt>
mov    %eax,%edi
call   1090 <major@plt>
mov    %eax,%r14d
mov    %r13,%rdi
call   1110 <udev_device_get_devnum@plt>
mov    %eax,%edi
call   1070 <minor@plt>
lea    0xd98(%rip),%rsi
mov    %r15,(%rsp)
mov    %r15,%rdi
mov    %ebp,%edx
mov    %r14d,%ecx
mov    %eax,%r8d
mov    %ebx,%r9d
mov    0x8(%rsp),%rbp
push   %rbp
push   %r12
call   1060 <udev_log_null@plt>
add    $0x10,%rsp
mov    %r13,%rdi
xor    %esi,%esi
mov    %ebx,%edx
mov    %r12d,%ecx
mov    %ebp,%r8d
call   10e0 <udev_node_mknod@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    13b8 <udev_node_add+0x1a8>
mov    (%rsp),%r12
mov    %r12,%rdi
call   10f0 <udev_get_dev_path@plt>
mov    %rax,%r15
mov    %r13,%rdi
call   10a0 <udev_device_get_subsystem@plt>
lea    0xd83(%rip),%rbp
mov    %eax,%edi
mov    %rbp,%rsi
call   10d0 <strcmp@plt>
test   %rax,%rax
lea    0xd75(%rip),%rbx
cmove  %rbp,%rbx
mov    %r13,%rdi
call   1110 <udev_device_get_devnum@plt>
mov    %eax,%edi
call   1090 <major@plt>
mov    %eax,%ebp
mov    %r13,%rdi
call   1110 <udev_device_get_devnum@plt>
mov    %eax,%edi
call   1070 <minor@plt>
sub    $0x8,%rsp
lea    0xd34(%rip),%rdx
lea    0x18(%rsp),%r14
mov    %r14,%rdi
mov    $0x400,%esi
mov    %r15,%rcx
mov    %rbx,%r8
mov    %ebp,%r9d
push   %rax
call   1080 <snprintf@plt>
add    $0x10,%rsp
mov    %r13,%rdi
call   1130 <udev_device_get_devnode@plt>
mov    %r12,%rdi
mov    %eax,%esi
mov    %r14,%rdx
call   1050 <node_symlink@plt>
mov    %r13,%rdi
call   10b0 <udev_device_get_devlinks_list_entry@plt>
test   %rax,%rax
je     13b6 <udev_node_add+0x1a6>
mov    %rax,%rbx
jmp    1388 <udev_node_add+0x178>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1120 <udev_list_entry_get_name@plt>
mov    %r13,%rdi
mov    %rax,%rsi
mov    $0x1,%edx
call   1030 <link_update@plt>
mov    %rbx,%rdi
call   1100 <udev_list_entry_get_next@plt>
mov    %rax,%rbx
test   %rax,%rax
je     13b6 <udev_node_add+0x1a6>
mov    %rbx,%rdi
call   10c0 <udev_list_entry_get_num@plt>
test   %rax,%rax
je     1360 <udev_node_add+0x150>
mov    %r13,%rdi
call   1130 <udev_device_get_devnode@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1120 <udev_list_entry_get_name@plt>
mov    %r12,%rdi
mov    %ebp,%esi
mov    %rax,%rdx
call   1050 <node_symlink@plt>
jmp    1378 <udev_node_add+0x168>
xor    %eax,%eax
add    $0x418,%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 }
%struct.udev_list_entry = type { i32 }
@.str = [67 x i8] c"creating device node '%s', devnum=%d:%d, mode=%#o, uid=%d, gid=%d\0A\00"
@.str.1 = [12 x i8] c"%s/%s/%u:%u\00"
@.str.2 = [6 x i8] c"block\00"
@.str.3 = [5 x i8] c"char\00"
define i32 @udev_node_add(%struct.udev_device* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca %struct.udev_device*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.udev*
%10 = alloca [1024 x i8]
%11 = alloca %struct.udev_list_entry*
%12 = alloca i32
store %struct.udev_device* %0, %struct.udev_device** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%13 = load %struct.udev_device*, %struct.udev_device** %5
%14 = call %struct.udev* @udev_device_get_udev(%struct.udev_device* %13)
store %struct.udev* %14, %struct.udev** %9
store i32 0, i32* %12
%15 = load %struct.udev*, %struct.udev** %9
%16 = load %struct.udev_device*, %struct.udev_device** %5
%17 = call i32 @udev_device_get_devnode(%struct.udev_device* %16)
%18 = load %struct.udev_device*, %struct.udev_device** %5
%19 = call i32 @udev_device_get_devnum(%struct.udev_device* %18)
%20 = call i32 @major(i32 %19)
%21 = load %struct.udev_device*, %struct.udev_device** %5
%22 = call i32 @udev_device_get_devnum(%struct.udev_device* %21)
%23 = call i32 @minor(i32 %22)
%24 = load i32, i32* %6
%25 = load i32, i32* %7
%26 = load i32, i32* %8
%27 = call i32 @udev_log_null(%struct.udev* %15, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %20, i32 %23, i32 %24, i32 %25, i32 %26)
%28 = load %struct.udev_device*, %struct.udev_device** %5
%29 = load i32, i32* %6
%30 = load i32, i32* %7
%31 = load i32, i32* %8
%32 = call i64 @udev_node_mknod(%struct.udev_device* %28, i32* null, i32 %29, i32 %30, i32 %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %4
store i32 -1, i32* %12
br label %83
35: ; preds = %4
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%37 = load %struct.udev*, %struct.udev** %9
%38 = call i8* @udev_get_dev_path(%struct.udev* %37)
%39 = load %struct.udev_device*, %struct.udev_device** %5
%40 = call i32 @udev_device_get_subsystem(%struct.udev_device* %39)
%41 = call i64 @strcmp(i32 %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
%43 = zext i1 %42 to i64
%44 = select i1 %42, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0)
%45 = load %struct.udev_device*, %struct.udev_device** %5
%46 = call i32 @udev_device_get_devnum(%struct.udev_device* %45)
%47 = call i32 @major(i32 %46)
%48 = load %struct.udev_device*, %struct.udev_device** %5
%49 = call i32 @udev_device_get_devnum(%struct.udev_device* %48)
%50 = call i32 @minor(i32 %49)
%51 = call i32 @snprintf(i8* %36, i32 1024, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %38, i8* %44, i32 %47, i32 %50)
%52 = load %struct.udev*, %struct.udev** %9
%53 = load %struct.udev_device*, %struct.udev_device** %5
%54 = call i32 @udev_device_get_devnode(%struct.udev_device* %53)
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%56 = call i32 @node_symlink(%struct.udev* %52, i32 %54, i8* %55)
%57 = load %struct.udev_device*, %struct.udev_device** %5
%58 = call %struct.udev_list_entry* @udev_device_get_devlinks_list_entry(%struct.udev_device* %57)
store %struct.udev_list_entry* %58, %struct.udev_list_entry** %11
br label %59
59: ; preds = %79, %35
%60 = load %struct.udev_list_entry*, %struct.udev_list_entry** %11
%61 = icmp ne %struct.udev_list_entry* %60, null
br i1 %61, label %62, label %82
62: ; preds = %59
%63 = load %struct.udev_list_entry*, %struct.udev_list_entry** %11
%64 = call i64 @udev_list_entry_get_num(%struct.udev_list_entry* %63)
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %73
66: ; preds = %62
%67 = load %struct.udev*, %struct.udev** %9
%68 = load %struct.udev_device*, %struct.udev_device** %5
%69 = call i32 @udev_device_get_devnode(%struct.udev_device* %68)
%70 = load %struct.udev_list_entry*, %struct.udev_list_entry** %11
%71 = call i8* @udev_list_entry_get_name(%struct.udev_list_entry* %70)
%72 = call i32 @node_symlink(%struct.udev* %67, i32 %69, i8* %71)
br label %78
73: ; preds = %62
%74 = load %struct.udev_device*, %struct.udev_device** %5
%75 = load %struct.udev_list_entry*, %struct.udev_list_entry** %11
%76 = call i8* @udev_list_entry_get_name(%struct.udev_list_entry* %75)
%77 = call i32 @link_update(%struct.udev_device* %74, i8* %76, i32 1)
br label %78
78: ; preds = %73, %66
br label %79
79: ; preds = %78
%80 = load %struct.udev_list_entry*, %struct.udev_list_entry** %11
%81 = call %struct.udev_list_entry* @udev_list_entry_get_next(%struct.udev_list_entry* %80)
store %struct.udev_list_entry* %81, %struct.udev_list_entry** %11
br label %59
82: ; preds = %59
br label %83
83: ; preds = %82, %34
%84 = load i32, i32* %12
ret i32 %84
}

LLVM IR (-O2):
%struct.udev_device = type { i32 }
%struct.udev = type { i32 }
%struct.udev_list_entry = type { i32 }
@.str = [67 x i8] c"creating device node '%s', devnum=%d:%d, mode=%#o, uid=%d, gid=%d\0A\00"
@.str.1 = [12 x i8] c"%s/%s/%u:%u\00"
@.str.2 = [6 x i8] c"block\00"
@.str.3 = [5 x i8] c"char\00"
define i32 @udev_node_add(%struct.udev_device* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca [1024 x i8]
%6 = tail call %struct.udev* @udev_device_get_udev(%struct.udev_device* %0)
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%8 = tail call i32 @udev_device_get_devnode(%struct.udev_device* %0)
%9 = tail call i32 @udev_device_get_devnum(%struct.udev_device* %0)
%10 = tail call i32 @major(i32 %9)
%11 = tail call i32 @udev_device_get_devnum(%struct.udev_device* %0)
%12 = tail call i32 @minor(i32 %11)
%13 = tail call i32 @udev_log_null(%struct.udev* %6, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %10, i32 %12, i32 %1, i32 %2, i32 %3)
%14 = tail call i64 @udev_node_mknod(%struct.udev_device* %0, i32* null, i32 %1, i32 %2, i32 %3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %45
16: ; preds = %4
%17 = tail call i8* @udev_get_dev_path(%struct.udev* %6)
%18 = tail call i32 @udev_device_get_subsystem(%struct.udev_device* %0)
%19 = tail call i64 @strcmp(i32 %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
%21 = select i1 %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0)
%22 = tail call i32 @udev_device_get_devnum(%struct.udev_device* %0)
%23 = tail call i32 @major(i32 %22)
%24 = tail call i32 @udev_device_get_devnum(%struct.udev_device* %0)
%25 = tail call i32 @minor(i32 %24)
%26 = call i32 @snprintf(i8* %7, i32 1024, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %17, i8* %21, i32 %23, i32 %25)
%27 = call i32 @udev_device_get_devnode(%struct.udev_device* %0)
%28 = call i32 @node_symlink(%struct.udev* %6, i32 %27, i8* %7)
%29 = call %struct.udev_list_entry* @udev_device_get_devlinks_list_entry(%struct.udev_device* %0)
%30 = icmp eq %struct.udev_list_entry* %29, null
br i1 %30, label %45, label %31
31: ; preds = %16, %42
%32 = phi %struct.udev_list_entry* [ %43, %42 ], [ %29, %16 ]
%33 = call i64 @udev_list_entry_get_num(%struct.udev_list_entry* %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %39, label %35
35: ; preds = %31
%36 = call i32 @udev_device_get_devnode(%struct.udev_device* %0)
%37 = call i8* @udev_list_entry_get_name(%struct.udev_list_entry* %32)
%38 = call i32 @node_symlink(%struct.udev* %6, i32 %36, i8* %37)
br label %42
39: ; preds = %31
%40 = call i8* @udev_list_entry_get_name(%struct.udev_list_entry* %32)
%41 = call i32 @link_update(%struct.udev_device* %0, i8* %40, i32 1)
br label %42
42: ; preds = %35, %39
%43 = call %struct.udev_list_entry* @udev_list_entry_get_next(%struct.udev_list_entry* %32)
%44 = icmp eq %struct.udev_list_entry* %43, null
br i1 %44, label %45, label %31
45: ; preds = %42, %16, %4
%46 = phi i32 [ -1, %4 ], [ 0, %16 ], [ 0, %42 ]
ret i32 %46
}