#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 {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ udev_get_dev_path(struct udev *);
size_t util_path_encode(char *, size_t);
size_t util_strlcat(char *, char const *, size_t);
int /*<<< orphan*/ util_strlcpy(char *, int /*<<< orphan*/, size_t);
size_t devpath_to_db_path(struct udev *udev, const char *devpath,
                          char *filename, size_t len) {
  size_t start;
  util_strlcpy(filename, udev_get_dev_path(udev), len);
  start = util_strlcat(filename, "/.udev/db/", len);
  util_strlcat(filename, devpath, len);
  return util_path_encode(&filename[start], len - start);
}


x86 assembly (clang, -O0):
<devpath_to_db_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <udev_get_dev_path@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
mov    -0x20(%rbp),%rdx
call   1050 <util_strlcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe79(%rip),%rsi
call   1060 <util_strlcat@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <util_strlcat@plt>
mov    -0x18(%rbp),%rdi
add    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
sub    -0x28(%rbp),%rsi
call   1040 <util_path_encode@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<devpath_to_db_path>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%r15
call   1030 <udev_get_dev_path@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r14,%rdx
call   1050 <util_strlcpy@plt>
lea    0xe96(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1060 <util_strlcat@plt>
mov    %rax,%r12
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1060 <util_strlcat@plt>
add    %r12,%rbx
sub    %r12,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <util_path_encode@plt>

LLVM IR (-O0):
%struct.udev = type { i32 }
@.str = [11 x i8] c"/.udev/db/\00"
define i64 @devpath_to_db_path(%struct.udev* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca %struct.udev*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
store %struct.udev* %0, %struct.udev** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%10 = load i8*, i8** %7
%11 = load %struct.udev*, %struct.udev** %5
%12 = call i32 @udev_get_dev_path(%struct.udev* %11)
%13 = load i64, i64* %8
%14 = call i32 @util_strlcpy(i8* %10, i32 %12, i64 %13)
%15 = load i8*, i8** %7
%16 = load i64, i64* %8
%17 = call i64 @util_strlcat(i8* %15, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i64 %16)
store i64 %17, i64* %9
%18 = load i8*, i8** %7
%19 = load i8*, i8** %6
%20 = load i64, i64* %8
%21 = call i64 @util_strlcat(i8* %18, i8* %19, i64 %20)
%22 = load i8*, i8** %7
%23 = load i64, i64* %9
%24 = getelementptr inbounds i8, i8* %22, i64 %23
%25 = load i64, i64* %8
%26 = load i64, i64* %9
%27 = sub i64 %25, %26
%28 = call i64 @util_path_encode(i8* %24, i64 %27)
ret i64 %28
}

LLVM IR (-O2):
%struct.udev = type { i32 }
@.str = [11 x i8] c"/.udev/db/\00"
define i64 @devpath_to_db_path(%struct.udev* %0, i8* %1, i8* %2, i64 %3) {
%5 = tail call i32 @udev_get_dev_path(%struct.udev* %0)
%6 = tail call i32 @util_strlcpy(i8* %2, i32 %5, i64 %3)
%7 = tail call i64 @util_strlcat(i8* %2, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i64 %3)
%8 = tail call i64 @util_strlcat(i8* %2, i8* %1, i64 %3)
%9 = getelementptr inbounds i8, i8* %2, i64 %7
%10 = sub i64 %3, %7
%11 = tail call i64 @util_path_encode(i8* %9, i64 %10)
ret i64 %11
}