#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 sscanf(char *, char *, unsigned long *, unsigned long *, unsigned long *,
           unsigned long *, unsigned long *, unsigned long *, unsigned long *,
           unsigned long *, unsigned long *, unsigned long *);
int read_cpu_fields(FILE *fp, unsigned long *fields) {
  int retval;
  char buffer[1024] = {0};
  unsigned long total_tick = 0;
  if (!fgets(buffer, 1024, fp)) {
    return 0;
  }
  retval = sscanf(buffer, "%*s %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) {
    return 0;
  }
  int i = 0;
  for (i = 0; i < 10; i++)
    total_tick += fields[i];
  return total_tick ? 1 : 0;
}


x86 assembly (clang, -O0):
<read_cpu_fields>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x468,%rsp
mov    %rdi,-0x28(%rbp)
mov    %rsi,-0x30(%rbp)
lea    -0x440(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
movq   $0x0,-0x448(%rbp)
lea    -0x440(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
cmp    $0x0,%eax
jne    1190 <read_cpu_fields+0x60>
movl   $0x0,-0x1c(%rbp)
jmp    128f <read_cpu_fields+0x15f>
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    0xe16(%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    1225 <read_cpu_fields+0xf5>
movl   $0x0,-0x1c(%rbp)
jmp    128f <read_cpu_fields+0x15f>
movl   $0x0,-0x44c(%rbp)
movl   $0x0,-0x44c(%rbp)
cmpl   $0xa,-0x44c(%rbp)
jge    1277 <read_cpu_fields+0x147>
mov    -0x30(%rbp),%rax
movslq -0x44c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
add    -0x448(%rbp),%rax
mov    %rax,-0x448(%rbp)
mov    -0x44c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44c(%rbp)
jmp    1239 <read_cpu_fields+0x109>
mov    -0x448(%rbp),%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x468,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_cpu_fields>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %rsp,%r15
xor    %r14d,%r14d
mov    $0x400,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
mov    %r15,%rdi
mov    $0x400,%esi
mov    %rbp,%rdx
call   1040 <fgets@plt>
test   %eax,%eax
je     11f7 <read_cpu_fields+0xc7>
lea    0x8(%rbx),%rcx
lea    0x10(%rbx),%r8
lea    0x18(%rbx),%r9
lea    0x20(%rbx),%r10
lea    0x28(%rbx),%r11
lea    0x30(%rbx),%r15
lea    0x38(%rbx),%r12
lea    0x40(%rbx),%rax
lea    0x48(%rbx),%rbp
lea    0xe63(%rip),%rsi
mov    %rsp,%rdi
mov    %rbx,%rdx
push   %rbp
push   %rax
push   %r12
push   %r15
push   %r11
push   %r10
call   1050 <sscanf@plt>
add    $0x30,%rsp
cmp    $0x4,%eax
jl     11f7 <read_cpu_fields+0xc7>
movdqu 0x8(%rbx),%xmm0
movdqu 0x18(%rbx),%xmm1
movdqu 0x28(%rbx),%xmm2
paddq  %xmm0,%xmm2
movdqu 0x38(%rbx),%xmm0
paddq  %xmm1,%xmm0
paddq  %xmm2,%xmm0
pshufd $0xee,%xmm0,%xmm1
paddq  %xmm0,%xmm1
movq   %xmm1,%rax
add    (%rbx),%rax
xor    %r14d,%r14d
add    0x48(%rbx),%rax
setne  %r14b
mov    %r14d,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"%*s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\00"
define i32 @read_cpu_fields(i32* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i64*
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca i64
%9 = alloca i32
store i32* %0, i32** %4
store i64* %1, i64** %5
%10 = bitcast [1024 x i8]* %7 to i8*
store i64 0, i64* %8
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%12 = load i32*, i32** %4
%13 = call i32 @fgets(i8* %11, i32 1024, i32* %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %2
store i32 0, i32* %3
br label %62
16: ; preds = %2
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%18 = load i64*, i64** %5
%19 = getelementptr inbounds i64, i64* %18, i64 0
%20 = load i64*, i64** %5
%21 = getelementptr inbounds i64, i64* %20, i64 1
%22 = load i64*, i64** %5
%23 = getelementptr inbounds i64, i64* %22, i64 2
%24 = load i64*, i64** %5
%25 = getelementptr inbounds i64, i64* %24, i64 3
%26 = load i64*, i64** %5
%27 = getelementptr inbounds i64, i64* %26, i64 4
%28 = load i64*, i64** %5
%29 = getelementptr inbounds i64, i64* %28, i64 5
%30 = load i64*, i64** %5
%31 = getelementptr inbounds i64, i64* %30, i64 6
%32 = load i64*, i64** %5
%33 = getelementptr inbounds i64, i64* %32, i64 7
%34 = load i64*, i64** %5
%35 = getelementptr inbounds i64, i64* %34, i64 8
%36 = load i64*, i64** %5
%37 = getelementptr inbounds i64, i64* %36, i64 9
%38 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i64* %19, i64* %21, i64* %23, i64* %25, i64* %27, i64* %29, i64* %31, i64* %33, i64* %35, i64* %37)
store i32 %38, i32* %6
%39 = load i32, i32* %6
%40 = icmp slt i32 %39, 4
br i1 %40, label %41, label %42
41: ; preds = %16
store i32 0, i32* %3
br label %62
42: ; preds = %16
store i32 0, i32* %9
store i32 0, i32* %9
br label %43
43: ; preds = %54, %42
%44 = load i32, i32* %9
%45 = icmp slt i32 %44, 10
br i1 %45, label %46, label %57
46: ; preds = %43
%47 = load i64*, i64** %5
%48 = load i32, i32* %9
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i64, i64* %47, i64 %49
%51 = load i64, i64* %50
%52 = load i64, i64* %8
%53 = add i64 %52, %51
store i64 %53, i64* %8
br label %54
54: ; preds = %46
%55 = load i32, i32* %9
%56 = add nsw i32 %55, 1
store i32 %56, i32* %9
br label %43
57: ; preds = %43
%58 = load i64, i64* %8
%59 = icmp ne i64 %58, 0
%60 = zext i1 %59 to i64
%61 = select i1 %59, i32 1, i32 0
store i32 %61, i32* %3
br label %62
62: ; preds = %57, %41, %15
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@.str = [44 x i8] c"%*s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\00"
define i32 @read_cpu_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 %29, label %7
7: ; preds = %2
%8 = getelementptr inbounds i64, i64* %1, i64 1
%9 = getelementptr inbounds i64, i64* %1, i64 2
%10 = getelementptr inbounds i64, i64* %1, i64 3
%11 = getelementptr inbounds i64, i64* %1, i64 4
%12 = getelementptr inbounds i64, i64* %1, i64 5
%13 = getelementptr inbounds i64, i64* %1, i64 6
%14 = getelementptr inbounds i64, i64* %1, i64 7
%15 = getelementptr inbounds i64, i64* %1, i64 8
%16 = getelementptr inbounds i64, i64* %1, i64 9
%17 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i64* %1, i64* %8, i64* %9, i64* %10, i64* %11, i64* %12, i64* %13, i64* %14, i64* %15, i64* %16)
%18 = icmp slt i32 %17, 4
br i1 %18, label %29, label %19
19: ; preds = %7
%20 = load i64, i64* %1
%21 = bitcast i64* %8 to <8 x i64>*
%22 = load <8 x i64>, <8 x i64>* %21
%23 = call i64 @llvm.vector.reduce.add.v8i64(<8 x i64> %22)
%24 = add i64 %23, %20
%25 = load i64, i64* %16
%26 = sub i64 0, %24
%27 = icmp ne i64 %25, %26
%28 = zext i1 %27 to i32
br label %29
29: ; preds = %7, %2, %19
%30 = phi i32 [ %28, %19 ], [ 0, %2 ], [ 0, %7 ]
ret i32 %30
}