#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;
};
struct stat {
  int /*<<< orphan*/ st_mode;
};
typedef int /*<<< orphan*/ path;
typedef int /*<<< orphan*/ part;
typedef int /*<<< orphan*/ file;
typedef int /*<<< orphan*/ block;

/* Variables and functions */
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
struct udev_device *device_new(struct udev *);
scalar_t__ stat(char *, struct stat *);
size_t strlen(char *);
scalar_t__ strncmp(char const *, char *, int);
char *strrchr(char const *, char);
int /*<<< orphan*/ udev_device_get_devpath(struct udev_device *);
int /*<<< orphan*/ udev_device_set_syspath(struct udev_device *, char *);
char *udev_get_sys_path(struct udev *);
int /*<<< orphan*/ udev_log_null(struct udev *, char *, char const *, ...);
scalar_t__ util_resolve_sys_link(struct udev *, char *, int);
int /*<<< orphan*/ util_strlcat(char *, char *, int);
int /*<<< orphan*/ util_strlcpy(char *, char const *, int);
struct udev_device *udev_device_new_from_syspath(struct udev *udev,
                                                 const char *syspath) {
  size_t len;
  const char *subdir;
  char path[1024];
  char *pos;
  struct stat statbuf;
  struct udev_device *udev_device;
  if (udev == NULL)
    return NULL;
  if (syspath == NULL)
    return NULL;
  len = strlen(udev_get_sys_path(udev));
  if (strncmp(syspath, udev_get_sys_path(udev), len) != 0) {
    udev_log_null(udev, "not in sys :%s\n", syspath);
    return NULL;
  }
  subdir = &syspath[len + 1];
  pos = strrchr(subdir, '/');
  if (pos == NULL || pos[1] == '\0' || pos < &subdir[2]) {
    udev_log_null(udev, "not a subdir :%s\n", syspath);
    return NULL;
  }
  util_strlcpy(path, syspath, sizeof(path));
  util_resolve_sys_link(udev, path, sizeof(path));
  if (strncmp(&path[len], "/block/", 7) == 0) {
    char block[1024];
    char part[1024];
    util_strlcpy(block, path, sizeof(block));
    pos = strrchr(block, '/');
    if (pos == NULL)
      return NULL;
    util_strlcpy(part, pos, sizeof(part));
    pos[0] = '\0';
    if (util_resolve_sys_link(udev, block, sizeof(block)) == 0) {
      util_strlcpy(path, block, sizeof(path));
      util_strlcat(path, part, sizeof(path));
    }
  }
  if (strncmp(&syspath[len], "/devices/", 9) == 0 ||
      strncmp(&syspath[len], "/class/", 7) == 0 ||
      strncmp(&syspath[len], "/block/", 7) == 0) {
    char file[1024];
    util_strlcpy(file, path, sizeof(file));
    util_strlcat(file, "/uevent", sizeof(file));
    if (stat(file, &statbuf) != 0) {
      udev_log_null(udev, "not a device: %s\n", syspath);
      return NULL;
    }
  } else {
    if (stat(path, &statbuf) != 0 || !S_ISDIR(statbuf.st_mode)) {
      udev_log_null(udev, "directory not found: %s\n", syspath);
      return NULL;
    }
  }
  udev_device = device_new(udev);
  if (udev_device == NULL)
    return NULL;
  udev_device_set_syspath(udev_device, path);
  udev_log_null(udev, "device %p has devpath '%s'\n", udev_device,
                udev_device_get_devpath(udev_device));
  return udev_device;
}


