#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ time_t;
struct TYPE_4__ {
  long tv_usec;
  int /*<<< orphan*/ tv_sec;
};
struct TYPE_3__ {
  long tv_usec;
  int /*<<< orphan*/ tv_sec;
};
struct rusage {
  TYPE_2__ ru_stime;
  TYPE_1__ ru_utime;
};

/* Variables and functions */
int /*<<< orphan*/ RUSAGE_SELF;
int getrusage(int /*<<< orphan*/, struct rusage *);
int octave_cpu_time(time_t *usr_sec, time_t *sys_sec, long *usr_usec,
                    long *sys_usec) {
  struct rusage ru;
  int status = getrusage(RUSAGE_SELF, &ru);
  if (status < 0) {
    *usr_sec = 0;
    *sys_sec = 0;
    *usr_usec = 0;
    *sys_usec = 0;
  } else {
    *usr_sec = ru.ru_utime.tv_sec;
    *usr_usec = ru.ru_utime.tv_usec;
    *sys_sec = ru.ru_stime.tv_sec;
    *sys_usec = ru.ru_stime.tv_usec;
  }
  return status;
}


x86 assembly (clang, -O0):
<octave_cpu_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    0x2eb1(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rsi
call   1030 <getrusage@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    1176 <octave_cpu_time+0x66>
mov    -0x8(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
jmp    119e <octave_cpu_time+0x8e>
mov    -0x28(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x40(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x44(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<octave_cpu_time>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
mov    0x2eb2(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1030 <getrusage@plt>
test   %eax,%eax
js     115b <octave_cpu_time+0x4b>
mov    0x20(%rsp),%ecx
mov    %ecx,(%rbx)
mov    0x18(%rsp),%rcx
mov    %rcx,(%r15)
mov    0x10(%rsp),%ecx
mov    %ecx,(%r12)
mov    0x8(%rsp),%rcx
jmp    1172 <octave_cpu_time+0x62>
movl   $0x0,(%rbx)
movl   $0x0,(%r12)
movq   $0x0,(%r15)
xor    %ecx,%ecx
mov    %rcx,(%r14)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.rusage = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i64, i32 }
%struct.TYPE_3__ = type { i64, i32 }
@RUSAGE_SELF = global i32 0
define i32 @octave_cpu_time(i32* %0, i32* %1, i64* %2, i64* %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i64*
%8 = alloca i64*
%9 = alloca %struct.rusage
%10 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i64* %2, i64** %7
store i64* %3, i64** %8
%11 = load i32, i32* @RUSAGE_SELF
%12 = call i32 @getrusage(i32 %11, %struct.rusage* %9)
store i32 %12, i32* %10
%13 = load i32, i32* %10
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %4
%16 = load i32*, i32** %5
store i32 0, i32* %16
%17 = load i32*, i32** %6
store i32 0, i32* %17
%18 = load i64*, i64** %7
store i64 0, i64* %18
%19 = load i64*, i64** %8
store i64 0, i64* %19
br label %37
20: ; preds = %4
%21 = getelementptr inbounds %struct.rusage, %struct.rusage* %9, i32 0, i32 1
%22 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %21, i32 0, i32 1
%23 = load i32, i32* %22
%24 = load i32*, i32** %5
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.rusage, %struct.rusage* %9, i32 0, i32 1
%26 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %25, i32 0, i32 0
%27 = load i64, i64* %26
%28 = load i64*, i64** %7
store i64 %27, i64* %28
%29 = getelementptr inbounds %struct.rusage, %struct.rusage* %9, i32 0, i32 0
%30 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %29, i32 0, i32 1
%31 = load i32, i32* %30
%32 = load i32*, i32** %6
store i32 %31, i32* %32
%33 = getelementptr inbounds %struct.rusage, %struct.rusage* %9, i32 0, i32 0
%34 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %33, i32 0, i32 0
%35 = load i64, i64* %34
%36 = load i64*, i64** %8
store i64 %35, i64* %36
br label %37
37: ; preds = %20, %15
%38 = load i32, i32* %10
ret i32 %38
}

LLVM IR (-O2):
%struct.rusage = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i64, i32 }
%struct.TYPE_3__ = type { i64, i32 }
@RUSAGE_SELF = global i32 0
define i32 @octave_cpu_time(i32* nocapture writeonly %0, i32* nocapture writeonly %1, i64* nocapture writeonly %2, i64* nocapture writeonly %3) {
%5 = alloca %struct.rusage
%6 = bitcast %struct.rusage* %5 to i8*
%7 = load i32, i32* @RUSAGE_SELF
%8 = call i32 @getrusage(i32 %7, %struct.rusage* %5)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %4
store i32 0, i32* %0
store i32 0, i32* %1
store i64 0, i64* %2
br label %20
11: ; preds = %4
%12 = getelementptr inbounds %struct.rusage, %struct.rusage* %5, i64 0, i32 1, i32 1
%13 = load i32, i32* %12
store i32 %13, i32* %0
%14 = getelementptr inbounds %struct.rusage, %struct.rusage* %5, i64 0, i32 1, i32 0
%15 = load i64, i64* %14
store i64 %15, i64* %2
%16 = getelementptr inbounds %struct.rusage, %struct.rusage* %5, i64 0, i32 0, i32 1
%17 = load i32, i32* %16
store i32 %17, i32* %1
%18 = getelementptr inbounds %struct.rusage, %struct.rusage* %5, i64 0, i32 0, i32 0
%19 = load i64, i64* %18
br label %20
20: ; preds = %11, %10
%21 = phi i64 [ %19, %11 ], [ 0, %10 ]
store i64 %21, i64* %3
ret i32 %8
}