#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 tms {
  int tms_utime;
  int tms_stime;
};
struct timespec {
  int tv_sec;
  int tv_nsec;
};
typedef int clock_t;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_PROCESS_CPUTIME_ID;
int /*<<< orphan*/ __clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ __syscall(int, struct tms *);
clock_t clock() {
  struct timespec ts;
  struct tms tms;
  if (!__clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts))
    return ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
  __syscall(43, &tms);
  return (tms.tms_utime + tms.tms_stime) * 100;
}


x86 assembly (clang, -O0):
<clock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2eb9(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1040 <__clock_gettime@plt>
cmp    $0x0,%eax
jne    1167 <clock+0x47>
imul   $0xf4240,-0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1181 <clock+0x61>
mov    $0x2b,%edi
lea    -0x18(%rbp),%rsi
call   1030 <__syscall@plt>
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
imul   $0x64,%eax,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clock>:
sub    $0x18,%rsp
mov    0x2ebd(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
call   1040 <__clock_gettime@plt>
test   %eax,%eax
je     115a <clock+0x3a>
lea    0x8(%rsp),%rsi
mov    $0x2b,%edi
call   1030 <__syscall@plt>
mov    0xc(%rsp),%eax
add    0x8(%rsp),%eax
imul   $0x64,%eax,%eax
add    $0x18,%rsp
ret
imul   $0xf4240,0x10(%rsp),%ecx
movslq 0x14(%rsp),%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rax
add    %edx,%eax
add    %ecx,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
%struct.tms = type { i32, i32 }
@CLOCK_PROCESS_CPUTIME_ID = global i32 0
define i32 @clock() {
%1 = alloca i32
%2 = alloca %struct.timespec
%3 = alloca %struct.tms
%4 = load i32, i32* @CLOCK_PROCESS_CPUTIME_ID
%5 = call i32 @__clock_gettime(i32 %4, %struct.timespec* %2)
%6 = icmp ne i32 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %0
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%9 = load i32, i32* %8
%10 = mul nsw i32 %9, 1000000
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
%12 = load i32, i32* %11
%13 = sdiv i32 %12, 1000
%14 = add nsw i32 %10, %13
store i32 %14, i32* %1
br label %23
15: ; preds = %0
%16 = call i32 @__syscall(i32 43, %struct.tms* %3)
%17 = getelementptr inbounds %struct.tms, %struct.tms* %3, i32 0, i32 0
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.tms, %struct.tms* %3, i32 0, i32 1
%20 = load i32, i32* %19
%21 = add nsw i32 %18, %20
%22 = mul nsw i32 %21, 100
store i32 %22, i32* %1
br label %23
23: ; preds = %15, %7
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
%struct.tms = type { i32, i32 }
@CLOCK_PROCESS_CPUTIME_ID = global i32 0
define i32 @clock() {
%1 = alloca %struct.timespec
%2 = alloca %struct.tms
%3 = bitcast %struct.timespec* %1 to i8*
%4 = bitcast %struct.tms* %2 to i8*
%5 = load i32, i32* @CLOCK_PROCESS_CPUTIME_ID
%6 = call i32 @__clock_gettime(i32 %5, %struct.timespec* %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %0
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%10 = load i32, i32* %9
%11 = mul nsw i32 %10, 1000000
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%13 = load i32, i32* %12
%14 = sdiv i32 %13, 1000
%15 = add nsw i32 %14, %11
br label %24
16: ; preds = %0
%17 = call i32 @__syscall(i32 43, %struct.tms* %2)
%18 = getelementptr inbounds %struct.tms, %struct.tms* %2, i64 0, i32 0
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tms, %struct.tms* %2, i64 0, i32 1
%21 = load i32, i32* %20
%22 = add nsw i32 %21, %19
%23 = mul nsw i32 %22, 100
br label %24
24: ; preds = %16, %8
%25 = phi i32 [ %23, %16 ], [ %15, %8 ]
ret i32 %25
}