#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;

/* 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,
                            char const *);
int ploop_get_delta_attr_str(const char *device, int level, const char *attr,
                             char *out, int len) {
  char path[PATH_MAX];
  if (memcmp(device, "/dev/", 5) == 0)
    device += 5;
  snprintf(path, sizeof(path), "/sys/block/%s/pdelta/%d/%s", device, level,
           attr);
  if (read_line(path, out, len))
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<ploop_get_delta_attr_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    0x2e9e(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x58(%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,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7a(%rip),%rsi
mov    $0x5,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    11a6 <ploop_get_delta_attr_str+0x76>
mov    -0x10(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x10(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
mov    -0x20(%rbp),%r9
lea    0xe43(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1050 <read_line@plt>
cmp    $0x0,%rax
je     11f5 <ploop_get_delta_attr_str+0xc5>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    1203 <ploop_get_delta_attr_str+0xd3>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ploop_get_delta_attr_str>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,-0x2c(%rbp)
mov    %rcx,-0x38(%rbp)
mov    %rdx,%r12
mov    %esi,%r13d
mov    %rdi,%r15
mov    0x2e97(%rip),%rax
mov    (%rax),%ebx
mov    %rsp,%r14
mov    %rbx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
lea    0xe8a(%rip),%rsi
mov    $0x5,%edx
call   1040 <memcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
lea    (%rcx,%rcx,4),%rcx
add    %r15,%rcx
lea    0xe70(%rip),%rdx
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r13d,%r8d
mov    %r12,%r9
call   1030 <snprintf@plt>
mov    %r14,%rdi
mov    -0x38(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1050 <read_line@plt>
neg    %rax
sbb    %eax,%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 = [27 x i8] c"/sys/block/%s/pdelta/%d/%s\00"
define i32 @ploop_get_delta_attr_str(i8* %0, i32 %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32
store i8* %0, i8** %7
store i32 %1, i32* %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%15 = load i32, i32* @PATH_MAX
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %12
%18 = alloca i8, i64 %16
store i64 %16, i64* %13
%19 = load i8*, i8** %7
%20 = call i64 @memcmp(i8* %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %5
%23 = load i8*, i8** %7
%24 = getelementptr inbounds i8, i8* %23, i64 5
store i8* %24, i8** %7
br label %25
25: ; preds = %22, %5
%26 = trunc i64 %16 to i32
%27 = load i8*, i8** %7
%28 = load i32, i32* %8
%29 = load i8*, i8** %9
%30 = call i32 @snprintf(i8* %18, i32 %26, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %27, i32 %28, i8* %29)
%31 = load i8*, i8** %10
%32 = load i32, i32* %11
%33 = call i64 @read_line(i8* %18, i8* %31, i32 %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %25
store i32 -1, i32* %6
store i32 1, i32* %14
br label %37
36: ; preds = %25
store i32 0, i32* %6
store i32 1, i32* %14
br label %37
37: ; preds = %36, %35
%38 = load i8*, i8** %12
%39 = load i32, i32* %6
ret i32 %39
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [6 x i8] c"/dev/\00"
@.str.1 = [27 x i8] c"/sys/block/%s/pdelta/%d/%s\00"
define i32 @ploop_get_delta_attr_str(i8* %0, i32 %1, i8* %2, i8* %3, i32 %4) {
%6 = load i32, i32* @PATH_MAX
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = tail call i64 @memcmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i64 5, i64 0
%12 = getelementptr i8, i8* %0, i64 %11
%13 = call i32 @snprintf(i8* %8, i32 %6, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %12, i32 %1, i8* %2)
%14 = call i64 @read_line(i8* %8, i8* %3, i32 %4)
%15 = icmp ne i64 %14, 0
%16 = sext i1 %15 to i32
ret i32 %16
}