#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;
int /*<<< orphan*/ __ploop_err(int /*<<< orphan*/, char *, char *, char *);
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 sscanf(char *, char *, int *);
int ploop_get_delta_attr(const char *device, int level, const char *attr,
                         int *res) {
  char path[PATH_MAX];
  char nbuf[4096];
  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, nbuf, sizeof(nbuf)))
    return -1;
  if (sscanf(nbuf, "%d", res) != 1) {
    __ploop_err(0, "Unexpected format of %s: %s", path, nbuf);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ploop_get_delta_attr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1060,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x1058(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x30(%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,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe55(%rip),%rsi
mov    $0x5,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    11cb <ploop_get_delta_attr+0x7b>
mov    -0x10(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x10(%rbp)
mov    -0x1050(%rbp),%rdi
mov    -0x1058(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
mov    -0x20(%rbp),%r9
lea    0xe18(%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     122b <ploop_get_delta_attr+0xdb>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x1044(%rbp)
jmp    128e <ploop_get_delta_attr+0x13e>
lea    -0x1040(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xde4(%rip),%rsi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     127d <ploop_get_delta_attr+0x12d>
mov    -0x1050(%rbp),%rdx
lea    -0x1040(%rbp),%rcx
xor    %edi,%edi
lea    0xdc2(%rip),%rsi
call   1070 <__ploop_err@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x1044(%rbp)
jmp    128e <ploop_get_delta_attr+0x13e>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x1044(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ploop_get_delta_attr>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %rcx,-0x30(%rbp)
mov    %rdx,%r15
mov    %esi,%r12d
mov    %rdi,%r14
mov    0x2e78(%rip),%rax
mov    (%rax),%r13d
mov    %rsp,%rbx
mov    %r13,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe6a(%rip),%rsi
mov    $0x5,%edx
call   1040 <memcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
lea    (%rcx,%rcx,4),%rcx
add    %r14,%rcx
lea    0xe50(%rip),%rdx
mov    %rbx,%rdi
mov    %r13d,%esi
mov    %r12d,%r8d
mov    %r15,%r9
call   1030 <snprintf@plt>
lea    -0x1030(%rbp),%rsi
mov    %rbx,%rdi
mov    $0x1000,%edx
call   1060 <read_line@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    1225 <ploop_get_delta_attr+0xd5>
lea    0xe32(%rip),%rsi
lea    -0x1030(%rbp),%rdi
mov    -0x30(%rbp),%rdx
call   1050 <sscanf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
je     1225 <ploop_get_delta_attr+0xd5>
lea    0xe15(%rip),%rsi
lea    -0x1030(%rbp),%rcx
xor    %edi,%edi
mov    %rbx,%rdx
call   1070 <__ploop_err@plt>
mov    $0xffffffff,%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"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [28 x i8] c"Unexpected format of %s: %s\00"
define i32 @ploop_get_delta_attr(i8* %0, i32 %1, i8* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca [4096 x i8]
%13 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32* %3, i32** %9
%14 = load i32, i32* @PATH_MAX
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %10
%17 = alloca i8, i64 %15
store i64 %15, i64* %11
%18 = load i8*, i8** %6
%19 = call i64 @memcmp(i8* %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %4
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i64 5
store i8* %23, i8** %6
br label %24
24: ; preds = %21, %4
%25 = trunc i64 %15 to i32
%26 = load i8*, i8** %6
%27 = load i32, i32* %7
%28 = load i8*, i8** %8
%29 = call i32 @snprintf(i8* %17, i32 %25, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %26, i32 %27, i8* %28)
%30 = getelementptr inbounds [4096 x i8], [4096 x i8]* %12, i64 0, i64 0
%31 = call i64 @read_line(i8* %17, i8* %30, i32 4096)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %24
store i32 -1, i32* %5
store i32 1, i32* %13
br label %43
34: ; preds = %24
%35 = getelementptr inbounds [4096 x i8], [4096 x i8]* %12, i64 0, i64 0
%36 = load i32*, i32** %9
%37 = call i32 @sscanf(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %36)
%38 = icmp ne i32 %37, 1
br i1 %38, label %39, label %42
39: ; preds = %34
%40 = getelementptr inbounds [4096 x i8], [4096 x i8]* %12, i64 0, i64 0
%41 = call i32 @__ploop_err(i32 0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %17, i8* %40)
store i32 -1, i32* %5
store i32 1, i32* %13
br label %43
42: ; preds = %34
store i32 0, i32* %5
store i32 1, i32* %13
br label %43
43: ; preds = %42, %39, %33
%44 = load i8*, i8** %10
%45 = load i32, i32* %5
ret i32 %45
}

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"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [28 x i8] c"Unexpected format of %s: %s\00"
define i32 @ploop_get_delta_attr(i8* %0, i32 %1, i8* %2, i32* %3) {
%5 = alloca [4096 x i8]
%6 = load i32, i32* @PATH_MAX
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%10 = tail call i64 @memcmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, i64 5, i64 0
%13 = getelementptr i8, i8* %0, i64 %12
%14 = call i32 @snprintf(i8* %8, i32 %6, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %13, i32 %1, i8* %2)
%15 = call i64 @read_line(i8* %8, i8* %9, i32 4096)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %4
%18 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%19 = icmp eq i32 %18, 1
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = call i32 @__ploop_err(i32 0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %8, i8* %9)
br label %22
22: ; preds = %17, %4, %20
%23 = phi i32 [ -1, %20 ], [ -1, %4 ], [ 0, %17 ]
ret i32 %23
}