#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*/ data;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EINVAL;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getpid();
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int sscanf(char *, char *, char *, int *, int *, int *, int *, int *,
           unsigned long *, unsigned long *, unsigned long *, unsigned long *,
           unsigned long *, unsigned long *, unsigned long *);
char *strrchr(char *, char);
int cpu_test_usage(unsigned long *sys_utime, unsigned long *sys_stime) {
  FILE *f;
  char path[64];
  char *ptr, data[256], status;
  char fmt[] = " %c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu ";
  int num, good_num = 13, err;
  int ppid, pgrp, session, tty, tpgid;
  unsigned long flags, minflt, cminflt, majflt, cmajflt, utime, stime;
  snprintf(path, sizeof(path), "/proc/%d/stat", getpid());
  f = fopen(path, "r");
  if (!f) {
    ;
    return 1;
  }
  err = -EINVAL;
  ptr = fgets(data, sizeof(data), f);
  if (!ptr) {
    ;
    goto err_out_close;
  }
  fclose(f);
  data[sizeof(data) - 1] = '\0';
  ptr = strrchr(data, ')');
  if (!ptr) {
    ;
    goto err_out_exit;
  }
  ptr++;
  if (!ptr || !*ptr) {
    ;
    goto err_out_exit;
  }
  num = sscanf(ptr, fmt, &status, &ppid, &pgrp, &session, &tty, &tpgid, &flags,
               &minflt, &cminflt, &majflt, &cmajflt, &utime, &stime);
  if (num != good_num) {
    ;
    goto err_out_exit;
  }
  *sys_utime = utime;
  *sys_stime = stime;
  return 0;
err_out_close:
  fclose(f);
err_out_exit:
  return -1;
}


