#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 rusage {
  int /*<<< orphan*/ ru_utime;
  int /*<<< orphan*/ ru_stime;
};
typedef scalar_t__ clock_t;

/* Variables and functions */
int /*<<< orphan*/ RUSAGE_SELF;
scalar_t__ __getrusage(int /*<<< orphan*/, struct rusage *);
scalar_t__ timeval_to_clock_t(int /*<<< orphan*/ *);
clock_t clock(void) {
  struct rusage usage;
  if (__getrusage(RUSAGE_SELF, &usage) < 0)
    return (clock_t)-1;
  return (timeval_to_clock_t(&usage.ru_stime) +
          timeval_to_clock_t(&usage.ru_utime));
}


x86 assembly (clang, -O0):
<clock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2eb1(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1030 <__getrusage@plt>
cmp    $0x0,%rax
jge    1151 <clock+0x31>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1179 <clock+0x59>
lea    -0x10(%rbp),%rdi
add    $0x4,%rdi
call   1040 <timeval_to_clock_t@plt>
mov    %rax,-0x18(%rbp)
lea    -0x10(%rbp),%rdi
call   1040 <timeval_to_clock_t@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clock>:
push   %rbx
sub    $0x10,%rsp
mov    0x2eb4(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1030 <__getrusage@plt>
test   %rax,%rax
js     1159 <clock+0x39>
lea    0xc(%rsp),%rdi
call   1040 <timeval_to_clock_t@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
call   1040 <timeval_to_clock_t@plt>
add    %rbx,%rax
jmp    1160 <clock+0x40>
mov    $0xffffffffffffffff,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.rusage = type { i32, i32 }
@RUSAGE_SELF = global i32 0
define i64 @clock() {
%1 = alloca i64
%2 = alloca %struct.rusage
%3 = load i32, i32* @RUSAGE_SELF
%4 = call i64 @__getrusage(i32 %3, %struct.rusage* %2)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %0
store i64 -1, i64* %1
br label %13
7: ; preds = %0
%8 = getelementptr inbounds %struct.rusage, %struct.rusage* %2, i32 0, i32 1
%9 = call i64 @timeval_to_clock_t(i32* %8)
%10 = getelementptr inbounds %struct.rusage, %struct.rusage* %2, i32 0, i32 0
%11 = call i64 @timeval_to_clock_t(i32* %10)
%12 = add nsw i64 %9, %11
store i64 %12, i64* %1
br label %13
13: ; preds = %7, %6
%14 = load i64, i64* %1
ret i64 %14
}

LLVM IR (-O2):
%struct.rusage = type { i32, i32 }
@RUSAGE_SELF = global i32 0
define i64 @clock() {
%1 = alloca %struct.rusage
%2 = bitcast %struct.rusage* %1 to i8*
%3 = load i32, i32* @RUSAGE_SELF
%4 = call i64 @__getrusage(i32 %3, %struct.rusage* %1)
%5 = icmp slt i64 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %0
%7 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 1
%8 = call i64 @timeval_to_clock_t(i32* %7)
%9 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 0
%10 = call i64 @timeval_to_clock_t(i32* %9)
%11 = add nsw i64 %10, %8
br label %12
12: ; preds = %0, %6
%13 = phi i64 [ %11, %6 ], [ -1, %0 ]
ret i64 %13
}