x86 assembly (clang, -O0):
<udev_device_new_from_syspath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1070,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11fb <udev_device_new_from_syspath+0x2b>
movq   $0x0,-0x8(%rbp)
jmp    15d7 <udev_device_new_from_syspath+0x407>
cmpq   $0x0,-0x18(%rbp)
jne    1213 <udev_device_new_from_syspath+0x43>
movq   $0x0,-0x8(%rbp)
jmp    15d7 <udev_device_new_from_syspath+0x407>
mov    -0x10(%rbp),%rdi
call   1040 <udev_get_sys_path@plt>
mov    %rax,%rdi
call   1060 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x1058(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <udev_get_sys_path@plt>
mov    -0x1058(%rbp),%rdi
mov    %rax,%rsi
mov    -0x20(%rbp),%rax
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     127e <udev_device_new_from_syspath+0xae>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xd96(%rip),%rsi
mov    $0x0,%al
call   1050 <udev_log_null@plt>
movq   $0x0,-0x8(%rbp)
jmp    15d7 <udev_device_new_from_syspath+0x407>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    $0x1,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x2f,%esi
call   1090 <strrchr@plt>
mov    %rax,-0x438(%rbp)
cmpq   $0x0,-0x438(%rbp)
je     12e0 <udev_device_new_from_syspath+0x110>
mov    -0x438(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     12e0 <udev_device_new_from_syspath+0x110>
mov    -0x438(%rbp),%rax
mov    -0x28(%rbp),%rcx
add    $0x2,%rcx
cmp    %rcx,%rax
jae    1303 <udev_device_new_from_syspath+0x133>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xd21(%rip),%rsi
mov    $0x0,%al
call   1050 <udev_log_null@plt>
movq   $0x0,-0x8(%rbp)
jmp    15d7 <udev_device_new_from_syspath+0x407>
lea    -0x430(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x400,%edx
call   10c0 <util_strlcpy@plt>
mov    -0x10(%rbp),%rdi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   10a0 <util_resolve_sys_link@plt>
lea    -0x430(%rbp),%rdi
add    -0x20(%rbp),%rdi
lea    0xce3(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1414 <udev_device_new_from_syspath+0x244>
lea    -0x850(%rbp),%rdi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   10c0 <util_strlcpy@plt>
lea    -0x850(%rbp),%rdi
mov    $0x2f,%esi
call   1090 <strrchr@plt>
mov    %rax,-0x438(%rbp)
cmpq   $0x0,-0x438(%rbp)
jne    139e <udev_device_new_from_syspath+0x1ce>
movq   $0x0,-0x8(%rbp)
jmp    15d7 <udev_device_new_from_syspath+0x407>
lea    -0xc50(%rbp),%rdi
mov    -0x438(%rbp),%rsi
mov    $0x400,%edx
call   10c0 <util_strlcpy@plt>
mov    -0x438(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x850(%rbp),%rsi
mov    $0x400,%edx
call   10a0 <util_resolve_sys_link@plt>
cmp    $0x0,%rax
jne    140f <udev_device_new_from_syspath+0x23f>
lea    -0x430(%rbp),%rdi
lea    -0x850(%rbp),%rsi
mov    $0x400,%edx
call   10c0 <util_strlcpy@plt>
lea    -0x430(%rbp),%rdi
lea    -0xc50(%rbp),%rsi
mov    $0x400,%edx
call   10e0 <util_strlcat@plt>
jmp    1414 <udev_device_new_from_syspath+0x244>
mov    -0x18(%rbp),%rdi
add    -0x20(%rbp),%rdi
lea    0xc07(%rip),%rsi
mov    $0x9,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     147d <udev_device_new_from_syspath+0x2ad>
mov    -0x18(%rbp),%rdi
add    -0x20(%rbp),%rdi
lea    0xbee(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     147d <udev_device_new_from_syspath+0x2ad>
mov    -0x18(%rbp),%rdi
add    -0x20(%rbp),%rdi
lea    0xbb9(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    14f2 <udev_device_new_from_syspath+0x322>
lea    -0x1050(%rbp),%rdi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   10c0 <util_strlcpy@plt>
lea    -0x1050(%rbp),%rdi
lea    0xb99(%rip),%rsi
mov    $0x400,%edx
call   10e0 <util_strlcat@plt>
lea    -0x1050(%rbp),%rdi
lea    -0x440(%rbp),%rsi
call   10b0 <stat@plt>
cmp    $0x0,%rax
je     14ed <udev_device_new_from_syspath+0x31d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xb6b(%rip),%rsi
mov    $0x0,%al
call   1050 <udev_log_null@plt>
movq   $0x0,-0x8(%rbp)
jmp    15d7 <udev_device_new_from_syspath+0x407>
jmp    154b <udev_device_new_from_syspath+0x37b>
lea    -0x430(%rbp),%rdi
lea    -0x440(%rbp),%rsi
call   10b0 <stat@plt>
cmp    $0x0,%rax
jne    1523 <udev_device_new_from_syspath+0x353>
mov    -0x440(%rbp),%edi
call   1080 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    1546 <udev_device_new_from_syspath+0x376>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xb24(%rip),%rsi
mov    $0x0,%al
call   1050 <udev_log_null@plt>
movq   $0x0,-0x8(%rbp)
jmp    15d7 <udev_device_new_from_syspath+0x407>
jmp    154b <udev_device_new_from_syspath+0x37b>
mov    -0x10(%rbp),%rdi
call   10d0 <device_new@plt>
mov    %rax,-0x448(%rbp)
cmpq   $0x0,-0x448(%rbp)
jne    1576 <udev_device_new_from_syspath+0x3a6>
movq   $0x0,-0x8(%rbp)
jmp    15d7 <udev_device_new_from_syspath+0x407>
mov    -0x448(%rbp),%rdi
lea    -0x430(%rbp),%rsi
call   1070 <udev_device_set_syspath@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x1068(%rbp)
mov    -0x448(%rbp),%rax
mov    %rax,-0x1060(%rbp)
mov    -0x448(%rbp),%rdi
call   10f0 <udev_device_get_devpath@plt>
mov    -0x1068(%rbp),%rdi
mov    -0x1060(%rbp),%rdx
mov    %eax,%ecx
lea    0xaaa(%rip),%rsi
mov    $0x0,%al
call   1050 <udev_log_null@plt>
mov    -0x448(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udev_device_new_from_syspath>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xc08,%rsp
xor    %ebx,%ebx
test   %rdi,%rdi
je     133f <udev_device_new_from_syspath+0x16f>
mov    %rsi,%r14
test   %rsi,%rsi
je     133f <udev_device_new_from_syspath+0x16f>
mov    %rdi,%r12
call   1040 <udev_get_sys_path@plt>
mov    %rax,%rdi
call   1060 <strlen@plt>
mov    %rax,%r15
mov    %r12,%rdi
call   1040 <udev_get_sys_path@plt>
mov    %r14,%rdi
mov    %rax,%rsi
mov    %r15d,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     122f <udev_device_new_from_syspath+0x5f>
lea    0xdd6(%rip),%rsi
jmp    1330 <udev_device_new_from_syspath+0x160>
lea    (%r15,%r14,1),%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1090 <strrchr@plt>
test   %rax,%rax
je     1329 <udev_device_new_from_syspath+0x159>
cmpb   $0x0,0x1(%rax)
je     1329 <udev_device_new_from_syspath+0x159>
add    $0x2,%rbx
cmp    %rbx,%rax
jb     1329 <udev_device_new_from_syspath+0x159>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x400,%edx
call   10c0 <util_strlcpy@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x400,%edx
call   10a0 <util_resolve_sys_link@plt>
lea    (%rsp,%r15,1),%rdi
lea    0xd90(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     139f <udev_device_new_from_syspath+0x1cf>
add    %r14,%r15
lea    0xd7b(%rip),%rsi
mov    %r15,%rdi
mov    $0x9,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1351 <udev_device_new_from_syspath+0x181>
lea    0xd68(%rip),%rsi
mov    %r15,%rdi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1351 <udev_device_new_from_syspath+0x181>
lea    0xd3d(%rip),%rsi
mov    %r15,%rdi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1351 <udev_device_new_from_syspath+0x181>
mov    %rsp,%rdi
lea    0x400(%rsp),%rsi
call   10b0 <stat@plt>
test   %rax,%rax
jne    1320 <udev_device_new_from_syspath+0x150>
mov    0x400(%rsp),%edi
call   1080 <S_ISDIR@plt>
test   %eax,%eax
jne    1438 <udev_device_new_from_syspath+0x268>
lea    0xd2f(%rip),%rsi
jmp    1330 <udev_device_new_from_syspath+0x160>
lea    0xce0(%rip),%rsi
xor    %ebx,%ebx
mov    %r12,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <udev_log_null@plt>
mov    %rbx,%rax
add    $0xc08,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0x800(%rsp),%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0x400,%edx
call   10c0 <util_strlcpy@plt>
lea    0xccc(%rip),%rsi
mov    %rbx,%rdi
mov    $0x400,%edx
call   10e0 <util_strlcat@plt>
lea    0x400(%rsp),%rsi
mov    %rbx,%rdi
call   10b0 <stat@plt>
test   %rax,%rax
je     1438 <udev_device_new_from_syspath+0x268>
lea    0xca7(%rip),%rsi
jmp    1330 <udev_device_new_from_syspath+0x160>
lea    0x800(%rsp),%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0x400,%edx
call   10c0 <util_strlcpy@plt>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1090 <strrchr@plt>
test   %rax,%rax
je     1476 <udev_device_new_from_syspath+0x2a6>
mov    %rax,%rbx
lea    0x400(%rsp),%rdi
mov    %rax,%rsi
mov    $0x400,%edx
call   10c0 <util_strlcpy@plt>
movb   $0x0,(%rbx)
lea    0x800(%rsp),%rsi
mov    %r12,%rdi
mov    $0x400,%edx
call   10a0 <util_resolve_sys_link@plt>
test   %rax,%rax
jne    12a5 <udev_device_new_from_syspath+0xd5>
mov    %rsp,%rbx
lea    0x800(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x400,%edx
call   10c0 <util_strlcpy@plt>
lea    0x400(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x400,%edx
call   10e0 <util_strlcat@plt>
jmp    12a5 <udev_device_new_from_syspath+0xd5>
mov    %r12,%rdi
call   10d0 <device_new@plt>
test   %rax,%rax
je     1476 <udev_device_new_from_syspath+0x2a6>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
call   1070 <udev_device_set_syspath@plt>
mov    %rbx,%rdi
call   10f0 <udev_device_get_devpath@plt>
lea    0xc0d(%rip),%rsi
mov    %r12,%rdi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <udev_log_null@plt>
jmp    133f <udev_device_new_from_syspath+0x16f>
xor    %ebx,%ebx
jmp    133f <udev_device_new_from_syspath+0x16f>

LLVM IR (-O0):
%struct.udev_device = type { i32 }
%struct.udev = type { i32 }
%struct.stat = type { i32 }
@.str = [16 x i8] c"not in sys :%s\0A\00"
@.str.1 = [18 x i8] c"not a subdir :%s\0A\00"
@.str.2 = [8 x i8] c"/block/\00"
@.str.3 = [10 x i8] c"/devices/\00"
@.str.4 = [8 x i8] c"/class/\00"
@.str.5 = [8 x i8] c"/uevent\00"
@.str.6 = [18 x i8] c"not a device: %s\0A\00"
@.str.7 = [25 x i8] c"directory not found: %s\0A\00"
@.str.8 = [28 x i8] c"device %p has devpath '%s'\0A\00"
define %struct.udev_device* @udev_device_new_from_syspath(%struct.udev* %0, i8* %1) {
%3 = alloca %struct.udev_device*
%4 = alloca %struct.udev*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca [1024 x i8]
%9 = alloca i8*
%10 = alloca %struct.stat
%11 = alloca %struct.udev_device*
%12 = alloca [1024 x i8]
%13 = alloca [1024 x i8]
%14 = alloca [1024 x i8]
store %struct.udev* %0, %struct.udev** %4
store i8* %1, i8** %5
%15 = load %struct.udev*, %struct.udev** %4
%16 = icmp eq %struct.udev* %15, null
br i1 %16, label %17, label %18
17: ; preds = %2
store %struct.udev_device* null, %struct.udev_device** %3
br label %162
18: ; preds = %2
%19 = load i8*, i8** %5
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %18
store %struct.udev_device* null, %struct.udev_device** %3
br label %162
22: ; preds = %18
%23 = load %struct.udev*, %struct.udev** %4
%24 = call i8* @udev_get_sys_path(%struct.udev* %23)
%25 = call i64 @strlen(i8* %24)
store i64 %25, i64* %6
%26 = load i8*, i8** %5
%27 = load %struct.udev*, %struct.udev** %4
%28 = call i8* @udev_get_sys_path(%struct.udev* %27)
%29 = load i64, i64* %6
%30 = trunc i64 %29 to i32
%31 = call i64 @strncmp(i8* %26, i8* %28, i32 %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %22
%34 = load %struct.udev*, %struct.udev** %4
%35 = load i8*, i8** %5
%36 = call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %34, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %35)
store %struct.udev_device* null, %struct.udev_device** %3
br label %162
37: ; preds = %22
%38 = load i8*, i8** %5
%39 = load i64, i64* %6
%40 = add i64 %39, 1
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8* %41, i8** %7
%42 = load i8*, i8** %7
%43 = call i8* @strrchr(i8* %42, i8 signext 47)
store i8* %43, i8** %9
%44 = load i8*, i8** %9
%45 = icmp eq i8* %44, null
br i1 %45, label %57, label %46
46: ; preds = %37
%47 = load i8*, i8** %9
%48 = getelementptr inbounds i8, i8* %47, i64 1
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 0
br i1 %51, label %57, label %52
52: ; preds = %46
%53 = load i8*, i8** %9
%54 = load i8*, i8** %7
%55 = getelementptr inbounds i8, i8* %54, i64 2
%56 = icmp ult i8* %53, %55
br i1 %56, label %57, label %61
57: ; preds = %52, %46, %37
%58 = load %struct.udev*, %struct.udev** %4
%59 = load i8*, i8** %5
%60 = call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %58, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %59)
store %struct.udev_device* null, %struct.udev_device** %3
br label %162
61: ; preds = %52
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%63 = load i8*, i8** %5
%64 = call i32 @util_strlcpy(i8* %62, i8* %63, i32 1024)
%65 = load %struct.udev*, %struct.udev** %4
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%67 = call i64 @util_resolve_sys_link(%struct.udev* %65, i8* %66, i32 1024)
%68 = load i64, i64* %6
%69 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 %68
%70 = call i64 @strncmp(i8* %69, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 7)
%71 = icmp eq i64 %70, 0
br i1 %71, label %72, label %99
72: ; preds = %61
%73 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%74 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%75 = call i32 @util_strlcpy(i8* %73, i8* %74, i32 1024)
%76 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%77 = call i8* @strrchr(i8* %76, i8 signext 47)
store i8* %77, i8** %9
%78 = load i8*, i8** %9
%79 = icmp eq i8* %78, null
br i1 %79, label %80, label %81
80: ; preds = %72
store %struct.udev_device* null, %struct.udev_device** %3
br label %162
81: ; preds = %72
%82 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%83 = load i8*, i8** %9
%84 = call i32 @util_strlcpy(i8* %82, i8* %83, i32 1024)
%85 = load i8*, i8** %9
%86 = getelementptr inbounds i8, i8* %85, i64 0
store i8 0, i8* %86
%87 = load %struct.udev*, %struct.udev** %4
%88 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%89 = call i64 @util_resolve_sys_link(%struct.udev* %87, i8* %88, i32 1024)
%90 = icmp eq i64 %89, 0
br i1 %90, label %91, label %98
91: ; preds = %81
%92 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%93 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%94 = call i32 @util_strlcpy(i8* %92, i8* %93, i32 1024)
%95 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%96 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%97 = call i32 @util_strlcat(i8* %95, i8* %96, i32 1024)
br label %98
98: ; preds = %91, %81
br label %99
99: ; preds = %98, %61
%100 = load i8*, i8** %5
%101 = load i64, i64* %6
%102 = getelementptr inbounds i8, i8* %100, i64 %101
%103 = call i64 @strncmp(i8* %102, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 9)
%104 = icmp eq i64 %103, 0
br i1 %104, label %117, label %105
105: ; preds = %99
%106 = load i8*, i8** %5
%107 = load i64, i64* %6
%108 = getelementptr inbounds i8, i8* %106, i64 %107
%109 = call i64 @strncmp(i8* %108, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 7)
%110 = icmp eq i64 %109, 0
br i1 %110, label %117, label %111
111: ; preds = %105
%112 = load i8*, i8** %5
%113 = load i64, i64* %6
%114 = getelementptr inbounds i8, i8* %112, i64 %113
%115 = call i64 @strncmp(i8* %114, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 7)
%116 = icmp eq i64 %115, 0
br i1 %116, label %117, label %131
117: ; preds = %111, %105, %99
%118 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%119 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%120 = call i32 @util_strlcpy(i8* %118, i8* %119, i32 1024)
%121 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%122 = call i32 @util_strlcat(i8* %121, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 1024)
%123 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%124 = call i64 @stat(i8* %123, %struct.stat* %10)
%125 = icmp ne i64 %124, 0
br i1 %125, label %126, label %130
126: ; preds = %117
%127 = load %struct.udev*, %struct.udev** %4
%128 = load i8*, i8** %5
%129 = call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %127, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %128)
store %struct.udev_device* null, %struct.udev_device** %3
br label %162
130: ; preds = %117
br label %145
131: ; preds = %111
%132 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%133 = call i64 @stat(i8* %132, %struct.stat* %10)
%134 = icmp ne i64 %133, 0
br i1 %134, label %140, label %135
135: ; preds = %131
%136 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%137 = load i32, i32* %136
%138 = call i32 @S_ISDIR(i32 %137)
%139 = icmp ne i32 %138, 0
br i1 %139, label %144, label %140
140: ; preds = %135, %131
%141 = load %struct.udev*, %struct.udev** %4
%142 = load i8*, i8** %5
%143 = call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %141, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %142)
store %struct.udev_device* null, %struct.udev_device** %3
br label %162
144: ; preds = %135
br label %145
145: ; preds = %144, %130
%146 = load %struct.udev*, %struct.udev** %4
%147 = call %struct.udev_device* @device_new(%struct.udev* %146)
store %struct.udev_device* %147, %struct.udev_device** %11
%148 = load %struct.udev_device*, %struct.udev_device** %11
%149 = icmp eq %struct.udev_device* %148, null
br i1 %149, label %150, label %151
150: ; preds = %145
store %struct.udev_device* null, %struct.udev_device** %3
br label %162
151: ; preds = %145
%152 = load %struct.udev_device*, %struct.udev_device** %11
%153 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%154 = call i32 @udev_device_set_syspath(%struct.udev_device* %152, i8* %153)
%155 = load %struct.udev*, %struct.udev** %4
%156 = load %struct.udev_device*, %struct.udev_device** %11
%157 = bitcast %struct.udev_device* %156 to i8*
%158 = load %struct.udev_device*, %struct.udev_device** %11
%159 = call i32 @udev_device_get_devpath(%struct.udev_device* %158)
%160 = call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %155, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i8* %157, i32 %159)
%161 = load %struct.udev_device*, %struct.udev_device** %11
store %struct.udev_device* %161, %struct.udev_device** %3
br label %162
162: ; preds = %151, %150, %140, %126, %80, %57, %33, %21, %17
%163 = load %struct.udev_device*, %struct.udev_device** %3
ret %struct.udev_device* %163
}

LLVM IR (-O2):
%struct.udev_device = type { i32 }
%struct.udev = type { i32 }
%struct.stat = type { i32 }
@.str = [16 x i8] c"not in sys :%s\0A\00"
@.str.1 = [18 x i8] c"not a subdir :%s\0A\00"
@.str.2 = [8 x i8] c"/block/\00"
@.str.3 = [10 x i8] c"/devices/\00"
@.str.4 = [8 x i8] c"/class/\00"
@.str.5 = [8 x i8] c"/uevent\00"
@.str.6 = [18 x i8] c"not a device: %s\0A\00"
@.str.7 = [25 x i8] c"directory not found: %s\0A\00"
@.str.8 = [28 x i8] c"device %p has devpath '%s'\0A\00"
define %struct.udev_device* @udev_device_new_from_syspath(%struct.udev* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = alloca %struct.stat
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%9 = bitcast %struct.stat* %4 to i8*
%10 = icmp eq %struct.udev* %0, null
%11 = icmp eq i8* %1, null
%12 = or i1 %10, %11
br i1 %12, label %94, label %13
13: ; preds = %2
%14 = tail call i8* @udev_get_sys_path(%struct.udev* %0)
%15 = tail call i64 @strlen(i8* dereferenceable(1) %14)
%16 = tail call i8* @udev_get_sys_path(%struct.udev* %0)
%17 = trunc i64 %15 to i32
%18 = tail call i64 @strncmp(i8* %1, i8* %16, i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %13
%21 = tail call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %94
22: ; preds = %13
%23 = add i64 %15, 1
%24 = getelementptr inbounds i8, i8* %1, i64 %23
%25 = tail call i8* @strrchr(i8* %24, i8 signext 47)
%26 = icmp eq i8* %25, null
br i1 %26, label %34, label %27
27: ; preds = %22
%28 = getelementptr inbounds i8, i8* %25, i64 1
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 0
%31 = getelementptr inbounds i8, i8* %24, i64 2
%32 = icmp ult i8* %25, %31
%33 = select i1 %30, i1 true, i1 %32
br i1 %33, label %34, label %36
34: ; preds = %27, %22
%35 = tail call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %94
36: ; preds = %27
%37 = call i32 @util_strlcpy(i8* %8, i8* %1, i32 1024)
%38 = call i64 @util_resolve_sys_link(%struct.udev* %0, i8* %8, i32 1024)
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %15
%40 = call i64 @strncmp(i8* %39, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 7)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %56
42: ; preds = %36
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%45 = call i32 @util_strlcpy(i8* %43, i8* %8, i32 1024)
%46 = call i8* @strrchr(i8* %43, i8 signext 47)
%47 = icmp eq i8* %46, null
br i1 %47, label %93, label %48
48: ; preds = %42
%49 = call i32 @util_strlcpy(i8* %44, i8* %46, i32 1024)
store i8 0, i8* %46
%50 = call i64 @util_resolve_sys_link(%struct.udev* %0, i8* %43, i32 1024)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %48
%53 = call i32 @util_strlcpy(i8* %8, i8* %43, i32 1024)
%54 = call i32 @util_strlcat(i8* %8, i8* %44, i32 1024)
br label %55
55: ; preds = %48, %52
br label %56
56: ; preds = %55, %36
%57 = getelementptr inbounds i8, i8* %1, i64 %15
%58 = call i64 @strncmp(i8* %57, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 9)
%59 = icmp eq i64 %58, 0
br i1 %59, label %66, label %60
60: ; preds = %56
%61 = call i64 @strncmp(i8* %57, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 7)
%62 = icmp eq i64 %61, 0
br i1 %62, label %66, label %63
63: ; preds = %60
%64 = call i64 @strncmp(i8* %57, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 7)
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %74
66: ; preds = %63, %60, %56
%67 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%68 = call i32 @util_strlcpy(i8* %67, i8* %8, i32 1024)
%69 = call i32 @util_strlcat(i8* %67, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 1024)
%70 = call i64 @stat(i8* %67, %struct.stat* %4)
%71 = icmp eq i64 %70, 0
br i1 %71, label %84, label %72
72: ; preds = %66
%73 = call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %1)
br label %94
74: ; preds = %63
%75 = call i64 @stat(i8* %8, %struct.stat* %4)
%76 = icmp eq i64 %75, 0
br i1 %76, label %77, label %82
77: ; preds = %74
%78 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%79 = load i32, i32* %78
%80 = call i32 @S_ISDIR(i32 %79)
%81 = icmp eq i32 %80, 0
br i1 %81, label %82, label %85
82: ; preds = %77, %74
%83 = call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %1)
br label %94
84: ; preds = %66
br label %85
85: ; preds = %84, %77
%86 = call %struct.udev_device* @device_new(%struct.udev* %0)
%87 = icmp eq %struct.udev_device* %86, null
br i1 %87, label %94, label %88
88: ; preds = %85
%89 = call i32 @udev_device_set_syspath(%struct.udev_device* %86, i8* %8)
%90 = bitcast %struct.udev_device* %86 to i8*
%91 = call i32 @udev_device_get_devpath(%struct.udev_device* %86)
%92 = call i32 (%struct.udev*, i8*, i8*, ...) @udev_log_null(%struct.udev* %0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i8* %90, i32 %91)
br label %94
93: ; preds = %42
br label %94
94: ; preds = %72, %85, %93, %2, %88, %82, %34, %20
%95 = phi %struct.udev_device* [ null, %20 ], [ null, %34 ], [ %86, %88 ], [ null, %72 ], [ null, %82 ], [ null, %2 ], [ null, %93 ], [ null, %85 ]
ret %struct.udev_device* %95
}