#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*/ uint64_t;
typedef int int64_t;

/* Variables and functions */
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, int /*<<< orphan*/ *, int);
void print_cpustats(int fildes, int64_t cpu_num) {
  int i;
  uint64_t cpustat[10];
  lseek(fildes, cpu_num * 0x1000000000000, 0);
  read(fildes, cpustat, 10 * sizeof(uint64_t));
  if (cpu_num == 4 * 2) {
    printf("cpu ");
  } else {
    printf("cpu%i", (int)cpu_num);
  }
  for (i = 0; i < 10; ++i) {
    printf(" %li", cpustat[i]);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_cpustats>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
movslq -0x8(%rbp),%rax
shl    $0x30,%rax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <lseek@plt>
mov    -0x4(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x28,%edx
call   1050 <read@plt>
cmpl   $0x8,-0x8(%rbp)
jne    1180 <print_cpustats+0x50>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1191 <print_cpustats+0x61>
mov    -0x8(%rbp),%esi
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    11c6 <print_cpustats+0x96>
movslq -0xc(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1198 <print_cpustats+0x68>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_cpustats>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %esi,%ebx
mov    %edi,%ebp
xor    %esi,%esi
xor    %edx,%edx
call   1050 <lseek@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x28,%edx
call   1060 <read@plt>
cmp    $0x8,%ebx
jne    1177 <print_cpustats+0x37>
lea    0xe92(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1187 <print_cpustats+0x47>
lea    0xe87(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%esi
lea    0xe7a(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x14(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x1c(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x20(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x24(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
add    $0x28,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"cpu \00"
@.str.1 = [6 x i8] c"cpu%i\00"
@.str.2 = [5 x i8] c" %li\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @print_cpustats(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [10 x i32]
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = load i32, i32* %4
%9 = sext i32 %8 to i64
%10 = mul nsw i64 %9, 281474976710656
%11 = trunc i64 %10 to i32
%12 = call i32 @lseek(i32 %7, i32 %11, i32 0)
%13 = load i32, i32* %3
%14 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%15 = call i32 @read(i32 %13, i32* %14, i32 40)
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 8
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %23
20: ; preds = %2
%21 = load i32, i32* %4
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %20, %18
store i32 0, i32* %5
br label %24
24: ; preds = %33, %23
%25 = load i32, i32* %5
%26 = icmp slt i32 %25, 10
br i1 %26, label %27, label %36
27: ; preds = %24
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %27
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
br label %24
36: ; preds = %24
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"cpu \00"
@.str.1 = [6 x i8] c"cpu%i\00"
@.str.2 = [5 x i8] c" %li\00"
define void @print_cpustats(i32 %0, i32 %1) {
%3 = alloca [10 x i32]
%4 = bitcast [10 x i32]* %3 to i8*
%5 = tail call i32 @lseek(i32 %0, i32 0, i32 0)
%6 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%7 = call i32 @read(i32 %0, i32* %6, i32 40)
%8 = icmp eq i32 %1, 8
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %13
11: ; preds = %2
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %1)
br label %13
13: ; preds = %11, %9
%14 = load i32, i32* %6
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 1
%17 = load i32, i32* %16
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 2
%20 = load i32, i32* %19
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 3
%23 = load i32, i32* %22
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 4
%26 = load i32, i32* %25
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 5
%29 = load i32, i32* %28
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 6
%32 = load i32, i32* %31
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 7
%35 = load i32, i32* %34
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 8
%38 = load i32, i32* %37
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 9
%41 = load i32, i32* %40
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %41)
%43 = tail call i32 @putchar(i32 10)
ret void
}