#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 timeval {
  long tv_sec;
  long tv_usec;
};
struct rusage {
  long ru_nivcsw;
  long ru_nvcsw;
  struct timeval ru_stime;
  struct timeval ru_utime;
};

/* Variables and functions */
int /*<<< orphan*/ RUSAGE_SELF;
int /*<<< orphan*/ getrusage(int /*<<< orphan*/, struct rusage *);
int /*<<< orphan*/ printf(char *, long);
int main() {
  struct rusage use;
  struct timeval utime;
  struct timeval stime;
  getrusage(RUSAGE_SELF, &use);
  utime = use.ru_utime;
  stime = use.ru_stime;
  long int time = (use.ru_nivcsw + use.ru_nvcsw);
  time = (utime.tv_sec + stime.tv_usec) / time;
  printf("%ld\n", time);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2eaa(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
call   1040 <getrusage@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x38(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x48(%rbp),%rax
add    -0x50(%rbp),%rax
cqto
idivq  -0x60(%rbp)
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rsi
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x38,%rsp
mov    0x2eb5(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1040 <getrusage@plt>
mov    0x10(%rsp),%rcx
mov    0x20(%rsp),%rax
add    0x8(%rsp),%rcx
add    0x28(%rsp),%rax
mov    %rax,%rdx
or     %rcx,%rdx
shr    $0x20,%rdx
je     115e <main+0x3e>
cqto
idiv   %rcx
jmp    1162 <main+0x42>
xor    %edx,%edx
div    %ecx
lea    0xe97(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
ret

LLVM IR (-O0):
%struct.rusage = type { i64, i64, %struct.timeval, %struct.timeval }
%struct.timeval = type { i64, i64 }
@RUSAGE_SELF = global i32 0
@.str = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.rusage
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca i64
store i32 0, i32* %1
%6 = load i32, i32* @RUSAGE_SELF
%7 = call i32 @getrusage(i32 %6, %struct.rusage* %2)
%8 = getelementptr inbounds %struct.rusage, %struct.rusage* %2, i32 0, i32 3
%9 = bitcast %struct.timeval* %3 to i8*
%10 = bitcast %struct.timeval* %8 to i8*
%11 = getelementptr inbounds %struct.rusage, %struct.rusage* %2, i32 0, i32 2
%12 = bitcast %struct.timeval* %4 to i8*
%13 = bitcast %struct.timeval* %11 to i8*
%14 = getelementptr inbounds %struct.rusage, %struct.rusage* %2, i32 0, i32 0
%15 = load i64, i64* %14
%16 = getelementptr inbounds %struct.rusage, %struct.rusage* %2, i32 0, i32 1
%17 = load i64, i64* %16
%18 = add nsw i64 %15, %17
store i64 %18, i64* %5
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%20 = load i64, i64* %19
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%22 = load i64, i64* %21
%23 = add nsw i64 %20, %22
%24 = load i64, i64* %5
%25 = sdiv i64 %23, %24
store i64 %25, i64* %5
%26 = load i64, i64* %5
%27 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %26)
ret i32 0
}

LLVM IR (-O2):
%struct.rusage = type { i64, i64, %struct.timeval, %struct.timeval }
%struct.timeval = type { i64, i64 }
@RUSAGE_SELF = global i32 0
@.str = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca %struct.rusage
%2 = bitcast %struct.rusage* %1 to i8*
%3 = load i32, i32* @RUSAGE_SELF
%4 = call i32 @getrusage(i32 %3, %struct.rusage* %1)
%5 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 3, i32 0
%6 = load i64, i64* %5
%7 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 2, i32 1
%8 = load i64, i64* %7
%9 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 0
%10 = load i64, i64* %9
%11 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 1
%12 = load i64, i64* %11
%13 = add nsw i64 %12, %10
%14 = add nsw i64 %8, %6
%15 = sdiv i64 %14, %13
%16 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %15)
ret i32 0
}