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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int errno;
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ read(int, char *, int);
int sscanf(char *, char *, long long *, long long *, long long *, long long *,
           long long *, long long *, long long *, long long *, long long *,
           long long *);
int statread(int statfd, long long *total, long long *idle) {
  long long val[10];
  char buf[256];
  int i, err = 0;
  if (lseek(statfd, 0, SEEK_SET) == -1) {
    err = errno;
    perror("lseek");
    goto out;
  }
  memset(buf, 0, sizeof(buf));
  if (read(statfd, buf, sizeof(buf) - 1) <= 0) {
    err = (errno) ? errno : -1;
    perror("read");
    goto out;
  }
  if (sscanf(buf, "cpu %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld",
             &val[0], &val[1], &val[2], &val[3], &val[4], &val[5], &val[6],
             &val[7], &val[8], &val[9]) != 10) {
    err = (errno) ? errno : -1;
    perror("sscanf");
    goto out;
  }
  *idle = val[3];
  *total = 0;
  for (i = 0; i < 10; i++)
    *total += val[i];
out:
  return err;
}


x86 assembly (clang, -O0):
<statread>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1a8,%rsp
mov    %edi,-0x1c(%rbp)
mov    %rsi,-0x28(%rbp)
mov    %rdx,-0x30(%rbp)
movl   $0x0,-0x188(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2e59(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
cmp    $0xffffffff,%eax
jne    11b1 <statread+0x61>
mov    0x2e48(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x188(%rbp)
lea    0xe59(%rip),%rdi
call   1070 <perror@plt>
jmp    1365 <statread+0x215>
lea    -0x180(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
mov    -0x1c(%rbp),%edi
lea    -0x180(%rbp),%rsi
mov    $0xff,%edx
call   1050 <read@plt>
cmp    $0x0,%rax
jg     1233 <statread+0xe3>
mov    0x2df7(%rip),%rax
cmpl   $0x0,(%rax)
je     1206 <statread+0xb6>
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18c(%rbp)
jmp    1216 <statread+0xc6>
mov    $0xffffffff,%eax
mov    %eax,-0x18c(%rbp)
jmp    1216 <statread+0xc6>
mov    -0x18c(%rbp),%eax
mov    %eax,-0x188(%rbp)
lea    0xddd(%rip),%rdi
call   1070 <perror@plt>
jmp    1365 <statread+0x215>
lea    -0x180(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    -0x80(%rbp),%rcx
add    $0x8,%rcx
lea    -0x80(%rbp),%r8
add    $0x10,%r8
lea    -0x80(%rbp),%r9
add    $0x18,%r9
lea    -0x80(%rbp),%r15
add    $0x20,%r15
lea    -0x80(%rbp),%r14
add    $0x28,%r14
lea    -0x80(%rbp),%rbx
add    $0x30,%rbx
lea    -0x80(%rbp),%r11
add    $0x38,%r11
lea    -0x80(%rbp),%r10
add    $0x40,%r10
lea    -0x80(%rbp),%rax
add    $0x48,%rax
lea    0xd7e(%rip),%rsi
mov    %r15,(%rsp)
mov    %r14,0x8(%rsp)
mov    %rbx,0x10(%rsp)
mov    %r11,0x18(%rsp)
mov    %r10,0x20(%rsp)
mov    %rax,0x28(%rsp)
call   1060 <sscanf@plt>
cmp    $0xa,%eax
je     1309 <statread+0x1b9>
mov    0x2d21(%rip),%rax
cmpl   $0x0,(%rax)
je     12dc <statread+0x18c>
mov    0x2d11(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x190(%rbp)
jmp    12ec <statread+0x19c>
mov    $0xffffffff,%eax
mov    %eax,-0x190(%rbp)
jmp    12ec <statread+0x19c>
mov    -0x190(%rbp),%eax
mov    %eax,-0x188(%rbp)
lea    0xd42(%rip),%rdi
call   1070 <perror@plt>
jmp    1365 <statread+0x215>
mov    -0x68(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x184(%rbp)
cmpl   $0xa,-0x184(%rbp)
jge    1360 <statread+0x210>
movslq -0x184(%rbp),%rax
mov    -0x80(%rbp,%rax,8),%rcx
mov    -0x28(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x184(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x184(%rbp)
jmp    1329 <statread+0x1d9>
jmp    1365 <statread+0x215>
mov    -0x188(%rbp),%eax
add    $0x1a8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<statread>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x150,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2e6a(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
cmp    $0xffffffff,%eax
je     1251 <statread+0x101>
lea    0x50(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xff,%edx
call   1050 <read@plt>
test   %rax,%rax
jle    1268 <statread+0x118>
lea    0x8(%rsp),%rcx
lea    0x10(%rsp),%r8
lea    0x18(%rsp),%r9
lea    0x20(%rsp),%r10
lea    0x28(%rsp),%r11
lea    0x30(%rsp),%r12
lea    0x38(%rsp),%rax
lea    0x40(%rsp),%rbp
lea    0x48(%rsp),%rbx
lea    0xe2b(%rip),%rsi
lea    0x50(%rsp),%rdi
mov    %rsp,%rdx
push   %rbx
push   %rbp
push   %rax
push   %r12
push   %r11
push   %r10
call   1060 <sscanf@plt>
add    $0x30,%rsp
cmp    $0xa,%eax
jne    1286 <statread+0x136>
mov    0x18(%rsp),%rax
mov    %rax,(%r15)
mov    (%rsp),%rcx
add    0x8(%rsp),%rcx
add    0x10(%rsp),%rcx
add    %rax,%rcx
add    0x20(%rsp),%rcx
add    0x28(%rsp),%rcx
add    0x30(%rsp),%rcx
add    0x38(%rsp),%rcx
add    0x40(%rsp),%rcx
add    0x48(%rsp),%rcx
mov    %rcx,(%r14)
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x150,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d88(%rip),%rax
mov    (%rax),%ebx
lea    0xd9f(%rip),%rdi
call   1070 <perror@plt>
jmp    123f <statread+0xef>
mov    0x2d71(%rip),%rax
mov    (%rax),%eax
cmp    $0x1,%eax
sbb    %ebx,%ebx
or     %eax,%ebx
lea    0xd87(%rip),%rdi
call   1070 <perror@plt>
jmp    123f <statread+0xef>
mov    0x2d53(%rip),%rax
mov    (%rax),%eax
cmp    $0x1,%eax
sbb    %ebx,%ebx
or     %eax,%ebx
lea    0xda4(%rip),%rdi
call   1070 <perror@plt>
jmp    123f <statread+0xef>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@errno = global i32 0
@.str = [6 x i8] c"lseek\00"
@.str.1 = [5 x i8] c"read\00"
@.str.2 = [54 x i8] c"cpu %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld\00"
@.str.3 = [7 x i8] c"sscanf\00"
define i32 @statread(i32 %0, i64* %1, i64* %2) {
%4 = alloca i32
%5 = alloca i64*
%6 = alloca i64*
%7 = alloca [10 x i64]
%8 = alloca [256 x i8]
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i64* %1, i64** %5
store i64* %2, i64** %6
store i32 0, i32* %10
%11 = load i32, i32* %4
%12 = load i32, i32* @SEEK_SET
%13 = call i32 @lseek(i32 %11, i32 0, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = load i32, i32* @errno
store i32 %16, i32* %10
%17 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %77
18: ; preds = %3
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%20 = call i32 @memset(i8* %19, i32 0, i32 256)
%21 = load i32, i32* %4
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%23 = call i64 @read(i32 %21, i8* %22, i32 255)
%24 = icmp sle i64 %23, 0
br i1 %24, label %25, label %34
25: ; preds = %18
%26 = load i32, i32* @errno
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = load i32, i32* @errno
br label %31
30: ; preds = %25
br label %31
31: ; preds = %30, %28
%32 = phi i32 [ %29, %28 ], [ -1, %30 ]
store i32 %32, i32* %10
%33 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %77
34: ; preds = %18
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%36 = getelementptr inbounds [10 x i64], [10 x i64]* %7, i64 0, i64 0
%37 = getelementptr inbounds [10 x i64], [10 x i64]* %7, i64 0, i64 1
%38 = getelementptr inbounds [10 x i64], [10 x i64]* %7, i64 0, i64 2
%39 = getelementptr inbounds [10 x i64], [10 x i64]* %7, i64 0, i64 3
%40 = getelementptr inbounds [10 x i64], [10 x i64]* %7, i64 0, i64 4
%41 = getelementptr inbounds [10 x i64], [10 x i64]* %7, i64 0, i64 5
%42 = getelementptr inbounds [10 x i64], [10 x i64]* %7, i64 0, i64 6
%43 = getelementptr inbounds [10 x i64], [10 x i64]* %7, i64 0, i64 7
%44 = getelementptr inbounds [10 x i64], [10 x i64]* %7, i64 0, i64 8
%45 = getelementptr inbounds [10 x i64], [10 x i64]* %7, i64 0, i64 9
%46 = call i32 @sscanf(i8* %35, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i64* %36, i64* %37, i64* %38, i64* %39, i64* %40, i64* %41, i64* %42, i64* %43, i64* %44, i64* %45)
%47 = icmp ne i32 %46, 10
br i1 %47, label %48, label %57
48: ; preds = %34
%49 = load i32, i32* @errno
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %48
%52 = load i32, i32* @errno
br label %54
53: ; preds = %48
br label %54
54: ; preds = %53, %51
%55 = phi i32 [ %52, %51 ], [ -1, %53 ]
store i32 %55, i32* %10
%56 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %77
57: ; preds = %34
%58 = getelementptr inbounds [10 x i64], [10 x i64]* %7, i64 0, i64 3
%59 = load i64, i64* %58
%60 = load i64*, i64** %6
store i64 %59, i64* %60
%61 = load i64*, i64** %5
store i64 0, i64* %61
store i32 0, i32* %9
br label %62
62: ; preds = %73, %57
%63 = load i32, i32* %9
%64 = icmp slt i32 %63, 10
br i1 %64, label %65, label %76
65: ; preds = %62
%66 = load i32, i32* %9
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [10 x i64], [10 x i64]* %7, i64 0, i64 %67
%69 = load i64, i64* %68
%70 = load i64*, i64** %5
%71 = load i64, i64* %70
%72 = add nsw i64 %71, %69
store i64 %72, i64* %70
br label %73
73: ; preds = %65
%74 = load i32, i32* %9
%75 = add nsw i32 %74, 1
store i32 %75, i32* %9
br label %62
76: ; preds = %62
br label %77
77: ; preds = %76, %54, %31, %15
%78 = load i32, i32* %10
ret i32 %78
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@errno = global i32 0
@.str = [6 x i8] c"lseek\00"
@.str.1 = [5 x i8] c"read\00"
@.str.2 = [54 x i8] c"cpu %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld\00"
@.str.3 = [7 x i8] c"sscanf\00"
define i32 @statread(i32 %0, i64* nocapture %1, i64* nocapture writeonly %2) {
%4 = alloca [10 x i64]
%5 = alloca [256 x i8]
%6 = bitcast [10 x i64]* %4 to i8*
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%8 = load i32, i32* @SEEK_SET
%9 = tail call i32 @lseek(i32 %0, i32 0, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i32, i32* @errno
%13 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %61
14: ; preds = %3
%15 = call i32 @memset(i8* %7, i32 0, i32 256)
%16 = call i64 @read(i32 %0, i8* %7, i32 255)
%17 = icmp slt i64 %16, 1
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i32, i32* @errno
%20 = icmp eq i32 %19, 0
%21 = select i1 %20, i32 -1, i32 %19
%22 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %61
23: ; preds = %14
%24 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 0
%25 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 1
%26 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 2
%27 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 3
%28 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 4
%29 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 5
%30 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 6
%31 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 7
%32 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 8
%33 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 9
%34 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i64* %24, i64* %25, i64* %26, i64* %27, i64* %28, i64* %29, i64* %30, i64* %31, i64* %32, i64* %33)
%35 = icmp eq i32 %34, 10
br i1 %35, label %41, label %36
36: ; preds = %23
%37 = load i32, i32* @errno
%38 = icmp eq i32 %37, 0
%39 = select i1 %38, i32 -1, i32 %37
%40 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %61
41: ; preds = %23
%42 = load i64, i64* %27
store i64 %42, i64* %2
%43 = load i64, i64* %24
%44 = load i64, i64* %25
%45 = add nsw i64 %43, %44
%46 = load i64, i64* %26
%47 = add nsw i64 %45, %46
%48 = add nsw i64 %47, %42
%49 = load i64, i64* %28
%50 = add nsw i64 %48, %49
%51 = load i64, i64* %29
%52 = add nsw i64 %50, %51
%53 = load i64, i64* %30
%54 = add nsw i64 %52, %53
%55 = load i64, i64* %31
%56 = add nsw i64 %54, %55
%57 = load i64, i64* %32
%58 = add nsw i64 %56, %57
%59 = load i64, i64* %33
%60 = add nsw i64 %58, %59
store i64 %60, i64* %1
br label %61
61: ; preds = %41, %36, %18, %11
%62 = phi i32 [ %12, %11 ], [ %21, %18 ], [ %39, %36 ], [ 0, %41 ]
ret i32 %62
}