#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 HZ;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *, char *, char *,
                          int *, int *, int *, int *, int *, int *, int *,
                          int *, int *, int *, int *, int *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
float obterUsoDaCPUPeloProcesso(int pid, int tempoAtualizacao) {
  int vNULLI;
  char vNULLC[100];
  char nomeArquivo[100];
  int jiffiesUsuario;
  int jiffiesKernel;
  float jiffiesTotal1;
  float jiffiesTotal2;
  float porcentagem;
  FILE *stat;
  sprintf(nomeArquivo, "/proc/%d/stat", pid);
  if ((stat = fopen(nomeArquivo, "r")) != NULL) {
    fscanf(stat, "%d\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d",
           &vNULLI, vNULLC, vNULLC, &vNULLI, &vNULLI, &vNULLI, &vNULLI, &vNULLI,
           &vNULLI, &vNULLI, &vNULLI, &vNULLI, &vNULLI, &jiffiesUsuario,
           &jiffiesKernel);
    fclose(stat);
    jiffiesTotal1 = (float)(jiffiesUsuario + jiffiesKernel);
  }
  sleep(tempoAtualizacao);
  if ((stat = fopen(nomeArquivo, "r")) != NULL) {
    fscanf(stat, "%d\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d",
           &vNULLI, vNULLC, vNULLC, &vNULLI, &vNULLI, &vNULLI, &vNULLI, &vNULLI,
           &vNULLI, &vNULLI, &vNULLI, &vNULLI, &vNULLI, &jiffiesUsuario,
           &jiffiesKernel);
    fclose(stat);
    jiffiesTotal2 = (float)(jiffiesUsuario + jiffiesKernel);
  }
  porcentagem =
      ((jiffiesTotal2 - jiffiesTotal1) / (HZ * tempoAtualizacao)) * 100.00;
  return porcentagem;
}


