#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 */

/* Variables and functions */
int /*<<< orphan*/ asprintf(char **, char *, char const *);
char *encode_label(char const *);
int /*<<< orphan*/ free(char *);
char *join_paths(char *, char const *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int /*<<< orphan*/ strncasecmp(char const *, char *, int);
int /*<<< orphan*/ strncmp(char const *, char *, int);
char *parse_device_path(const char *dev_str, const char *cur_dev) {
  char *dev, tmp[256], *enc;
  if (!strncasecmp(dev_str, "uuid=", 5)) {
    asprintf(&dev, "/dev/disk/by-uuid/%s", dev_str + 5);
    return dev;
  }
  if (!strncasecmp(dev_str, "label=", 6)) {
    enc = encode_label(dev_str + 6);
    asprintf(&dev, "/dev/disk/by-label/%s", enc);
    free(enc);
    return dev;
  }
  if (!strncmp(dev_str, "/dev/", 5))
    dev_str += 5;
  if (cur_dev && !strncmp(cur_dev, "/dev/ps3d", 9) &&
      !strncmp(dev_str, "sd", 2)) {
    snprintf(tmp, 255, "ps3d%s", dev_str + 2);
    dev_str = tmp;
  }
  return join_paths("/dev", dev_str);
}


x86 assembly (clang, -O0):
<parse_device_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe72(%rip),%rsi
mov    $0x5,%edx
call   1070 <strncasecmp@plt>
cmp    $0x0,%eax
jne    11c6 <parse_device_path+0x56>
mov    -0x10(%rbp),%rdx
add    $0x5,%rdx
lea    -0x20(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1080 <asprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12d8 <parse_device_path+0x168>
mov    -0x10(%rbp),%rdi
lea    0xe4a(%rip),%rsi
mov    $0x6,%edx
call   1070 <strncasecmp@plt>
cmp    $0x0,%eax
jne    1228 <parse_device_path+0xb8>
mov    -0x10(%rbp),%rdi
add    $0x6,%rdi
call   1050 <encode_label@plt>
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    0xe18(%rip),%rsi
call   1080 <asprintf@plt>
mov    -0x128(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12d8 <parse_device_path+0x168>
mov    -0x10(%rbp),%rdi
lea    0xe05(%rip),%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    1252 <parse_device_path+0xe2>
mov    -0x10(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12c4 <parse_device_path+0x154>
mov    -0x18(%rbp),%rdi
lea    0xdd6(%rip),%rsi
mov    $0x9,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    12c4 <parse_device_path+0x154>
mov    -0x10(%rbp),%rdi
lea    0xdc2(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    12c4 <parse_device_path+0x154>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rcx
add    $0x2,%rcx
mov    $0xff,%esi
lea    0xd97(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x120(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xd83(%rip),%rdi
call   1090 <join_paths@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_device_path>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xe77(%rip),%rsi
mov    $0x5,%edx
call   1070 <strncasecmp@plt>
test   %eax,%eax
je     1240 <parse_device_path+0xd0>
lea    0xe79(%rip),%rsi
mov    %rbx,%rdi
mov    $0x6,%edx
call   1070 <strncasecmp@plt>
test   %eax,%eax
je     1258 <parse_device_path+0xe8>
lea    0xe7a(%rip),%rsi
mov    %rbx,%rdi
mov    $0x5,%edx
call   1040 <strncmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
lea    (%rcx,%rcx,4),%r14
add    %rbx,%r14
test   %r15,%r15
je     122f <parse_device_path+0xbf>
lea    0xe59(%rip),%rsi
mov    %r15,%rdi
mov    $0x9,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
jne    122f <parse_device_path+0xbf>
lea    0xe4b(%rip),%rsi
mov    %r14,%rdi
mov    $0x2,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
jne    122f <parse_device_path+0xbf>
mov    %rsp,%rbx
add    $0x2,%r14
lea    0xe2f(%rip),%rdx
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %r14,%rcx
call   1060 <snprintf@plt>
mov    %rbx,%r14
lea    0xe1c(%rip),%rdi
mov    %r14,%rsi
call   1090 <join_paths@plt>
jmp    1285 <parse_device_path+0x115>
add    $0x5,%rbx
lea    0xdbb(%rip),%rsi
mov    %rsp,%rdi
mov    %rbx,%rdx
call   1080 <asprintf@plt>
jmp    1281 <parse_device_path+0x111>
add    $0x6,%rbx
mov    %rbx,%rdi
call   1050 <encode_label@plt>
mov    %rax,%rbx
lea    0xdb4(%rip),%rsi
mov    %rsp,%rdi
mov    %rax,%rdx
call   1080 <asprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    (%rsp),%rax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"uuid=\00"
@.str.1 = [21 x i8] c"/dev/disk/by-uuid/%s\00"
@.str.2 = [7 x i8] c"label=\00"
@.str.3 = [22 x i8] c"/dev/disk/by-label/%s\00"
@.str.4 = [6 x i8] c"/dev/\00"
@.str.5 = [10 x i8] c"/dev/ps3d\00"
@.str.6 = [3 x i8] c"sd\00"
@.str.7 = [7 x i8] c"ps3d%s\00"
@.str.8 = [5 x i8] c"/dev\00"
define i8* @parse_device_path(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [256 x i8]
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call i32 @strncasecmp(i8* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%11 = icmp ne i32 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 5
%15 = call i32 @asprintf(i8** %6, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = load i8*, i8** %6
store i8* %16, i8** %3
br label %57
17: ; preds = %2
%18 = load i8*, i8** %4
%19 = call i32 @strncasecmp(i8* %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 6)
%20 = icmp ne i32 %19, 0
br i1 %20, label %30, label %21
21: ; preds = %17
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i64 6
%24 = call i8* @encode_label(i8* %23)
store i8* %24, i8** %8
%25 = load i8*, i8** %8
%26 = call i32 @asprintf(i8** %6, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = load i8*, i8** %8
%28 = call i32 @free(i8* %27)
%29 = load i8*, i8** %6
store i8* %29, i8** %3
br label %57
30: ; preds = %17
%31 = load i8*, i8** %4
%32 = call i32 @strncmp(i8* %31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%33 = icmp ne i32 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %30
%35 = load i8*, i8** %4
%36 = getelementptr inbounds i8, i8* %35, i64 5
store i8* %36, i8** %4
br label %37
37: ; preds = %34, %30
%38 = load i8*, i8** %5
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %54
40: ; preds = %37
%41 = load i8*, i8** %5
%42 = call i32 @strncmp(i8* %41, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 9)
%43 = icmp ne i32 %42, 0
br i1 %43, label %54, label %44
44: ; preds = %40
%45 = load i8*, i8** %4
%46 = call i32 @strncmp(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 2)
%47 = icmp ne i32 %46, 0
br i1 %47, label %54, label %48
48: ; preds = %44
%49 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%50 = load i8*, i8** %4
%51 = getelementptr inbounds i8, i8* %50, i64 2
%52 = call i32 @snprintf(i8* %49, i32 255, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* %51)
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
store i8* %53, i8** %4
br label %54
54: ; preds = %48, %44, %40, %37
%55 = load i8*, i8** %4
%56 = call i8* @join_paths(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* %55)
store i8* %56, i8** %3
br label %57
57: ; preds = %54, %21, %12
%58 = load i8*, i8** %3
ret i8* %58
}

LLVM IR (-O2):
@.str = [6 x i8] c"uuid=\00"
@.str.1 = [21 x i8] c"/dev/disk/by-uuid/%s\00"
@.str.2 = [7 x i8] c"label=\00"
@.str.3 = [22 x i8] c"/dev/disk/by-label/%s\00"
@.str.4 = [6 x i8] c"/dev/\00"
@.str.5 = [10 x i8] c"/dev/ps3d\00"
@.str.6 = [3 x i8] c"sd\00"
@.str.7 = [7 x i8] c"ps3d%s\00"
@.str.8 = [5 x i8] c"/dev\00"
define i8* @parse_device_path(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca [256 x i8]
%5 = bitcast i8** %3 to i8*
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @strncasecmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = getelementptr inbounds i8, i8* %0, i64 5
%11 = call i32 @asprintf(i8** %3, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %3
br label %40
13: ; preds = %2
%14 = tail call i32 @strncasecmp(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 6)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = getelementptr inbounds i8, i8* %0, i64 6
%18 = tail call i8* @encode_label(i8* %17)
%19 = call i32 @asprintf(i8** %3, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %18)
%20 = call i32 @free(i8* %18)
%21 = load i8*, i8** %3
br label %40
22: ; preds = %13
%23 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%24 = icmp eq i32 %23, 0
%25 = select i1 %24, i64 5, i64 0
%26 = getelementptr i8, i8* %0, i64 %25
%27 = icmp eq i8* %1, null
br i1 %27, label %37, label %28
28: ; preds = %22
%29 = tail call i32 @strncmp(i8* %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 9)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %28
%32 = tail call i32 @strncmp(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 2)
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = getelementptr inbounds i8, i8* %26, i64 2
%36 = call i32 @snprintf(i8* %6, i32 255, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* %35)
br label %37
37: ; preds = %34, %31, %28, %22
%38 = phi i8* [ %26, %28 ], [ %26, %31 ], [ %6, %34 ], [ %26, %22 ]
%39 = call i8* @join_paths(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %37, %16, %9
%41 = phi i8* [ %39, %37 ], [ %21, %16 ], [ %12, %9 ]
ret i8* %41
}