#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 */
struct cpuusage_jiffies_stat {
  int dummy;
};
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
struct cpuusage_jiffies_stat *cpuusage_set_jiffies_stat(char *, long, long,
                                                        long, long, long, long,
                                                        long, long, long, long,
                                                        int /*<<< orphan*/ *,
                                                        int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sscanf(char *, char *, char *, long *, long *, long *,
                          long *, long *, long *, long *, long *, long *,
                          long *);
int strlen(char *);
struct cpuusage_jiffies_stat *proc_get_total_jiffies_stat() {
  FILE *fp = NULL;
  char buf[128];
  char cpu[6];
  long int user, nice, system, idle, iowait, irq, softirq, steal, guest,
      guest_nice;
  struct cpuusage_jiffies_stat *jiffies_stat = NULL;
  fp = fopen("/proc/stat", "r");
  if (fp == NULL) {
    perror("fopen:");
    exit(0);
  }
  if (!fgets(buf, sizeof(buf), fp)) {
    goto error;
  }
  if (strlen(buf) > (255 - 10)) {
    goto error;
  }
  {
    sscanf(buf, "%s%ld%ld%ld%ld%ld%ld%ld%ld%ld%ld", cpu, &user, &nice, &system,
           &idle, &iowait, &irq, &softirq, &steal, &guest, &guest_nice);
  }
  fclose(fp);
  if ((jiffies_stat = cpuusage_set_jiffies_stat(
           cpu, user, nice, system, idle, iowait, irq, softirq, steal, guest,
           guest_nice, NULL, NULL)) == NULL) {
    perror("error ");
    exit(-1);
  }
  return jiffies_stat;
error:
  fclose(fp);
  return NULL;
}


x86 assembly (clang, -O0):
<proc_get_total_jiffies_stat>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x130,%rsp
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x110(%rbp)
lea    0xe54(%rip),%rdi
lea    0xe58(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11da <proc_get_total_jiffies_stat+0x5a>
lea    0xe3f(%rip),%rdi
call   1090 <perror@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0x80,%esi
call   1050 <fgets@plt>
cmp    $0x0,%eax
jne    11fd <proc_get_total_jiffies_stat+0x7d>
jmp    135a <proc_get_total_jiffies_stat+0x1da>
lea    -0xb0(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0xf5,%eax
jle    1219 <proc_get_total_jiffies_stat+0x99>
jmp    135a <proc_get_total_jiffies_stat+0x1da>
lea    -0xb0(%rbp),%rdi
lea    -0xb6(%rbp),%rdx
lea    0xde6(%rip),%rsi
lea    -0xc0(%rbp),%rcx
lea    -0xc8(%rbp),%r8
lea    -0xd0(%rbp),%r9
lea    -0xd8(%rbp),%r12
lea    -0xe0(%rbp),%r15
lea    -0xe8(%rbp),%r14
lea    -0xf0(%rbp),%rbx
lea    -0xf8(%rbp),%r11
lea    -0x100(%rbp),%r10
lea    -0x108(%rbp),%rax
mov    %r12,(%rsp)
mov    %r15,0x8(%rsp)
mov    %r14,0x10(%rsp)
mov    %rbx,0x18(%rsp)
mov    %r11,0x20(%rsp)
mov    %r10,0x28(%rsp)
mov    %rax,0x30(%rsp)
call   1060 <sscanf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0xb6(%rbp),%rdi
mov    -0xc0(%rbp),%rsi
mov    -0xc8(%rbp),%rdx
mov    -0xd0(%rbp),%rcx
mov    -0xd8(%rbp),%r8
mov    -0xe0(%rbp),%r9
mov    -0xe8(%rbp),%r14
mov    -0xf0(%rbp),%rbx
mov    -0xf8(%rbp),%r11
mov    -0x100(%rbp),%r10
mov    -0x108(%rbp),%rax
xor    %r15d,%r15d
mov    %r14,(%rsp)
mov    %rbx,0x8(%rsp)
mov    %r11,0x10(%rsp)
mov    %r10,0x18(%rsp)
mov    %rax,0x20(%rsp)
movq   $0x0,0x28(%rsp)
movq   $0x0,0x30(%rsp)
call   1070 <cpuusage_set_jiffies_stat@plt>
mov    %rax,-0x110(%rbp)
cmp    $0x0,%rax
jne    134a <proc_get_total_jiffies_stat+0x1ca>
lea    0xcfa(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x110(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    136b <proc_get_total_jiffies_stat+0x1eb>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x130,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<proc_get_total_jiffies_stat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe8,%rsp
lea    0xe68(%rip),%rdi
lea    0xe6c(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12c6 <proc_get_total_jiffies_stat+0x146>
mov    %rax,%rbx
lea    0x60(%rsp),%rdi
mov    $0x80,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %eax,%eax
je     11d7 <proc_get_total_jiffies_stat+0x57>
lea    0x60(%rsp),%rdi
call   1040 <strlen@plt>
cmp    $0xf5,%eax
jle    11e6 <proc_get_total_jiffies_stat+0x66>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    12b4 <proc_get_total_jiffies_stat+0x134>
sub    $0x8,%rsp
lea    0x10(%rsp),%rax
lea    0x18(%rsp),%r10
lea    0x20(%rsp),%r11
lea    0x28(%rsp),%r15
lea    0x30(%rsp),%r12
lea    0x38(%rsp),%r13
lea    0x40(%rsp),%rbp
lea    0xe00(%rip),%rsi
lea    0x68(%rsp),%rdi
lea    0x62(%rsp),%r14
lea    0x58(%rsp),%rcx
lea    0x50(%rsp),%r8
lea    0x48(%rsp),%r9
mov    %r14,%rdx
push   %rax
push   %r10
push   %r11
push   %r15
push   %r12
push   %r13
push   %rbp
call   1060 <sscanf@plt>
add    $0x40,%rsp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x50(%rsp),%rsi
mov    0x48(%rsp),%rdx
mov    0x40(%rsp),%rcx
mov    0x38(%rsp),%r8
mov    0x30(%rsp),%r9
mov    0x28(%rsp),%r10
mov    0x20(%rsp),%rdi
mov    0x18(%rsp),%rbp
mov    0x10(%rsp),%rbx
mov    0x8(%rsp),%rax
sub    $0x40,%rsp
xorps  %xmm0,%xmm0
movups %xmm0,0x28(%rsp)
mov    %rax,0x20(%rsp)
mov    %rbx,0x18(%rsp)
mov    %rbp,0x10(%rsp)
mov    %rdi,0x8(%rsp)
mov    %r10,(%rsp)
mov    %r14,%rdi
call   1070 <cpuusage_set_jiffies_stat@plt>
add    $0x40,%rsp
test   %rax,%rax
je     12d9 <proc_get_total_jiffies_stat+0x159>
add    $0xe8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd40(%rip),%rdi
call   1090 <perror@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    0xd55(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.cpuusage_jiffies_stat = type { i32 }
@.str = [11 x i8] c"/proc/stat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [7 x i8] c"fopen:\00"
@.str.3 = [33 x i8] c"%s%ld%ld%ld%ld%ld%ld%ld%ld%ld%ld\00"
@.str.4 = [7 x i8] c"error \00"
define %struct.cpuusage_jiffies_stat* @proc_get_total_jiffies_stat() {
%1 = alloca %struct.cpuusage_jiffies_stat*
%2 = alloca i32*
%3 = alloca [128 x i8]
%4 = alloca [6 x i8]
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca %struct.cpuusage_jiffies_stat*
store i32* null, i32** %2
store %struct.cpuusage_jiffies_stat* null, %struct.cpuusage_jiffies_stat** %15
%16 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %2
%17 = load i32*, i32** %2
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %0
%20 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %0
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%24 = load i32*, i32** %2
%25 = call i32 @fgets(i8* %23, i32 128, i32* %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %22
br label %57
28: ; preds = %22
%29 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%30 = call i32 @strlen(i8* %29)
%31 = icmp sgt i32 %30, 245
br i1 %31, label %32, label %33
32: ; preds = %28
br label %57
33: ; preds = %28
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%35 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%36 = call i32 @sscanf(i8* %34, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %35, i64* %5, i64* %6, i64* %7, i64* %8, i64* %9, i64* %10, i64* %11, i64* %12, i64* %13, i64* %14)
%37 = load i32*, i32** %2
%38 = call i32 @fclose(i32* %37)
%39 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%40 = load i64, i64* %5
%41 = load i64, i64* %6
%42 = load i64, i64* %7
%43 = load i64, i64* %8
%44 = load i64, i64* %9
%45 = load i64, i64* %10
%46 = load i64, i64* %11
%47 = load i64, i64* %12
%48 = load i64, i64* %13
%49 = load i64, i64* %14
%50 = call %struct.cpuusage_jiffies_stat* @cpuusage_set_jiffies_stat(i8* %39, i64 %40, i64 %41, i64 %42, i64 %43, i64 %44, i64 %45, i64 %46, i64 %47, i64 %48, i64 %49, i32* null, i32* null)
store %struct.cpuusage_jiffies_stat* %50, %struct.cpuusage_jiffies_stat** %15
%51 = icmp eq %struct.cpuusage_jiffies_stat* %50, null
br i1 %51, label %52, label %55
52: ; preds = %33
%53 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%54 = call i32 @exit(i32 -1)
unreachable
55: ; preds = %33
%56 = load %struct.cpuusage_jiffies_stat*, %struct.cpuusage_jiffies_stat** %15
store %struct.cpuusage_jiffies_stat* %56, %struct.cpuusage_jiffies_stat** %1
br label %60
57: ; preds = %32, %27
%58 = load i32*, i32** %2
%59 = call i32 @fclose(i32* %58)
store %struct.cpuusage_jiffies_stat* null, %struct.cpuusage_jiffies_stat** %1
br label %60
60: ; preds = %57, %55
%61 = load %struct.cpuusage_jiffies_stat*, %struct.cpuusage_jiffies_stat** %1
ret %struct.cpuusage_jiffies_stat* %61
}

LLVM IR (-O2):
%struct.cpuusage_jiffies_stat = type { i32 }
@.str = [11 x i8] c"/proc/stat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [7 x i8] c"fopen:\00"
@.str.3 = [33 x i8] c"%s%ld%ld%ld%ld%ld%ld%ld%ld%ld%ld\00"
@.str.4 = [7 x i8] c"error \00"
define %struct.cpuusage_jiffies_stat* @proc_get_total_jiffies_stat() {
%1 = alloca [128 x i8]
%2 = alloca [6 x i8]
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%14 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%15 = bitcast i64* %3 to i8*
%16 = bitcast i64* %4 to i8*
%17 = bitcast i64* %5 to i8*
%18 = bitcast i64* %6 to i8*
%19 = bitcast i64* %7 to i8*
%20 = bitcast i64* %8 to i8*
%21 = bitcast i64* %9 to i8*
%22 = bitcast i64* %10 to i8*
%23 = bitcast i64* %11 to i8*
%24 = bitcast i64* %12 to i8*
%25 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %30
27: ; preds = %0
%28 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%29 = tail call i32 @exit(i32 0)
unreachable
30: ; preds = %0
%31 = call i32 @fgets(i8* %13, i32 128, i32* %25)
%32 = icmp eq i32 %31, 0
br i1 %32, label %54, label %33
33: ; preds = %30
%34 = call i32 @strlen(i8* %13)
%35 = icmp sgt i32 %34, 245
br i1 %35, label %54, label %36
36: ; preds = %33
%37 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %14, i64* %3, i64* %4, i64* %5, i64* %6, i64* %7, i64* %8, i64* %9, i64* %10, i64* %11, i64* %12)
%38 = call i32 @fclose(i32* %25)
%39 = load i64, i64* %3
%40 = load i64, i64* %4
%41 = load i64, i64* %5
%42 = load i64, i64* %6
%43 = load i64, i64* %7
%44 = load i64, i64* %8
%45 = load i64, i64* %9
%46 = load i64, i64* %10
%47 = load i64, i64* %11
%48 = load i64, i64* %12
%49 = call %struct.cpuusage_jiffies_stat* @cpuusage_set_jiffies_stat(i8* %14, i64 %39, i64 %40, i64 %41, i64 %42, i64 %43, i64 %44, i64 %45, i64 %46, i64 %47, i64 %48, i32* null, i32* null)
%50 = icmp eq %struct.cpuusage_jiffies_stat* %49, null
br i1 %50, label %51, label %56
51: ; preds = %36
%52 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%53 = call i32 @exit(i32 -1)
unreachable
54: ; preds = %33, %30
%55 = call i32 @fclose(i32* %25)
br label %56
56: ; preds = %36, %54
%57 = phi %struct.cpuusage_jiffies_stat* [ null, %54 ], [ %49, %36 ]
ret %struct.cpuusage_jiffies_stat* %57
}