x86 assembly (clang, -O0):
<obterUsoDaCPUPeloProcesso>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0xe0(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe96(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0xe0(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x100(%rbp)
cmp    $0x0,%rax
je     122f <obterUsoDaCPUPeloProcesso+0xdf>
mov    -0x100(%rbp),%rdi
lea    -0x70(%rbp),%rcx
lea    -0x70(%rbp),%r8
lea    0xe67(%rip),%rsi
lea    -0xc(%rbp),%r11
mov    %r11,-0x108(%rbp)
lea    -0xe4(%rbp),%r10
lea    -0xe8(%rbp),%rax
mov    %r11,%rdx
mov    %r11,%r9
mov    %r11,(%rsp)
mov    %r11,0x8(%rsp)
mov    %r11,0x10(%rsp)
mov    %r11,0x18(%rsp)
mov    %r11,0x20(%rsp)
mov    %r11,0x28(%rsp)
mov    %r11,0x30(%rsp)
mov    %r11,0x38(%rsp)
mov    %r11,0x40(%rsp)
mov    %r10,0x48(%rsp)
mov    %rax,0x50(%rsp)
call   1040 <fscanf@plt>
mov    -0x100(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xe4(%rbp),%eax
add    -0xe8(%rbp),%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0xec(%rbp)
ff
mov    -0x8(%rbp),%edi
call   1070 <sleep@plt>
lea    -0xe0(%rbp),%rdi
lea    0xdd1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x100(%rbp)
cmp    $0x0,%rax
je     12ef <obterUsoDaCPUPeloProcesso+0x19f>
mov    -0x100(%rbp),%rdi
lea    -0x70(%rbp),%rcx
lea    -0x70(%rbp),%r8
lea    0xda7(%rip),%rsi
lea    -0xc(%rbp),%r11
mov    %r11,-0x110(%rbp)
lea    -0xe4(%rbp),%r10
lea    -0xe8(%rbp),%rax
mov    %r11,%rdx
mov    %r11,%r9
mov    %r11,(%rsp)
mov    %r11,0x8(%rsp)
mov    %r11,0x10(%rsp)
mov    %r11,0x18(%rsp)
mov    %r11,0x20(%rsp)
mov    %r11,0x28(%rsp)
mov    %r11,0x30(%rsp)
mov    %r11,0x38(%rsp)
mov    %r11,0x40(%rsp)
mov    %r10,0x48(%rsp)
mov    %rax,0x50(%rsp)
call   1040 <fscanf@plt>
mov    -0x100(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xe4(%rbp),%eax
add    -0xe8(%rbp),%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0xf0(%rbp)
ff
movss  -0xf0(%rbp),%xmm0
ff
subss  -0xec(%rbp),%xmm0
ff
mov    0x2cda(%rip),%rax
mov    (%rax),%eax
imul   -0x8(%rbp),%eax
cvtsi2ss %eax,%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xce0(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xf4(%rbp)
ff
movss  -0xf4(%rbp),%xmm0
ff
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<obterUsoDaCPUPeloProcesso>:
push   %rbp
push   %rbx
sub    $0xe8,%rsp
mov    %esi,%ebp
mov    %edi,%edx
lea    0xea0(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
lea    0xe9a(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11e3 <obterUsoDaCPUPeloProcesso+0x93>
mov    %rax,%rbx
sub    $0x8,%rsp
lea    0x8(%rsp),%rax
lea    0xc(%rsp),%r10
lea    0x14(%rsp),%rdx
lea    0xe72(%rip),%rsi
lea    0x88(%rsp),%rcx
mov    %rbx,%rdi
mov    %rcx,%r8
mov    %rdx,%r9
push   %rax
push   %r10
push   %rdx
push   %rdx
push   %rdx
push   %rdx
push   %rdx
push   %rdx
push   %rdx
push   %rdx
push   %rdx
call   1040 <fscanf@plt>
add    $0x60,%rsp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    (%rsp),%eax
add    0x4(%rsp),%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,0x8(%rsp)
jmp    11e3 <obterUsoDaCPUPeloProcesso+0x93>
mov    %ebp,%edi
call   1070 <sleep@plt>
lea    0xe21(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     125b <obterUsoDaCPUPeloProcesso+0x10b>
mov    %rax,%rbx
sub    $0x8,%rsp
lea    0x8(%rsp),%rax
lea    0xc(%rsp),%r10
lea    0x14(%rsp),%rdx
lea    0xdf7(%rip),%rsi
lea    0x88(%rsp),%rcx
mov    %rbx,%rdi
mov    %rcx,%r8
mov    %rdx,%r9
push   %rax
push   %r10
push   %rdx
push   %rdx
push   %rdx
push   %rdx
push   %rdx
push   %rdx
push   %rdx
push   %rdx
push   %rdx
call   1040 <fscanf@plt>
add    $0x60,%rsp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    (%rsp),%eax
add    0x4(%rsp),%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
jmp    125b <obterUsoDaCPUPeloProcesso+0x10b>
mov    0x2d7e(%rip),%rax
imul   (%rax),%ebp
cvtsi2ss %ebp,%xmm1
subss  0x8(%rsp),%xmm0
divss  %xmm1,%xmm0
mulss  0xd85(%rip),%xmm0
add    $0xe8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/%d/stat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [45 x i8] c"%d\09%s\09%s\09%d\09%d\09%d\09%d\09%d\09%d\09%d\09%d\09%d\09%d\09%d\09%d\00"
@HZ = global i32 0
define float @obterUsoDaCPUPeloProcesso(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [100 x i8]
%7 = alloca [100 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca float
%11 = alloca float
%12 = alloca float
%13 = alloca i32*
store i32 %0, i32* %3
store i32 %1, i32* %4
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%15 = load i32, i32* %3
%16 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %13
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %31
20: ; preds = %2
%21 = load i32*, i32** %13
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%24 = call i32 @fscanf(i32* %21, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32* %5, i8* %22, i8* %23, i32* %5, i32* %5, i32* %5, i32* %5, i32* %5, i32* %5, i32* %5, i32* %5, i32* %5, i32* %5, i32* %8, i32* %9)
%25 = load i32*, i32** %13
%26 = call i32 @fclose(i32* %25)
%27 = load i32, i32* %8
%28 = load i32, i32* %9
%29 = add nsw i32 %27, %28
%30 = sitofp i32 %29 to float
store float %30, float* %10
br label %31
31: ; preds = %20, %2
%32 = load i32, i32* %4
%33 = call i32 @sleep(i32 %32)
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%35 = call i32* @fopen(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %35, i32** %13
%36 = icmp ne i32* %35, null
br i1 %36, label %37, label %48
37: ; preds = %31
%38 = load i32*, i32** %13
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%41 = call i32 @fscanf(i32* %38, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32* %5, i8* %39, i8* %40, i32* %5, i32* %5, i32* %5, i32* %5, i32* %5, i32* %5, i32* %5, i32* %5, i32* %5, i32* %5, i32* %8, i32* %9)
%42 = load i32*, i32** %13
%43 = call i32 @fclose(i32* %42)
%44 = load i32, i32* %8
%45 = load i32, i32* %9
%46 = add nsw i32 %44, %45
%47 = sitofp i32 %46 to float
store float %47, float* %11
br label %48
48: ; preds = %37, %31
%49 = load float, float* %11
%50 = load float, float* %10
%51 = fsub float %49, %50
%52 = load i32, i32* @HZ
%53 = load i32, i32* %4
%54 = mul nsw i32 %52, %53
%55 = sitofp i32 %54 to float
%56 = fdiv float %51, %55
%57 = fpext float %56 to double
%58 = fmul double %57, 1.000000e+02
%59 = fptrunc double %58 to float
store float %59, float* %12
%60 = load float, float* %12
ret float %60
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/%d/stat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [45 x i8] c"%d\09%s\09%s\09%d\09%d\09%d\09%d\09%d\09%d\09%d\09%d\09%d\09%d\09%d\09%d\00"
@HZ = global i32 0
define float @obterUsoDaCPUPeloProcesso(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = alloca [100 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i32* %3 to i8*
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%11 = bitcast i32* %6 to i8*
%12 = bitcast i32* %7 to i8*
%13 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %0)
%14 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %23, label %16
16: ; preds = %2
%17 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32* %3, i8* %9, i8* %9, i32* %3, i32* %3, i32* %3, i32* %3, i32* %3, i32* %3, i32* %3, i32* %3, i32* %3, i32* %3, i32* %6, i32* %7)
%18 = call i32 @fclose(i32* %14)
%19 = load i32, i32* %6
%20 = load i32, i32* %7
%21 = add nsw i32 %20, %19
%22 = sitofp i32 %21 to float
br label %23
23: ; preds = %16, %2
%24 = phi float [ %22, %16 ], [ undef, %2 ]
%25 = call i32 @sleep(i32 %1)
%26 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %35, label %28
28: ; preds = %23
%29 = call i32 @fscanf(i32* %26, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32* %3, i8* %9, i8* %9, i32* %3, i32* %3, i32* %3, i32* %3, i32* %3, i32* %3, i32* %3, i32* %3, i32* %3, i32* %3, i32* %6, i32* %7)
%30 = call i32 @fclose(i32* %26)
%31 = load i32, i32* %6
%32 = load i32, i32* %7
%33 = add nsw i32 %32, %31
%34 = sitofp i32 %33 to float
br label %35
35: ; preds = %28, %23
%36 = phi float [ %34, %28 ], [ undef, %23 ]
%37 = fsub float %36, %24
%38 = load i32, i32* @HZ
%39 = mul nsw i32 %38, %1
%40 = sitofp i32 %39 to float
%41 = fdiv float %37, %40
%42 = fmul float %41, 1.000000e+02
ret float %42
}