x86 assembly (clang, -O0):
<cpu_test_usage>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x278,%rsp
mov    %rdi,-0x38(%rbp)
mov    %rsi,-0x40(%rbp)
lea    -0x1e0(%rbp),%rdi
lea    0xe56(%rip),%rsi
mov    $0x30,%edx
call   1080 <memcpy@plt>
movl   $0xd,-0x1e8(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0x240(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x240(%rbp),%rdi
mov    %eax,%ecx
mov    $0x40,%esi
lea    0xe48(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x90(%rbp),%rdi
lea    0xe43(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    121b <cpu_test_usage+0x9b>
movl   $0x1,-0x2c(%rbp)
jmp    13d6 <cpu_test_usage+0x256>
xor    %eax,%eax
mov    0x2dbc(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x1ec(%rbp)
lea    -0x1a0(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    $0x100,%esi
call   1070 <fgets@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
jne    125b <cpu_test_usage+0xdb>
jmp    13c6 <cpu_test_usage+0x246>
mov    -0x48(%rbp),%rdi
call   1040 <fclose@plt>
movb   $0x0,-0xa1(%rbp)
lea    -0x1a0(%rbp),%rdi
mov    $0x29,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
jne    1296 <cpu_test_usage+0x116>
jmp    13cf <cpu_test_usage+0x24f>
mov    -0x98(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
je     12c6 <cpu_test_usage+0x146>
mov    -0x98(%rbp),%rax
cmpb   $0x0,(%rax)
jne    12cb <cpu_test_usage+0x14b>
jmp    13cf <cpu_test_usage+0x24f>
mov    -0x98(%rbp),%rdi
lea    -0x1e0(%rbp),%rsi
lea    -0x1a1(%rbp),%rdx
lea    -0x1f0(%rbp),%rcx
lea    -0x1f4(%rbp),%r8
lea    -0x1f8(%rbp),%r9
lea    -0x1fc(%rbp),%rax
mov    %rax,-0x250(%rbp)
lea    -0x200(%rbp),%r13
lea    -0x208(%rbp),%r12
lea    -0x210(%rbp),%r15
lea    -0x218(%rbp),%r14
lea    -0x220(%rbp),%rbx
lea    -0x228(%rbp),%r11
lea    -0x230(%rbp),%r10
lea    -0x238(%rbp),%rax
mov    %rax,-0x248(%rbp)
mov    -0x250(%rbp),%rax
mov    %rax,(%rsp)
mov    -0x248(%rbp),%rax
mov    %r13,0x8(%rsp)
mov    %r12,0x10(%rsp)
mov    %r15,0x18(%rsp)
mov    %r14,0x20(%rsp)
mov    %rbx,0x28(%rsp)
mov    %r11,0x30(%rsp)
mov    %r10,0x38(%rsp)
mov    %rax,0x40(%rsp)
call   1090 <sscanf@plt>
mov    %eax,-0x1e4(%rbp)
mov    -0x1e4(%rbp),%eax
cmp    -0x1e8(%rbp),%eax
je     139e <cpu_test_usage+0x21e>
jmp    13cf <cpu_test_usage+0x24f>
mov    -0x230(%rbp),%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x238(%rbp),%rcx
mov    -0x40(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x2c(%rbp)
jmp    13d6 <cpu_test_usage+0x256>
mov    -0x48(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x278,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu_test_usage>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1d8,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
movaps 0xe92(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xe73(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xe57(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe74(%rip),%rdx
lea    0x90(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x40,%esi
mov    %eax,%ecx
call   1050 <snprintf@plt>
lea    0xe64(%rip),%rsi
mov    %rbp,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     12cf <cpu_test_usage+0x15f>
mov    %rax,%rbp
lea    0xd0(%rsp),%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    $0xffffffff,%ebp
test   %rbx,%rbx
je     12d4 <cpu_test_usage+0x164>
movb   $0x0,0x1cf(%rsp)
lea    0xd0(%rsp),%rdi
mov    $0x29,%esi
call   1060 <strrchr@plt>
test   %rax,%rax
je     12d4 <cpu_test_usage+0x164>
cmpb   $0x0,0x1(%rax)
je     12d4 <cpu_test_usage+0x164>
add    $0x1,%rax
sub    $0x8,%rsp
lea    0x18(%rsp),%rbx
lea    0x20(%rsp),%r10
lea    0x40(%rsp),%r11
lea    0x48(%rsp),%r12
lea    0x50(%rsp),%r13
lea    0x68(%rsp),%rsi
lea    0x17(%rsp),%rdx
lea    0x3c(%rsp),%rcx
lea    0x38(%rsp),%r8
lea    0x34(%rsp),%r9
mov    %rax,%rdi
push   %rbx
push   %r10
push   %r11
push   %r12
push   %r13
lea    0x80(%rsp),%rax
push   %rax
lea    0x90(%rsp),%rax
push   %rax
lea    0x64(%rsp),%rax
push   %rax
lea    0x70(%rsp),%rax
push   %rax
call   1080 <sscanf@plt>
add    $0x50,%rsp
cmp    $0xd,%eax
jne    12d4 <cpu_test_usage+0x164>
mov    0x18(%rsp),%rax
mov    %rax,(%r15)
mov    0x10(%rsp),%rax
mov    %rax,(%r14)
xor    %ebp,%ebp
jmp    12d4 <cpu_test_usage+0x164>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x1d8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.cpu_test_usage.fmt = [48 x i8] c" %c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu \00"
@.str = [14 x i8] c"/proc/%d/stat\00"
@.str.1 = [2 x i8] c"r\00"
@EINVAL = global i32 0
define i32 @cpu_test_usage(i64* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i64*
%5 = alloca i64*
%6 = alloca i32*
%7 = alloca [64 x i8]
%8 = alloca i8*
%9 = alloca [256 x i8]
%10 = alloca i8
%11 = alloca [48 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i64
%21 = alloca i64
%22 = alloca i64
%23 = alloca i64
%24 = alloca i64
%25 = alloca i64
%26 = alloca i64
store i64* %0, i64** %4
store i64* %1, i64** %5
%27 = bitcast [48 x i8]* %11 to i8*
store i32 13, i32* %13
%28 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%29 = call i32 (...) @getpid()
%30 = call i32 @snprintf(i8* %28, i32 64, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %29)
%31 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %32, i32** %6
%33 = load i32*, i32** %6
%34 = icmp ne i32* %33, null
br i1 %34, label %36, label %35
35: ; preds = %2
store i32 1, i32* %3
br label %81
36: ; preds = %2
%37 = load i32, i32* @EINVAL
%38 = sub nsw i32 0, %37
store i32 %38, i32* %14
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%40 = load i32*, i32** %6
%41 = call i8* @fgets(i8* %39, i32 256, i32* %40)
store i8* %41, i8** %8
%42 = load i8*, i8** %8
%43 = icmp ne i8* %42, null
br i1 %43, label %45, label %44
44: ; preds = %36
br label %77
45: ; preds = %36
%46 = load i32*, i32** %6
%47 = call i32 @fclose(i32* %46)
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 255
store i8 0, i8* %48
%49 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%50 = call i8* @strrchr(i8* %49, i8 signext 41)
store i8* %50, i8** %8
%51 = load i8*, i8** %8
%52 = icmp ne i8* %51, null
br i1 %52, label %54, label %53
53: ; preds = %45
br label %80
54: ; preds = %45
%55 = load i8*, i8** %8
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %8
%57 = load i8*, i8** %8
%58 = icmp ne i8* %57, null
br i1 %58, label %59, label %63
59: ; preds = %54
%60 = load i8*, i8** %8
%61 = load i8, i8* %60
%62 = icmp ne i8 %61, 0
br i1 %62, label %64, label %63
63: ; preds = %59, %54
br label %80
64: ; preds = %59
%65 = load i8*, i8** %8
%66 = getelementptr inbounds [48 x i8], [48 x i8]* %11, i64 0, i64 0
%67 = call i32 @sscanf(i8* %65, i8* %66, i8* %10, i32* %15, i32* %16, i32* %17, i32* %18, i32* %19, i64* %20, i64* %21, i64* %22, i64* %23, i64* %24, i64* %25, i64* %26)
store i32 %67, i32* %12
%68 = load i32, i32* %12
%69 = load i32, i32* %13
%70 = icmp ne i32 %68, %69
br i1 %70, label %71, label %72
71: ; preds = %64
br label %80
72: ; preds = %64
%73 = load i64, i64* %25
%74 = load i64*, i64** %4
store i64 %73, i64* %74
%75 = load i64, i64* %26
%76 = load i64*, i64** %5
store i64 %75, i64* %76
store i32 0, i32* %3
br label %81
77: ; preds = %44
%78 = load i32*, i32** %6
%79 = call i32 @fclose(i32* %78)
br label %80
80: ; preds = %77, %71, %63, %53
store i32 -1, i32* %3
br label %81
81: ; preds = %80, %72, %35
%82 = load i32, i32* %3
ret i32 %82
}

LLVM IR (-O2):
@__const.cpu_test_usage.fmt = [48 x i8] c" %c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu \00"
@.str = [14 x i8] c"/proc/%d/stat\00"
@.str.1 = [2 x i8] c"r\00"
@EINVAL = global i32 0
define i32 @cpu_test_usage(i64* nocapture writeonly %0, i64* nocapture writeonly %1) {
%3 = alloca [64 x i8]
%4 = alloca [256 x i8]
%5 = alloca i8
%6 = alloca [48 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i64
%17 = alloca i64
%18 = alloca i64
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%21 = getelementptr inbounds [48 x i8], [48 x i8]* %6, i64 0, i64 0
%22 = bitcast i32* %7 to i8*
%23 = bitcast i32* %8 to i8*
%24 = bitcast i32* %9 to i8*
%25 = bitcast i32* %10 to i8*
%26 = bitcast i32* %11 to i8*
%27 = bitcast i64* %12 to i8*
%28 = bitcast i64* %13 to i8*
%29 = bitcast i64* %14 to i8*
%30 = bitcast i64* %15 to i8*
%31 = bitcast i64* %16 to i8*
%32 = bitcast i64* %17 to i8*
%33 = bitcast i64* %18 to i8*
%34 = tail call i32 (...) @getpid()
%35 = call i32 @snprintf(i8* %19, i32 64, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %34)
%36 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%37 = icmp eq i32* %36, null
br i1 %37, label %56, label %38
38: ; preds = %2
%39 = call i8* @fgets(i8* %20, i32 256, i32* %36)
%40 = icmp eq i8* %39, null
%41 = call i32 @fclose(i32* %36)
br i1 %40, label %56, label %42
42: ; preds = %38
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 255
store i8 0, i8* %43
%44 = call i8* @strrchr(i8* %20, i8 signext 41)
%45 = icmp eq i8* %44, null
br i1 %45, label %56, label %46
46: ; preds = %42
%47 = getelementptr inbounds i8, i8* %44, i64 1
%48 = load i8, i8* %47
%49 = icmp eq i8 %48, 0
br i1 %49, label %56, label %50
50: ; preds = %46
%51 = call i32 @sscanf(i8* %47, i8* %21, i8* %5, i32* %7, i32* %8, i32* %9, i32* %10, i32* %11, i64* %12, i64* %13, i64* %14, i64* %15, i64* %16, i64* %17, i64* %18)
%52 = icmp eq i32 %51, 13
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load i64, i64* %17
store i64 %54, i64* %0
%55 = load i64, i64* %18
store i64 %55, i64* %1
br label %56
56: ; preds = %38, %42, %46, %50, %2, %53
%57 = phi i32 [ 0, %53 ], [ 1, %2 ], [ -1, %50 ], [ -1, %46 ], [ -1, %42 ], [ -1, %38 ]
ret i32 %57
}