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

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int sscanf(char *, char *, unsigned long long *, unsigned long long *,
           unsigned long long *, unsigned long long *, unsigned long long *,
           unsigned long long *, unsigned long long *, unsigned long long *,
           unsigned long long *, unsigned long long *);
int /*<<< orphan*/ stderr;
int read_fields(FILE *fp, unsigned long long int *fields) {
  int retval;
  char buffer[1024];
  if (!fgets(buffer, 1024, fp)) {
    perror("Error");
  }
  retval = sscanf(buffer, "cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu",
                  &fields[0], &fields[1], &fields[2], &fields[3], &fields[4],
                  &fields[5], &fields[6], &fields[7], &fields[8], &fields[9]);
  if (retval < 4) {
    fprintf(stderr, "Error reading /proc/stat cpu field\n");
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<read_fields>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x458,%rsp
mov    %rdi,-0x28(%rbp)
mov    %rsi,-0x30(%rbp)
lea    -0x440(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x400,%esi
call   1030 <fgets@plt>
cmp    $0x0,%eax
jne    1182 <read_fields+0x42>
lea    0xe83(%rip),%rdi
call   1060 <perror@plt>
lea    -0x440(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x30(%rbp),%rcx
add    $0x8,%rcx
mov    -0x30(%rbp),%r8
add    $0x10,%r8
mov    -0x30(%rbp),%r9
add    $0x18,%r9
mov    -0x30(%rbp),%r15
add    $0x20,%r15
mov    -0x30(%rbp),%r14
add    $0x28,%r14
mov    -0x30(%rbp),%rbx
add    $0x30,%rbx
mov    -0x30(%rbp),%r11
add    $0x38,%r11
mov    -0x30(%rbp),%r10
add    $0x40,%r10
mov    -0x30(%rbp),%rax
add    $0x48,%rax
lea    0xe2a(%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   1050 <sscanf@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x4,-0x34(%rbp)
jge    122c <read_fields+0xec>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
lea    0xe17(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x1c(%rbp)
jmp    1233 <read_fields+0xf3>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x458,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_fields>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbx
mov    %rdi,%rdx
mov    %rsp,%rdi
mov    $0x400,%esi
call   1030 <fgets@plt>
test   %eax,%eax
je     11dc <read_fields+0x9c>
lea    0x8(%rbx),%rcx
lea    0x10(%rbx),%r8
lea    0x18(%rbx),%r9
lea    0x20(%rbx),%r10
lea    0x28(%rbx),%r11
lea    0x30(%rbx),%r14
lea    0x38(%rbx),%r15
lea    0x40(%rbx),%r12
lea    0x48(%rbx),%rax
lea    0xe76(%rip),%rsi
mov    %rsp,%rdi
mov    %rbx,%rdx
push   %rax
push   %r12
push   %r15
push   %r14
push   %r11
push   %r10
call   1050 <sscanf@plt>
add    $0x30,%rsp
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0x3,%ecx
jg     11cd <read_fields+0x8d>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe1d(%rip),%rdi
call   1060 <perror@plt>
jmp    1165 <read_fields+0x25>

LLVM IR (-O0):
@.str = [6 x i8] c"Error\00"
@.str.1 = [44 x i8] c"cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu\00"
@stderr = global i32 0
@.str.2 = [36 x i8] c"Error reading /proc/stat cpu field\0A\00"
define i32 @read_fields(i32* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i64*
%6 = alloca i32
%7 = alloca [1024 x i8]
store i32* %0, i32** %4
store i64* %1, i64** %5
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%9 = load i32*, i32** %4
%10 = call i32 @fgets(i8* %8, i32 1024, i32* %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%16 = load i64*, i64** %5
%17 = getelementptr inbounds i64, i64* %16, i64 0
%18 = load i64*, i64** %5
%19 = getelementptr inbounds i64, i64* %18, i64 1
%20 = load i64*, i64** %5
%21 = getelementptr inbounds i64, i64* %20, i64 2
%22 = load i64*, i64** %5
%23 = getelementptr inbounds i64, i64* %22, i64 3
%24 = load i64*, i64** %5
%25 = getelementptr inbounds i64, i64* %24, i64 4
%26 = load i64*, i64** %5
%27 = getelementptr inbounds i64, i64* %26, i64 5
%28 = load i64*, i64** %5
%29 = getelementptr inbounds i64, i64* %28, i64 6
%30 = load i64*, i64** %5
%31 = getelementptr inbounds i64, i64* %30, i64 7
%32 = load i64*, i64** %5
%33 = getelementptr inbounds i64, i64* %32, i64 8
%34 = load i64*, i64** %5
%35 = getelementptr inbounds i64, i64* %34, i64 9
%36 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i64* %17, i64* %19, i64* %21, i64* %23, i64* %25, i64* %27, i64* %29, i64* %31, i64* %33, i64* %35)
store i32 %36, i32* %6
%37 = load i32, i32* %6
%38 = icmp slt i32 %37, 4
br i1 %38, label %39, label %42
39: ; preds = %14
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %43
42: ; preds = %14
store i32 1, i32* %3
br label %43
43: ; preds = %42, %39
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [6 x i8] c"Error\00"
@.str.1 = [44 x i8] c"cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu\00"
@stderr = global i32 0
@.str.2 = [36 x i8] c"Error reading /proc/stat cpu field\0A\00"
define i32 @read_fields(i32* nocapture %0, i64* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32 @fgets(i8* %4, i32 1024, i32* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %2
%10 = getelementptr inbounds i64, i64* %1, i64 1
%11 = getelementptr inbounds i64, i64* %1, i64 2
%12 = getelementptr inbounds i64, i64* %1, i64 3
%13 = getelementptr inbounds i64, i64* %1, i64 4
%14 = getelementptr inbounds i64, i64* %1, i64 5
%15 = getelementptr inbounds i64, i64* %1, i64 6
%16 = getelementptr inbounds i64, i64* %1, i64 7
%17 = getelementptr inbounds i64, i64* %1, i64 8
%18 = getelementptr inbounds i64, i64* %1, i64 9
%19 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i64* %1, i64* %10, i64* %11, i64* %12, i64* %13, i64* %14, i64* %15, i64* %16, i64* %17, i64* %18)
%20 = icmp slt i32 %19, 4
br i1 %20, label %21, label %24
21: ; preds = %9
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %9, %21
%25 = phi i32 [ 0, %21 ], [ 1, %9 ]
ret i32 %25
}