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

/* Variables and functions */
char *getLineFromFile(char *, char *, char *, int, int *);
int /*<<< orphan*/ printf(char *, ...);
int printCPUtime() {
  printf("\n\n-- CPU time:\n\t\tuser\t\tsystem\t\tidle\n");
  int lineLength = 0;
  char *lineFromFile =
      getLineFromFile("/proc/stat", "rb", "cpu0", 4, &lineLength);
  int k = 0;
  int wordNumber = 1;
  while (k < lineLength) {
    if (lineFromFile[k] == ' ') {
      wordNumber++;
      k++;
      if (wordNumber == 2 || wordNumber == 4 || wordNumber == 5)
        printf("\t\t");
    }
    if (wordNumber == 2 || wordNumber == 4 || wordNumber == 5)
      printf("%c", lineFromFile[k]);
    k++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<printCPUtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
lea    0xee1(%rip),%rdi
lea    0xee5(%rip),%rsi
lea    0xee1(%rip),%rdx
mov    $0x4,%ecx
lea    -0x4(%rbp),%r8
call   1040 <getLineFromFile@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    121c <printCPUtime+0xfc>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    11d6 <printCPUtime+0xb6>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x18(%rbp)
je     11c3 <printCPUtime+0xa3>
cmpl   $0x4,-0x18(%rbp)
je     11c3 <printCPUtime+0xa3>
cmpl   $0x5,-0x18(%rbp)
jne    11d1 <printCPUtime+0xb1>
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d6 <printCPUtime+0xb6>
cmpl   $0x2,-0x18(%rbp)
je     11f4 <printCPUtime+0xd4>
cmpl   $0x4,-0x18(%rbp)
je     11f4 <printCPUtime+0xd4>
cmpl   $0x5,-0x18(%rbp)
jne    120e <printCPUtime+0xee>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1172 <printCPUtime+0x52>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printCPUtime>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xec4(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,0x4(%rsp)
lea    0xe9a(%rip),%rdi
lea    0xe9e(%rip),%rsi
lea    0xe9a(%rip),%rdx
lea    0x4(%rsp),%r8
mov    $0x4,%ecx
call   1060 <getLineFromFile@plt>
cmpl   $0x0,0x4(%rsp)
jle    1202 <printCPUtime+0xc2>
mov    %rax,%r13
mov    $0x1,%ebx
mov    $0x1a,%r15d
mov    $0x34,%r12d
xor    %ebp,%ebp
jmp    11b9 <printCPUtime+0x79>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%ebp
cmp    0x4(%rsp),%ebp
jge    1202 <printCPUtime+0xc2>
movslq %ebp,%rax
cmpb   $0x20,0x0(%r13,%rax,1)
jne    11e7 <printCPUtime+0xa7>
lea    0x1(%rbx),%r14d
add    $0x1,%ebp
cmp    $0x4,%ebx
ja     11e4 <printCPUtime+0xa4>
bt     %ebx,%r15d
jae    11e4 <printCPUtime+0xa4>
lea    0xe36(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14d,%ebx
cmp    $0x5,%ebx
ja     11b0 <printCPUtime+0x70>
bt     %ebx,%r12d
jae    11b0 <printCPUtime+0x70>
movslq %ebp,%rax
movsbl 0x0(%r13,%rax,1),%edi
call   1030 <putchar@plt>
jmp    11b0 <printCPUtime+0x70>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"\0A\0A-- CPU time:\0A\09\09user\09\09system\09\09idle\0A\00"
@.str.1 = [11 x i8] c"/proc/stat\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [5 x i8] c"cpu0\00"
@.str.4 = [3 x i8] c"\09\09\00"
@.str.5 = [3 x i8] c"%c\00"
define i32 @printCPUtime() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
%6 = call i8* @getLineFromFile(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4, i32* %1)
store i8* %6, i8** %2
store i32 0, i32* %3
store i32 1, i32* %4
br label %7
7: ; preds = %52, %0
%8 = load i32, i32* %3
%9 = load i32, i32* %1
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %55
11: ; preds = %7
%12 = load i8*, i8** %2
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 32
br i1 %18, label %19, label %35
19: ; preds = %11
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, 2
br i1 %25, label %32, label %26
26: ; preds = %19
%27 = load i32, i32* %4
%28 = icmp eq i32 %27, 4
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = load i32, i32* %4
%31 = icmp eq i32 %30, 5
br i1 %31, label %32, label %34
32: ; preds = %29, %26, %19
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %32, %29
br label %35
35: ; preds = %34, %11
%36 = load i32, i32* %4
%37 = icmp eq i32 %36, 2
br i1 %37, label %44, label %38
38: ; preds = %35
%39 = load i32, i32* %4
%40 = icmp eq i32 %39, 4
br i1 %40, label %44, label %41
41: ; preds = %38
%42 = load i32, i32* %4
%43 = icmp eq i32 %42, 5
br i1 %43, label %44, label %52
44: ; preds = %41, %38, %35
%45 = load i8*, i8** %2
%46 = load i32, i32* %3
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %44, %41
%53 = load i32, i32* %3
%54 = add nsw i32 %53, 1
store i32 %54, i32* %3
br label %7
55: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [11 x i8] c"/proc/stat\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [5 x i8] c"cpu0\00"
@.str.4 = [3 x i8] c"\09\09\00"
@str = [36 x i8] c"\0A\0A-- CPU time:\0A\09\09user\09\09system\09\09idle\00"
define i32 @printCPUtime() {
%1 = alloca i32
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = call i8* @getLineFromFile(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4, i32* %1)
%5 = load i32, i32* %1
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %32
7: ; preds = %0, %28
%8 = phi i32 [ %21, %28 ], [ 1, %0 ]
%9 = phi i32 [ %29, %28 ], [ 0, %0 ]
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %4, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 32
br i1 %13, label %14, label %19
14: ; preds = %7
%15 = add nsw i32 %8, 1
%16 = add nsw i32 %9, 1
switch i32 %8, label %19 [
i32 4, label %17
i32 3, label %17
i32 1, label %17
]
17: ; preds = %14, %14, %14
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %19
19: ; preds = %14, %17, %7
%20 = phi i32 [ %16, %17 ], [ %16, %14 ], [ %9, %7 ]
%21 = phi i32 [ %15, %17 ], [ %15, %14 ], [ %8, %7 ]
switch i32 %21, label %28 [
i32 5, label %22
i32 4, label %22
i32 2, label %22
]
22: ; preds = %19, %19, %19
%23 = sext i32 %20 to i64
%24 = getelementptr inbounds i8, i8* %4, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = call i32 @putchar(i32 %26)
br label %28
28: ; preds = %19, %22
%29 = add nsw i32 %20, 1
%30 = load i32, i32* %1
%31 = icmp slt i32 %29, %30
br i1 %31, label %7, label %32
32: ; preds = %28, %0
ret i32 0
}