#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*/ path;
typedef int /*<<< orphan*/ nbuf;

/* Variables and functions */
int PATH_MAX;
scalar_t__ memcmp(char const *, char *, int);
scalar_t__ read_line(char *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, int);
scalar_t__ strcmp(char *, char *);
char *strdup(char *);
int find_delta_names(const char *device, int start_level, int end_level,
                     char **names, char **format) {
  int i;
  char path[PATH_MAX];
  char nbuf[4096];
  if (memcmp(device, "/dev/", 5) == 0)
    device += 5;
  for (i = 0; i <= end_level - start_level; i++) {
    snprintf(path, sizeof(path), "/sys/block/%s/pdelta/%d/image", device,
             start_level + i);
    if (read_line(path, nbuf, sizeof(nbuf)))
      return -1;
    names[(end_level - start_level) - i] = strdup(nbuf);
    if (i == 0 && format) {
      snprintf(path, sizeof(path), "/sys/block/%s/pdelta/%d/format", device,
               start_level);
      if (read_line(path, nbuf, sizeof(nbuf)))
        return -1;
      if (strcmp(nbuf, "raw") == 0)
        *format = "raw";
      else if (strcmp(nbuf, "ploop1") == 0)
        *format = "ploop1";
      else
        *format = "unknown";
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<find_delta_names>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1060,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    0x2e7c(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x1058(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x1050(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe52(%rip),%rsi
mov    $0x5,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    11ce <find_delta_names+0x7e>
mov    -0x10(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    -0x14(%rbp),%ecx
cmp    %ecx,%eax
jg     1365 <find_delta_names+0x215>
mov    -0x1050(%rbp),%rdi
mov    -0x1058(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
add    -0x2c(%rbp),%r8d
lea    0xdfd(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x1050(%rbp),%rdi
lea    -0x1040(%rbp),%rsi
mov    $0x1000,%edx
call   1060 <read_line@plt>
cmp    $0x0,%rax
je     1246 <find_delta_names+0xf6>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x1044(%rbp)
jmp    1376 <find_delta_names+0x226>
lea    -0x1040(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    -0x14(%rbp),%ecx
sub    -0x2c(%rbp),%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
cmpl   $0x0,-0x2c(%rbp)
jne    1352 <find_delta_names+0x202>
cmpq   $0x0,-0x28(%rbp)
je     1352 <find_delta_names+0x202>
mov    -0x1050(%rbp),%rdi
mov    -0x1058(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
lea    0xd87(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x1050(%rbp),%rdi
lea    -0x1040(%rbp),%rsi
mov    $0x1000,%edx
call   1060 <read_line@plt>
cmp    $0x0,%rax
je     12da <find_delta_names+0x18a>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x1044(%rbp)
jmp    1376 <find_delta_names+0x226>
lea    -0x1040(%rbp),%rdi
lea    0xd5b(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    130a <find_delta_names+0x1ba>
mov    -0x28(%rbp),%rax
lea    0xd41(%rip),%rcx
mov    %rcx,(%rax)
jmp    134d <find_delta_names+0x1fd>
lea    -0x1040(%rbp),%rdi
lea    0xd2f(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    133a <find_delta_names+0x1ea>
mov    -0x28(%rbp),%rax
lea    0xd15(%rip),%rcx
mov    %rcx,(%rax)
jmp    1348 <find_delta_names+0x1f8>
mov    -0x28(%rbp),%rax
lea    0xd09(%rip),%rcx
mov    %rcx,(%rax)
jmp    134d <find_delta_names+0x1fd>
jmp    1352 <find_delta_names+0x202>
jmp    1357 <find_delta_names+0x207>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d5 <find_delta_names+0x85>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x1044(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_delta_names>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1038,%rsp
mov    %r8,-0x38(%rbp)
mov    %rcx,-0x58(%rbp)
mov    %edx,%ebx
mov    %esi,%r15d
mov    %rdi,%r13
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rax,-0x50(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
lea    0xe63(%rip),%rsi
mov    $0x5,%edx
call   1040 <memcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %al
mov    %ebx,%r12d
sub    %r15d,%r12d
js     12de <find_delta_names+0x18e>
mov    %al,%cl
lea    (%rcx,%rcx,4),%rax
add    %rax,%r13
mov    %r15d,%eax
mov    %rax,-0x40(%rbp)
sub    %r15d,%ebx
add    $0x1,%ebx
xor    %r15d,%r15d
mov    %r13,-0x30(%rbp)
jmp    11fc <find_delta_names+0xac>
nopw   0x0(%rax,%rax,1)
mov    -0x38(%rbp),%rax
mov    %r13,(%rax)
add    $0x1,%r15
add    $0xffffffff,%r12d
cmp    %r15,%rbx
mov    -0x30(%rbp),%r13
je     12de <find_delta_names+0x18e>
mov    -0x40(%rbp),%rax
lea    (%rax,%r15,1),%r8d
mov    -0x48(%rbp),%r14
mov    %r14,%rdi
mov    -0x50(%rbp),%rsi
lea    0xdf0(%rip),%rdx
mov    %r13,%rcx
call   1030 <snprintf@plt>
mov    %r14,%rdi
lea    -0x1060(%rbp),%r14
mov    %r14,%rsi
mov    $0x1000,%edx
call   1060 <read_line@plt>
mov    $0xffffffff,%r13d
test   %rax,%rax
jne    12e1 <find_delta_names+0x191>
mov    %r14,%rdi
call   1070 <strdup@plt>
movslq %r12d,%rcx
mov    -0x58(%rbp),%rdx
mov    %rax,(%rdx,%rcx,8)
cmpq   $0x0,-0x38(%rbp)
je     11e7 <find_delta_names+0x97>
test   %r15,%r15
jne    11e7 <find_delta_names+0x97>
mov    -0x48(%rbp),%r14
mov    %r14,%rdi
mov    -0x50(%rbp),%rsi
lea    0xdaf(%rip),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x40(%rbp),%r8
call   1030 <snprintf@plt>
mov    %r14,%rdi
lea    -0x1060(%rbp),%r14
mov    %r14,%rsi
mov    $0x1000,%edx
call   1060 <read_line@plt>
test   %rax,%rax
jne    12e1 <find_delta_names+0x191>
mov    %r14,%rdi
lea    0xd9b(%rip),%r13
mov    %r13,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11e0 <find_delta_names+0x90>
mov    %r14,%rdi
lea    0xd84(%rip),%r14
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
lea    0xd79(%rip),%r13
cmove  %r14,%r13
jmp    11e0 <find_delta_names+0x90>
xor    %r13d,%r13d
mov    %r13d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [6 x i8] c"/dev/\00"
@.str.1 = [30 x i8] c"/sys/block/%s/pdelta/%d/image\00"
@.str.2 = [31 x i8] c"/sys/block/%s/pdelta/%d/format\00"
@.str.3 = [4 x i8] c"raw\00"
@.str.4 = [7 x i8] c"ploop1\00"
@.str.5 = [8 x i8] c"unknown\00"
define i32 @find_delta_names(i8* %0, i32 %1, i32 %2, i8** %3, i8** %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8**
%11 = alloca i8**
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i64
%15 = alloca [4096 x i8]
%16 = alloca i32
store i8* %0, i8** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i8** %3, i8*** %10
store i8** %4, i8*** %11
%17 = load i32, i32* @PATH_MAX
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %13
%20 = alloca i8, i64 %18
store i64 %18, i64* %14
%21 = load i8*, i8** %7
%22 = call i64 @memcmp(i8* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %5
%25 = load i8*, i8** %7
%26 = getelementptr inbounds i8, i8* %25, i64 5
store i8* %26, i8** %7
br label %27
27: ; preds = %24, %5
store i32 0, i32* %12
br label %28
28: ; preds = %87, %27
%29 = load i32, i32* %12
%30 = load i32, i32* %9
%31 = load i32, i32* %8
%32 = sub nsw i32 %30, %31
%33 = icmp sle i32 %29, %32
br i1 %33, label %34, label %90
34: ; preds = %28
%35 = trunc i64 %18 to i32
%36 = load i8*, i8** %7
%37 = load i32, i32* %8
%38 = load i32, i32* %12
%39 = add nsw i32 %37, %38
%40 = call i32 @snprintf(i8* %20, i32 %35, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %36, i32 %39)
%41 = getelementptr inbounds [4096 x i8], [4096 x i8]* %15, i64 0, i64 0
%42 = call i64 @read_line(i8* %20, i8* %41, i32 4096)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %34
store i32 -1, i32* %6
store i32 1, i32* %16
br label %91
45: ; preds = %34
%46 = getelementptr inbounds [4096 x i8], [4096 x i8]* %15, i64 0, i64 0
%47 = call i8* @strdup(i8* %46)
%48 = load i8**, i8*** %10
%49 = load i32, i32* %9
%50 = load i32, i32* %8
%51 = sub nsw i32 %49, %50
%52 = load i32, i32* %12
%53 = sub nsw i32 %51, %52
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8*, i8** %48, i64 %54
store i8* %47, i8** %55
%56 = load i32, i32* %12
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %86
58: ; preds = %45
%59 = load i8**, i8*** %11
%60 = icmp ne i8** %59, null
br i1 %60, label %61, label %86
61: ; preds = %58
%62 = trunc i64 %18 to i32
%63 = load i8*, i8** %7
%64 = load i32, i32* %8
%65 = call i32 @snprintf(i8* %20, i32 %62, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %63, i32 %64)
%66 = getelementptr inbounds [4096 x i8], [4096 x i8]* %15, i64 0, i64 0
%67 = call i64 @read_line(i8* %20, i8* %66, i32 4096)
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %70
69: ; preds = %61
store i32 -1, i32* %6
store i32 1, i32* %16
br label %91
70: ; preds = %61
%71 = getelementptr inbounds [4096 x i8], [4096 x i8]* %15, i64 0, i64 0
%72 = call i64 @strcmp(i8* %71, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%73 = icmp eq i64 %72, 0
br i1 %73, label %74, label %76
74: ; preds = %70
%75 = load i8**, i8*** %11
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %75
br label %85
76: ; preds = %70
%77 = getelementptr inbounds [4096 x i8], [4096 x i8]* %15, i64 0, i64 0
%78 = call i64 @strcmp(i8* %77, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%79 = icmp eq i64 %78, 0
br i1 %79, label %80, label %82
80: ; preds = %76
%81 = load i8**, i8*** %11
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8** %81
br label %84
82: ; preds = %76
%83 = load i8**, i8*** %11
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8** %83
br label %84
84: ; preds = %82, %80
br label %85
85: ; preds = %84, %74
br label %86
86: ; preds = %85, %58, %45
br label %87
87: ; preds = %86
%88 = load i32, i32* %12
%89 = add nsw i32 %88, 1
store i32 %89, i32* %12
br label %28
90: ; preds = %28
store i32 0, i32* %6
store i32 1, i32* %16
br label %91
91: ; preds = %90, %69, %44
%92 = load i8*, i8** %13
%93 = load i32, i32* %6
ret i32 %93
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [6 x i8] c"/dev/\00"
@.str.1 = [30 x i8] c"/sys/block/%s/pdelta/%d/image\00"
@.str.2 = [31 x i8] c"/sys/block/%s/pdelta/%d/format\00"
@.str.3 = [4 x i8] c"raw\00"
@.str.4 = [7 x i8] c"ploop1\00"
@.str.5 = [8 x i8] c"unknown\00"
define i32 @find_delta_names(i8* %0, i32 %1, i32 %2, i8** nocapture writeonly %3, i8** writeonly %4) {
%6 = alloca [4096 x i8]
%7 = load i32, i32* @PATH_MAX
%8 = zext i32 %7 to i64
%9 = alloca i8, i64 %8
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%11 = tail call i64 @memcmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%12 = icmp eq i64 %11, 0
%13 = select i1 %12, i64 5, i64 0
%14 = getelementptr i8, i8* %0, i64 %13
%15 = sub nsw i32 %2, %1
%16 = icmp slt i32 %15, 0
br i1 %16, label %53, label %17
17: ; preds = %5
%18 = icmp ne i8** %4, null
%19 = add i32 %2, 1
%20 = sub i32 %19, %1
%21 = zext i32 %20 to i64
br label %22
22: ; preds = %17, %50
%23 = phi i64 [ 0, %17 ], [ %51, %50 ]
%24 = trunc i64 %23 to i32
%25 = add i32 %24, %1
%26 = call i32 @snprintf(i8* %9, i32 %7, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %14, i32 %25)
%27 = call i64 @read_line(i8* %9, i8* %10, i32 4096)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %53
29: ; preds = %22
%30 = trunc i64 %23 to i32
%31 = call i8* @strdup(i8* %10)
%32 = sub nsw i32 %15, %30
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %3, i64 %33
store i8* %31, i8** %34
%35 = icmp eq i64 %23, 0
%36 = and i1 %18, %35
br i1 %36, label %37, label %50
37: ; preds = %29
%38 = call i32 @snprintf(i8* %9, i32 %7, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %14, i32 %1)
%39 = call i64 @read_line(i8* %9, i8* %10, i32 4096)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %53
41: ; preds = %37
%42 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
br i1 %43, label %48, label %44
44: ; preds = %41
%45 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
%47 = select i1 %46, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0)
br label %48
48: ; preds = %44, %41
%49 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), %41 ], [ %47, %44 ]
store i8* %49, i8** %4
br label %50
50: ; preds = %48, %29
%51 = add nuw nsw i64 %23, 1
%52 = icmp eq i64 %51, %21
br i1 %52, label %53, label %22
53: ; preds = %22, %37, %50, %5
%54 = phi i32 [ 0, %5 ], [ 0, %50 ], [ -1, %37 ], [ -1, %22 ]
ret i32 %54
}